Overview
TheMemori class is the main entry point for the Memori SDK. It provides methods for managing memory attribution, sessions, recall, and LLM integrations.
Constructor
Database connection or connection factory. Can be:
- A callable that returns a database connection
- A database connection object directly
Noneto use cloud-based storage (requiresMEMORI_API_KEY)
Whether to truncate long content in debug logs for readability
Initialization
Methods
attribution()
Set entity and process identifiers for memory attribution.Unique identifier for the entity (e.g., user ID, customer ID). Maximum 100 characters.
Identifier for the process or application context. Maximum 100 characters.
Returns self for method chaining
new_session()
Create a new session with a fresh UUID. This resets the session context and cache.Returns self for method chaining
set_session()
Set an existing session ID to continue a previous session.The session ID to use
Returns self for method chaining
recall()
Retrieve relevant memories based on a query string.The search query to find relevant memories
Maximum number of facts to return. Defaults to
config.recall_facts_limit (5)List of relevant memory facts matching the query
embed_texts()
Generate embeddings for text inputs using the configured embedding model.Single text string or list of text strings to embed
If True, returns an awaitable that runs embedding in a threadpool
List of embedding vectors, one per input text. Returns awaitable if
async_=Trueclose()
Close the underlying storage connection or session. Important for long-running processes like web servers to release database connections.LLM Integration
TheMemori class provides built-in integration with multiple LLM providers:
llm.register()
Register an LLM client for automatic memory augmentation.Generic LLM client (auto-detected provider)
OpenAI chat completion client
Anthropic Claude client
Google Gemini client
xAI client
LangChain ChatBedrock
LangChain ChatGoogleGenerativeAI
LangChain ChatOpenAI
LangChain ChatVertexAI
Provider-Specific Integrations
Memori also provides direct access to provider-specific integrations:mem.openai- OpenAI integrationmem.anthropic- Anthropic Claude integrationmem.google- Google Gemini integrationmem.xai- xAI integrationmem.langchain- LangChain integrationmem.agno- Agno integrationmem.pydantic_ai- Pydantic AI integration
Configuration
Access and modify configuration throughmem.config:
Context Manager Support
TheMemori class supports Python’s context manager protocol:
Complete Example
See Also
- Attribution - Memory attribution methods
- Sessions - Session management
- Recall - Memory recall API
- Embeddings - Embeddings API