memory
Mem0 memory service integration for Pipecat.
This module provides a memory service that integrates with Mem0 to store and retrieve conversational memories, enhancing LLM context with relevant historical information.
- class pipecat.services.mem0.memory.Mem0MemoryService(*, api_key: str | None = None, local_config: dict[str, Any] | None = None, user_id: str | None = None, agent_id: str | None = None, run_id: str | None = None, params: InputParams | None = None, host: str | None = None)[source]
Bases:
FrameProcessorA standalone memory service that integrates with Mem0.
This service intercepts message frames in the pipeline, stores them in Mem0, and enhances context with relevant memories before passing them downstream. Supports both local and cloud-based Mem0 configurations.
- class InputParams(*, search_limit: Annotated[int, Ge(ge=1)] = 10, search_threshold: Annotated[float, Ge(ge=0.0), Le(le=1.0)] = 0.1, api_version: str = 'v2', system_prompt: str = 'Based on previous conversations, I recall: \n\n', add_as_system_message: bool = True, position: int = 1)[source]
Bases:
BaseModelConfiguration parameters for Mem0 memory service.
- Parameters:
search_limit – Maximum number of memories to retrieve per query.
search_threshold – Minimum similarity threshold for memory retrieval.
api_version – API version to use for Mem0 client operations.
system_prompt – Prefix text for memory context messages.
add_as_system_message – Whether to add memories as system messages.
position – Position to insert memory messages in context.
- search_limit: int
- search_threshold: float
- api_version: str
- system_prompt: str
- add_as_system_message: bool
- position: int
- __init__(*, api_key: str | None = None, local_config: dict[str, Any] | None = None, user_id: str | None = None, agent_id: str | None = None, run_id: str | None = None, params: InputParams | None = None, host: str | None = None)[source]
Initialize the Mem0 memory service.
- Parameters:
api_key – The API key for accessing Mem0’s cloud API.
local_config – Local configuration for Mem0 client (alternative to cloud API).
user_id – The user ID to associate with memories in Mem0.
agent_id – The agent ID to associate with memories in Mem0.
run_id – The run ID to associate with memories in Mem0.
params – Configuration parameters for memory retrieval and storage.
host – The host of the Mem0 server.
- Raises:
ValueError – If none of user_id, agent_id, or run_id are provided.
- async get_memories() list[dict[str, Any]][source]
Retrieve all stored memories for the configured user/agent/run IDs.
This is a convenience method for accessing memories outside the pipeline, e.g. to build a personalized greeting at connection time. It wraps the blocking Mem0
get_all()call in a background thread.- Returns:
List of memory dictionaries. Each dict contains at least a
"memory"key with the memory text. Returns an empty list on error.
- async process_frame(frame: Frame, direction: FrameDirection)[source]
Process incoming frames, intercept context frames for memory integration.
- Parameters:
frame – The incoming frame to process.
direction – The direction of frame flow in the pipeline.