Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions server/services/memory/mem0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,27 @@ memory = Mem0MemoryService(
)
```

### Retrieving Memories Outside the Pipeline

The `get_memories()` method allows you to access stored memories outside the normal pipeline flow, such as when creating a personalized greeting at connection time:

```python
# Get all stored memories for the configured user/agent/run IDs
memories = await memory.get_memories()

# Create a personalized greeting
if memories:
greeting = "Hello! Based on our previous conversations, I remember: "
for mem in memories[:3]:
greeting += f"{mem['memory']} "
else:
greeting = "Hello! It's nice to meet you."
```

## Notes

- **At least one ID required**: You must provide at least one of `user_id`, `agent_id`, or `run_id`. A `ValueError` is raised if none are provided.
- **Cloud vs local**: Use `api_key` for Mem0's cloud API, or `local_config` for a self-hosted Mem0 instance using `Memory.from_config()`.
- **Pipeline placement**: Place the `Mem0MemoryService` before your LLM service in the pipeline. It intercepts `LLMContextFrame`, `OpenAILLMContextFrame`, and `LLMMessagesFrame` to enhance context with relevant memories before passing them downstream.
- **Non-blocking operation**: All Mem0 API calls (storage, retrieval, search) run in background threads to avoid blocking the event loop. Message storage is fire-and-forget, so it doesn't delay downstream processing.
- **Message role filtering**: Only messages with `user` or `assistant` roles are stored in Mem0. Messages with other roles (such as `system` or `developer`) are automatically filtered out, as the Mem0 API does not accept them.
Loading