Mem0MemoryWriter
Write ChatMessage objects as memories to a Mem0 memory store, persisting conversation context for use in future pipeline runs.
Key Features
- Persists conversation messages to Mem0 memory storage so agents can recall past interactions.
- Supports scoping by
user_id,run_id,agent_id, orapp_id, allowing a single pipeline instance to serve multiple users or agents. - The
infersetting controls whether Mem0 extracts key facts from messages or stores message text verbatim. - Returns a count of the memory items written, useful for logging and conditional branching.
- No API key is required when using a self-hosted Mem0 instance.
Configuration
- Drag the
Mem0MemoryWritercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Configure the
Mem0MemoryStorewith your Mem0 API credentials. - Set
infertotrueto have Mem0 extract facts from messages, orfalseto store message text as-is.
- Configure the
Connections
Mem0MemoryWriter receives a list of ChatMessage objects, typically from the output of a chat generator or agent, along with optional scoping parameters such as user_id. It returns the count of written memory items through its memories_written output.
Source Code
To check this component's source code, open writer.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
Mem0MemoryWriter:
type: haystack_integrations.components.writers.mem0.writer.Mem0MemoryWriter
init_parameters:
infer: true
memory_store:
type: haystack_integrations.memory_stores.mem0.memory_store.Mem0MemoryStore
init_parameters:
api_key: YOUR_MEM0_API_KEY
Using the Component in a Pipeline
# haystack-pipeline
components:
Mem0MemoryWriter:
type: haystack_integrations.components.writers.mem0.writer.Mem0MemoryWriter
init_parameters:
infer: true
memory_store:
type: haystack_integrations.memory_stores.mem0.memory_store.Mem0MemoryStore
init_parameters:
api_key: YOUR_MEM0_API_KEY
connections: []
max_runs_per_component: 100
metadata: {}
inputs:
messages:
- Mem0MemoryWriter.messages
user_id:
- Mem0MemoryWriter.user_id
outputs:
memories_written: Mem0MemoryWriter.memories_written
Parameters
Inputs
| Parameter | Type | Description |
|---|---|---|
messages | List[ChatMessage] | List of ChatMessage objects to store as memories. |
user_id | Optional[str] | User ID to scope the stored memories. |
run_id | Optional[str] | Run ID to scope the stored memories. |
agent_id | Optional[str] | Agent ID to scope the stored memories. |
app_id | Optional[str] | App ID to scope the stored memories. |
Outputs
| Parameter | Type | Description |
|---|---|---|
memories_written | int | Count of memory items stored in Mem0. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
memory_store | Mem0MemoryStore | An instance of Mem0MemoryStore to write memories to. | |
infer | bool | True | If True, Mem0 extracts key facts from messages. If False, Mem0 stores message text verbatim. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
messages | List[ChatMessage] | List of ChatMessage objects to store. | |
user_id | Optional[str] | None | User ID to scope the stored memories. |
run_id | Optional[str] | None | Run ID to scope the stored memories. |
agent_id | Optional[str] | None | Agent ID to scope the stored memories. |
app_id | Optional[str] | None | App ID to scope the stored memories. |
Related Information
Was this page helpful?