Universal self-improving memory layer for LLM applications (Mem0 v1.0.11) enabling persistent context across sessions with support for both managed platform and open-source deployments. Use when building LLM applications requiring memory persistence, semantic recall across conversations, user-specific memory storage, or integrating LangChain/LlamaIndex with external memory backends.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Universal self-improving memory layer for LLM applications (Mem0 v1.0.11) enabling persistent context across sessions with support for both managed platform and open-source deployments. Use when building LLM applications requiring memory persistence, semantic recall across conversations, user-specific memory storage, or integrating LangChain/LlamaIndex with external memory backends.
Mem0 ("mem-zero") is a self-improving memory layer for LLM applications that enables persistent context across sessions. Unlike traditional RAG systems that are stateless, Mem0 creates stateful agents that remember user preferences, learn from interactions, and evolve behavior over time. It combines vector embeddings with optional graph databases for comprehensive recall — achieving +26% accuracy over OpenAI Memory, 91% faster responses, and 90% lower token usage on the LOCOMO benchmark.
Mem0 offers two deployment modes:
Mem0 Platform — Fully managed service at api.mem0.ai with automatic scaling, SOC 2 compliance, graph memory, webhooks, and a dashboard. Accessed via API key.
Mem0 Open Source — Self-hosted SDK (Python + Node.js) with full control over LLMs, vector stores, embedders, and rerankers. Runs on your infrastructure.
Both modes share the same core memory pipeline: information extraction → conflict resolution → dual storage (vector + optional graph).
When to Use
Building AI assistants or chatbots that need to remember users across sessions
Creating customer support agents that recall past tickets and preferences
Developing multi-agent systems where agents share or isolate memory
Implementing personalized recommendations based on historical interactions
Any LLM application where stateless context windows are insufficient
Migrating from OpenAI's native Memory API to a more cost-effective, faster alternative
Core Concepts
Memory Layers
Mem0 organizes memory into four layers:
Conversation memory — In-flight messages within a single turn (tool calls, chain-of-thought). Lost after the turn.
Session memory — Short-lived facts for a current task or channel. Scoped by session_id / run_id.
User memory — Long-lived knowledge tied to a person or account. Scoped by user_id. Persists across interactions.
Organizational memory — Shared context available to multiple agents or teams.
The Memory Pipeline
Every add call passes through three stages:
Information extraction — An LLM identifies key facts, preferences, and decisions from the conversation.
Conflict resolution — Existing memories are checked for duplicates or contradictions; latest truth wins.
Storage — Memories land in vector storage (and optionally graph storage) for fast retrieval.
Entity Scoping
Mem0 scopes memories by entity identifiers to prevent cross-contamination:
user_id — Persistent persona or account
agent_id — Distinct agent persona or tool
app_id — White-label app or product surface
run_id — Short-lived flow, ticket, or conversation thread
Response Format (v1.0+)
All operations return a consistent format: {"results": [...]}. This replaced the pre-v1.0 behavior where responses varied by operation. No more version or output_format parameters needed.
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
Open Source Setup
import os
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"from mem0 import Memory
m = Memory()
Default OSS components (override via Memory.from_config):
LLM: OpenAI gpt-4.1-nano-2025-04-14
Embeddings: OpenAI text-embedding-3-small
Vector store: Local Qdrant at /tmp/qdrant
History store: SQLite at ~/.mem0/history.db
Usage Examples
Basic Add and Search
from mem0 import Memory
m = Memory()
# Add memories from a conversation
messages = [
{"role": "user", "content": "Hi, I'm Alex. I love basketball and gaming."},
{"role": "assistant", "content": "Hey Alex! I'll remember your interests."}
]
result = m.add(messages, user_id="alex")
# Search for relevant memories
results = m.search("What do you know about me?", user_id="alex")
for hit in results["results"]:
print(hit["memory"])
Platform API with Filters
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
# Add with entity scoping
messages = [
{"role": "user", "content": "I'm planning a trip to Tokyo next month."},
{"role": "assistant", "content": "Great! I'll remember that for future suggestions."}
]
client.add(messages, user_id="alice")
# Search with logical filters
results = client.search(
"What are Alice's hobbies?",
filters={
"OR": [
{"user_id": "alice"},
{"agent_id": {"in": ["travel-assistant", "customer-support"]}}
]
}
)
Full Chat with Memory Loop
from openai import OpenAI
from mem0 import Memory
openai_client = OpenAI()
memory = Memory()
defchat_with_memories(message: str, user_id: str = "default_user") -> str:
# Retrieve relevant memories
relevant = memory.search(query=message, user_id=user_id, limit=3)
memories_str = "\n".join(f"- {entry['memory']}"for entry in relevant["results"])
# Generate response with memory context
system_prompt = f"You are a helpful AI.\nUser Memories:\n{memories_str}"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": message}
]
response = openai_client.chat.completions.create(
model="gpt-4.1-nano-2025-04-14", messages=messages
)
assistant_response = response.choices[0].message.content
# Store the conversation as new memory
messages.append({"role": "assistant", "content": assistant_response})
memory.add(messages, user_id=user_id)
return assistant_response
Advanced Topics
Memory Operations: Add, search, update, and delete workflows with Platform vs OSS differences → Memory Operations
Configuration & Components: LLM providers (18+), vector databases (24+), embedders (10+), rerankers (5+) with full setup guides → Configuration and Components