chore: import upstream snapshot with attribution
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:22:28 +08:00
commit c56bef871b
9296 changed files with 1854228 additions and 0 deletions
@@ -0,0 +1,91 @@
---
title: "DocumentWriter"
id: documentwriter
slug: "/documentwriter"
description: "Use this component to write documents into a Document Store of your choice."
---
# DocumentWriter
Use this component to write documents into a Document Store of your choice.
<div className="key-value-table">
| | |
| --- | --- |
| **Most common position in a pipeline** | As the last component in an indexing pipeline |
| **Mandatory init variables** | `document_store`: A Document Store instance |
| **Mandatory run variables** | `documents`: A list of documents |
| **Output variables** | `documents_written`: The number of documents written (integer) |
| **API reference** | [Document Writers](/reference/document-writers-api) |
| **GitHub link** | https://github.com/deepset-ai/haystack/blob/main/haystack/components/writers/document_writer.py |
| **Package name** | `haystack-ai` |
</div>
## Overview
`DocumentWriter` writes a list of documents into a Document Store of your choice. Its typically used in an indexing pipeline as the final step after preprocessing documents and creating their embeddings.
To use this component with a specific file type, make sure you use the correct [Converter](../converters.mdx) before it. For example, to use `DocumentWriter` with Markdown files, use the `MarkdownToDocument` component before `DocumentWriter` in your indexing pipeline.
### DuplicatePolicy
The `DuplicatePolicy` is a class that defines the different options for handling documents with the same ID in a `DocumentStore`. It has four possible values:
- **NONE**: The default policy that relies on Document Store settings.
- **OVERWRITE**: Indicates that if a document with the same ID already exists in the `DocumentStore`, it should be overwritten with the new document.
- **SKIP**: If a document with the same ID already exists, the new document will be skipped and not added to the `DocumentStore`.
- **FAIL**: Raises an error if a document with the same ID already exists in the `DocumentStore`. It prevents duplicate documents from being added.
## Usage
### On its own
Below is an example of how to write two documents into an `InMemoryDocumentStore`:
```python
from haystack import Document
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.components.writers import DocumentWriter
documents = [
Document(content="This is document 1"),
Document(content="This is document 2"),
]
document_store = InMemoryDocumentStore()
document_writer = DocumentWriter(document_store=document_store)
document_writer.run(documents=documents)
```
### In a pipeline
Below is an example of an indexing pipeline that first uses the `SentenceTransformersDocumentEmbedder` to create embeddings of documents and then use the `DocumentWriter` to write the documents to an `InMemoryDocumentStore`:
```python
from haystack.pipeline import Pipeline
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.document_stores.types import DuplicatePolicy
from haystack.components.embedders import SentenceTransformersDocumentEmbedder
from haystack.components.writers import DocumentWriter
documents = [
Document(content="This is document 1"),
Document(content="This is document 2"),
]
document_store = InMemoryDocumentStore()
embedder = SentenceTransformersDocumentEmbedder()
document_writer = DocumentWriter(
document_store=document_store,
policy=DuplicatePolicy.NONE,
)
indexing_pipeline = Pipeline()
indexing_pipeline.add_component(instance=embedder, name="embedder")
indexing_pipeline.add_component(instance=document_writer, name="writer")
indexing_pipeline.connect("embedder", "writer")
indexing_pipeline.run({"embedder": {"documents": documents}})
```
@@ -0,0 +1,119 @@
---
title: "Mem0MemoryWriter"
id: mem0memorywriter
slug: "/mem0memorywriter"
description: "Writes ChatMessage objects to Mem0 as long-term memories."
---
# Mem0MemoryWriter
Writes `ChatMessage` objects to Mem0 as long-term memories.
<div className="key-value-table">
| | |
| --- | --- |
| **Most common position in a pipeline** | After an [`Agent`](../agents-1/agent.mdx) or Chat Generator in memory-augmented pipelines |
| **Mandatory init variables** | `memory_store`: A `Mem0MemoryStore` instance |
| **Mandatory run variables** | `messages`: A list of `ChatMessage` objects; at least one Mem0 scope through `user_id`, `run_id`, `agent_id`, or `app_id` |
| **Output variables** | `memories_written`: The number of memories written |
| **Mem0 API docs** | [Add Memories](https://docs.mem0.ai/api-reference/memory/add-memories) |
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/mem0 |
| **Package name** | `mem0-haystack` |
</div>
## Overview
`Mem0MemoryWriter` writes a list of `ChatMessage` objects to a `Mem0MemoryStore`. Use it near the end of a memory-augmented pipeline to persist conversation facts, user preferences, and durable project context for future runs.
Scope written memories with at least one Mem0 entity ID: `user_id`, `run_id`, `agent_id`, or `app_id`. These are runtime inputs, so one pipeline instance can write memories for multiple users, sessions, agents, or applications.
The `infer` init parameter controls how Mem0 stores the incoming messages:
- `infer=True` lets Mem0 extract memories from the messages. This is useful when writing a full Agent turn that includes the user message, tool context, and final assistant response.
- `infer=False` stores the supplied message text as-is. This is useful when the upstream component has already selected the exact memory text.
### Installation
Install the Mem0 integration:
```shell
pip install mem0-haystack
```
Set your Mem0 API key:
```shell
export MEM0_API_KEY="your-mem0-api-key"
```
## Usage
### On its own
```python
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.writers.mem0 import Mem0MemoryWriter
from haystack_integrations.memory_stores.mem0 import Mem0MemoryStore
store = Mem0MemoryStore()
writer = Mem0MemoryWriter(memory_store=store, infer=False)
result = writer.run(
messages=[ChatMessage.from_user("Alice prefers concise Python examples.")],
user_id="alice",
)
print(result["memories_written"])
```
### In a Pipeline
This example connects an Agent's full `messages` output to `Mem0MemoryWriter` with `infer=True`, so Mem0 can extract memories from the full turn context.
```python
from haystack import Pipeline
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.components.generators.utils import print_streaming_chunk
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.writers.mem0 import Mem0MemoryWriter
from haystack_integrations.memory_stores.mem0 import Mem0MemoryStore
store = Mem0MemoryStore()
pipeline = Pipeline()
pipeline.add_component(
"agent",
Agent(
chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
system_prompt=(
"Answer the user and preserve durable user facts or preferences for future conversations."
),
streaming_callback=print_streaming_chunk,
),
)
pipeline.add_component("writer", Mem0MemoryWriter(memory_store=store, infer=True))
pipeline.connect("agent.messages", "writer.messages")
result = pipeline.run(
{
"agent": {
"messages": [
ChatMessage.from_user(
"My name is Alice and I prefer concise Python examples.",
),
],
},
"writer": {
"user_id": "alice",
},
},
)
print(result["writer"]["memories_written"])
```