Mem0 is a universal, self-improving memory layer for AI agents and LLM applications that combines vector databases, knowledge graphs, and key-value stores into a hybrid datastore architecture. With over 51,000 GitHub stars, Mem0 delivers 26% higher accuracy and 90% token savings compared to baselines like OpenAI Memory on the LOCOMO benchmark.
Hybrid Datastore – Combines vector stores for similarity search, knowledge graphs for entity relationships, and key-value stores for metadata filtering
Extraction Phase: Ingests the latest user exchange, a rolling long-term summary, and the most recent messages. An LLM extracts concise candidate memories as salient factual phrases. For graph-enhanced Mem0g, an Entity Extractor identifies nodes and a Relations Generator infers labeled edges.
Update Phase: Consolidates memories asynchronously to maintain a coherent, non-redundant store. Background processes refresh summaries without stalling inference.
graph TB
subgraph Input["Input Processing"]
Msg[User Message]
Ctx[Conversation Context]
Sum[Rolling Summary]
end
subgraph Extract["Extraction Phase"]
LLM[LLM Extractor]
Entity[Entity Extractor]
Rel[Relations Generator]
end
subgraph Store["Hybrid Datastore"]
VS[(Vector Store)]
KG[(Knowledge Graph)]
KV[(Key-Value Store)]
end
subgraph Retrieve["Retrieval Phase"]
VecSearch[Vector Similarity]
GraphTraverse[Graph Traversal]
KVLookup[Key-Value Lookup]
Rank[Ranking and Fusion]
end
subgraph Output["Memory Output"]
Memories[Ranked Memories]
Context[Enriched Context]
end
Input --> Extract
LLM --> VS
Entity --> KG
Rel --> KG
Extract --> Store
Store --> Retrieve
VecSearch --> Rank
GraphTraverse --> Rank
KVLookup --> Rank
Rank --> Output
Memory Types
Mem0 supports multi-level namespaces for scoped persistence:
Short-term – Derived from recent messages; stored as atomic semantic facts to minimize size
Long-term – Consolidated facts across sessions using rolling summaries and graph structures
User-scoped – Isolated to individual user_id; stores preferences and history
Agent-scoped – Global or shared facts across users and agents
Performance
On the LOCOMO benchmark:
Mem0: 66.9% accuracy vs OpenAI Memory's 52.9%
Mem0g (graph-enhanced): 68.4% accuracy
p95 latency: 1.44s (91% lower than baselines)
Token savings: 90% compared to full-context RAG approaches
Code Example
from mem0 import Memory
config ={"vector_store": {"provider": "qdrant","config": {"host": "localhost","port": 6333}},"llm": {"provider": "openai","config": {"model": "gpt-4o","temperature": 0}}}
m = Memory.from_config(config)# Add memories from a conversation
m.add("I prefer Python for backend and React for frontend",
user_id="alice", metadata={"topic": "preferences"})
m.add("My current project uses FastAPI with PostgreSQL",
user_id="alice", metadata={"topic": "project"})# Retrieve relevant memories
memories = m.search("What tech stack does Alice use?",
user_id="alice", limit=5)for mem in memories:
print(f"[{mem['score']:.2f}] {mem['memory']}")