Overview
The memory system automatically:- Retrieves relevant memories based on the current user input before generating a response.
- Injects these memories into the system prompt.
- Stores the new interaction (user input and agent response) into the vector store after the response is generated.
Configuration
To enable memory, you need to provide amemory configuration object when initializing your Agent.
1. Simple (In-Memory)
For testing or temporary agents, you can initialize memory without any configuration. This uses an in-memory vector store that resets when the process ends.2. Local Persistence
To persist chat history locally between runs, provide apath where the SQLite database should be stored.
3. Advanced (PgVector)
For production applications, we recommend using a robust vector database like PostgreSQL withpgvector.
PgVector Setup
Ensure your PostgreSQL database has thevector extension enabled:
Usage
Once configured, you can use thememory option in generate and stream methods to pass context identifiers like thread (run ID) and metadata (user ID, etc.).
Streaming with Memory
Retrieving Context
In a subsequent call, even in a new session, the agent will recall the information:Advanced Configuration
Thememory configuration accepts the standard mem0 configuration object, allowing you to customize the embedder, vector store, and LLM used for memory operations.
Refer to the Mem0 documentation for more advanced configuration options.