Overview
Mem0MemoryService provides long-term memory capabilities for conversational agents by integrating with Mem0’s API. It automatically stores conversation history and retrieves relevant past context based on the current conversation, enhancing LLM responses with persistent memory across sessions.
Mem0 Memory API Reference
Pipecat’s API methods for Mem0 memory integration
Example Implementation
Browse examples using Mem0 memory
Mem0 Documentation
Official Mem0 API documentation and guides
Mem0 Platform
Access memory services and manage API keys
Installation
To use Mem0 memory services, install the required dependencies:Prerequisites
Mem0 Account Setup
Before using Mem0 memory services, you need:- Mem0 Account: Sign up at Mem0 Platform
- API Key: Generate an API key from your account dashboard
- Host Configuration: Set up your Mem0 host endpoint
- User Management: Configure user IDs for memory association
Required Environment Variables
MEM0_API_KEY: Your Mem0 API key for authentication
Configuration Options
- User ID: Unique identifier for associating memories with specific users
- Agent ID: Identifier for the agent using the memory service
- Run ID: Identifier for specific conversation sessions
- Memory Retrieval: Configure how past context is retrieved and used
Key Features
- Persistent Memory: Long-term conversation history across sessions
- Context Retrieval: Automatic retrieval of relevant past conversations
- User Association: Memory tied to specific users for personalization
- Session Management: Track conversations across different runs and agents
Configuration
The API key for accessing Mem0’s cloud API.
Local configuration for Mem0 client as an alternative to the cloud API.
The user ID to associate with memories in Mem0. At least one of
user_id, agent_id, or run_id must be provided.The agent ID to associate with memories in Mem0.
The run ID to associate with memories in Mem0.
Configuration parameters for memory retrieval and storage. See InputParams below.
The host of the Mem0 server.
InputParams
| Parameter | Type | Default | Description |
|---|---|---|---|
search_limit | int | 10 | Maximum number of memories to retrieve per query (min: 1). |
search_threshold | float | 0.1 | Minimum similarity threshold for memory retrieval (0.0-1.0). |
api_version | str | "v2" | API version to use for Mem0 client operations. |
system_prompt | str | "Based on previous conversations, I recall: \n\n" | Prefix text for memory context messages. |
add_as_system_message | bool | True | Whether to add memories as system messages. When False, adds as user messages. |
position | int | 1 | Position to insert memory messages in context. |
Usage
Cloud API Setup
With Custom Parameters
Local Configuration
Notes
- At least one ID required: You must provide at least one of
user_id,agent_id, orrun_id. AValueErroris raised if none are provided. - Cloud vs local: Use
api_keyfor Mem0’s cloud API, orlocal_configfor a self-hosted Mem0 instance usingMemory.from_config(). - Pipeline placement: Place the
Mem0MemoryServicebefore your LLM service in the pipeline. It interceptsLLMContextFrame,OpenAILLMContextFrame, andLLMMessagesFrameto enhance context with relevant memories before passing them downstream.