| name | mem0-2-0-1 |
| description | Self-improving memory layer for LLM agents (Mem0 v2.0.1) enabling persistent context across sessions with single-pass ADD-only extraction, multi-signal hybrid search (semantic + BM25 + entity linking), and support for both managed platform and open-source deployments. Use when building LLM agent workflows requiring persistent memory, semantic recall across conversations, entity-linked memory retrieval, or integrating with managed Mem0 platform. |
Mem0 v2.0.1
Overview
Mem0 ("mem-zero") is a self-improving memory layer for LLM agents that enables persistent context across sessions. It creates stateful agents that remember user preferences, learn from interactions, and evolve behavior over time. Unlike traditional RAG systems that are stateless, Mem0 stores extracted facts in vector storage with optional graph connections, achieving +20 points on LoCoMo (71.4 → 91.6) and +26 points on LongMemEval (67.8 → 93.4) while cutting extraction latency roughly in half.
v2 introduces a fundamentally redesigned memory algorithm:
- Single-pass ADD-only extraction — one LLM call per
add(), no UPDATE/DELETE during extraction. Memories accumulate; nothing is overwritten.
- Multi-signal hybrid search — semantic embeddings, BM25 keyword matching, and entity linking scored in parallel and fused.
- Entity linking — entities are extracted, embedded, and linked across memories for retrieval boosting.
- Agent-generated facts as first-class — when an agent confirms an action, that information is stored with equal weight.
Mem0 offers two deployment modes:
- Mem0 Platform — Fully managed service at
api.mem0.ai with automatic scaling, dashboard, graph memory, webhooks, and per-user API keys. Accessed via MemoryClient.
- Mem0 Open Source — Self-hosted SDK (Python + Node.js) with full control over LLMs, vector stores, embedders, and rerankers. Accessed via
Memory.
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
- Replacing OpenAI's native Memory API with 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
run_id. Expires automatically when the session ends.
- 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 (v2)
Every add() call passes through three stages:
- Information extraction — An LLM identifies key facts, preferences, and decisions from the conversation in a single pass. No UPDATE/DELETE — memories only accumulate.
- Conflict resolution — Existing memories are checked for duplicates or contradictions; latest truth wins.
- Storage — Memories land in vector storage with entity embeddings for future retrieval.
Search Pipeline (v2)
- Query processing — Natural-language query is cleaned and enriched.
- Multi-signal retrieval — Semantic embeddings, BM25 keyword matching, and entity matching run in parallel.
- Filtering & reranking — Logical filters narrow candidates; optional reranker fine-tunes ordering.
- Results delivery — Formatted memories with metadata, timestamps, and categories return to the caller.
Entity Scoping
Mem0 scopes memories by entity identifiers:
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
Use run_id when you want short-term context to expire automatically; rely on user_id for lasting personalization.
Response Format
All operations return a consistent format: {"results": [...]}. No more version or output_format parameters needed.
Installation / Setup
Python SDK
pip install mem0ai
For enhanced hybrid search with BM25 keyword matching and entity extraction, install with NLP support:
pip install mem0ai[nlp]
python -m spacy download en_core_web_sm
Node.js SDK
npm install mem0ai
CLI
npm install -g @mem0/cli
mem0 init
mem0 add "Prefers dark mode and vim keybindings" --user-id alice
mem0 search "What does Alice prefer?" --user-id alice
Platform Setup
- Sign up at app.mem0.ai
- Get an API key from the dashboard
- Initialize the client:
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
Open Source Setup
from mem0 import Memory
m = Memory()
Default OSS components (override via Memory.from_config):
- LLM: OpenAI
gpt-5-mini (via OPENAI_API_KEY)
- Embeddings: OpenAI
text-embedding-3-small
- Vector store: Local Qdrant at
/tmp/qdrant
- History store: SQLite at
~/.mem0/history.db
Self-Hosted Server
cd server && make bootstrap
cd server && docker compose up -d
Auth is on by default. Set AUTH_DISABLED=true for local dev only.
Usage Examples
Basic Add and Search (OSS)
from mem0 import Memory
m = Memory()
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")
results = m.search("What do you know about me?", filters={"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")
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")
results = client.search(
"What are Alice's hobbies?",
filters={"user_id": "alice"}
)
all_memories = client.get_all(user_id="alice")
client.update(memory_id="<id>", data="Alice loves mountain hiking")
client.delete(memory_id="<id>")
client.delete_all(user_id="alice")
Full Chat with Memory Loop
from openai import OpenAI
from mem0 import Memory
openai_client = OpenAI()
memory = Memory()
def chat_with_memories(message: str, user_id: str = "default_user") -> str:
relevant = memory.search(query=message, filters={"user_id": user_id}, top_k=3)
memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant["results"])
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-5-mini", messages=messages
)
assistant_response = response.choices[0].message.content
messages.append({"role": "assistant", "content": assistant_response})
memory.add(messages, user_id=user_id)
return assistant_response
TypeScript / JavaScript (Platform)
import MemoryClient from "mem0ai";
const client = new MemoryClient({ apiKey: "your-api-key" });
await client.add(
[{ role: "user", content: "I love hiking on weekends" }],
{ user_id: "alice" }
);
const results = await client.search("What does Alice like?", { user_id: "alice" });
TypeScript / JavaScript (OSS)
import { Memory } from "mem0ai/oss";
const memory = new Memory();
await memory.add("I love hiking on weekends", { userId: "alice" });
const results = await memory.search("What does Alice like?", { userId: "alice" });
Advanced Topics
Memory Operations: Add, search, update, delete workflows with v2 pipeline details and Platform vs OSS differences → Memory Operations
Configuration & Components: LLM providers (18+), vector databases (24+), embedders (10+), rerankers (6+) with full setup guides → Configuration and Components
Platform Features: Entity scoping, async clients, multimodal support, webhooks, custom categories, advanced retrieval, v2 memory filters → Platform Features
Open Source Features: Self-hosted REST API server, async memory, metadata filtering, reranker search, OpenAI compatibility → Open Source Features
API Reference: REST endpoints for the managed Platform and OSS server → API Reference
Integrations & Migration: LangChain, CrewAI, LlamaIndex, AutoGen, Vercel AI SDK, MCP, and v1→v2 migration guide → Integrations and Migration