Mem0: Building Production-Ready AI Agents with Scalable Long-Term Memory
Prateek Chhikara · Dev Khant · Saket Aryan · Taranjeet Singh · Deshraj Yadav · mem0.ai
LLMs forget everything once it falls outside their context window. Mem0 fixes this by dynamically extracting compact memories from conversations, storing them in a vector database, and retrieving only what's relevant at query time. A graph-memory variant (Mem0g) adds structured entity–relationship storage for temporal and relational queries. Both beat every baseline on the LOCOMO benchmark while using 91% less latency and 90%+ fewer tokens than full-context approaches.
Why This Matters
Every time you start a new chat with an AI assistant, it has no memory of you. Tell it you're vegetarian today; ask for dinner recommendations tomorrow — it might suggest chicken. This isn't a quirk; it's a fundamental architectural constraint. LLMsLarge Language Models — neural networks trained to predict and generate text, like GPT-4. process a fixed-length "context window" of tokens, and anything outside that window is simply gone.
Even as context windows grow (GPT-4: 128K tokens, Claude 3.7: 200K, Gemini: 10M+), the problem isn't fully solved. Real conversations span weeks or months. A user's dietary preference from three weeks ago sits buried among thousands of tokens of unrelated coding discussions. The model either can't fit it all, or drowns in irrelevant context — attention degrades over distant tokens.
For high-stakes domains — healthcare, education, enterprise support — this forgetfulness actively erodes trust. What we need isn't a bigger window; we need a smarter memory system that selectively stores, consolidates, and retrieves only what's relevant.
The Big Idea
Mem0 treats memory as a dynamic knowledge base rather than a static log. As a conversation unfolds, an LLM continuously extracts salient facts from each new message pair, compares them against existing memories, and decides whether to add, update, delete, or ignore them. At query time, only the top-s semantically similar memories are retrieved and injected into the prompt — keeping token counts tiny while preserving recall accuracy.
A second variant, Mem0g, augments this with a knowledge graphA structured representation where entities (people, places, events) are nodes and their relationships are labeled edges. — storing memories as entity–relationship triplets in Neo4j. This enables richer temporal reasoning ("when did Alice visit Paris?") and multi-hop inference ("what does Alice's employer think about her project?") that flat text memories struggle with.
How It Works
1. Extraction Phase
When a new message pair $(m_{t-1}, m_t)$ arrives, Mem0 builds a rich prompt $P$ combining three sources:
- A conversation summary $S$ — a compressed semantic snapshot of the entire history, refreshed asynchronously.
- The last $m$ messages — fine-grained recent context (default $m=10$).
- The new message pair itself.
An LLM extraction function $\phi(P)$ then produces a candidate set $\Omega = \{\omega_1, \omega_2, \ldots, \omega_n\}$ of salient facts from the new exchange.
2. Update Phase — The Four Operations
Each candidate fact $\omega_i$ is compared against the top-$s$ semantically similar existing memories (default $s=10$). An LLM "tool call" then decides which of four operations to apply. Rather than a separate classifier, the LLM's own reasoning determines the right action based on semantic relationship.
Click an operation above to see when it's triggered and an example.
3. Mem0g — Graph-Based Memory
Mem0g represents memories as a directed labeled graph $G = (V, E, L)$:
- Nodes $V$: entities (Alice, San Francisco, …)
- Edges $E$: relationships (lives_in, prefers, owns, …)
- Labels $L$: semantic types (Person, City, Event, …)
A two-stage pipeline first runs an entity extractor then a relationship generator, both LLM-based. Conflict detection marks outdated relationships as invalid (rather than deleting them), enabling temporal reasoning. Retrieval uses a dual strategy: entity-centric graph traversal + semantic triplet matching.
Results
Evaluated on LOCOMOA benchmark of 10 long conversations (~600 turns, ~26K tokens each) with ~200 questions per conversation across 4 types: single-hop, multi-hop, temporal, open-domain. — 10 extended conversations (~26,000 tokens each) with ~200 questions per conversation. The primary metric is LLM-as-a-Judge (J)An LLM evaluates each response as CORRECT/WRONG by comparing to the ground truth, measuring factual accuracy, relevance, and completeness. Reported as mean ± 1 std dev over 10 runs., which better captures semantic correctness than lexical metrics like F1 or BLEU.
Limitations & Open Questions
Full-context still wins on accuracy
Graph memory doesn't help multi-hop queries
Small benchmark scale (10 conversations)
Latency overhead of Mem0g graph construction
LLM-dependency for memory operations
Glossary
Context Window
RAG (Retrieval-Augmented Generation)
LLM-as-a-Judge (J)
LOCOMO Benchmark
Vector Embeddings
p95 Latency
Knowledge Graph (Neo4j)
Citation
@article{chhikara2025mem0,
title = {Mem0: Building Production-Ready AI Agents
with Scalable Long-Term Memory},
author = {Chhikara, Prateek and Khant, Dev and
Aryan, Saket and Singh, Taranjeet and
Yadav, Deshraj},
journal = {arXiv preprint arXiv:2504.19413},
year = {2025},
url = {https://arxiv.org/abs/2504.19413}
}