Mem0 is the drop-in memory layer. It wraps vector + graph + reranker behind one managed API. You add a fact, search for it later, and the layer handles dedup, conflict, and rerank for you. When this finishes you have persistent user-scoped memory in a Python REPL with no infra.
One pip install. The package on PyPI is mem0ai (the import path is mem0).
pip install mem0ai
Mem0 calls an LLM to extract facts from raw text on add(). Default backend is OpenAI. Set the env var for your shell:
export OPENAI_API_KEY="sk-..."
$env:OPENAI_API_KEY = "sk-..."
set OPENAI_API_KEY=sk-...
Drop this into mem0_demo.py and run it. Three load-bearing lines. The rest is print.
import sys
sys.stdout.reconfigure(encoding="utf-8")
from mem0 import Memory
m = Memory()
m.add("Rayyan prefers pnpm over npm", user_id="ray")
results = m.search("what package manager?", user_id="ray")
print(results)
Run it:
python mem0_demo.py
{'results': [{'id': '0c8f...',
'memory': 'Prefers pnpm over npm',
'score': 0.42,
'metadata': None,
'created_at': '2026-05-11T19:18:33.481Z',
'user_id': 'ray'}]}
Mem0 turned "Rayyan prefers pnpm over npm" into an extracted fact ("Prefers pnpm over npm"), embedded it, and stored it scoped to user_id="ray". The search() call embedded your query, ran nearest-neighbor + rerank, returned the hit. The score is a relevance number, not a confidence.
The library auto-creates a local store on first use. By default that lives in ~/.mem0/ with a SQLite + Qdrant-lite backend. For prod you point it at Pinecone, Qdrant, pgvector, or the Mem0 cloud.
Add a second fact, search, forget, search again:
m.add("Rayyan ships on Vercel", user_id="ray")
m.add("Rayyan codes from a Windows machine", user_id="ray")
all_mems = m.get_all(user_id="ray")
print(f"have {len(all_mems['results'])} memories for ray")
# forget by id
first_id = all_mems['results'][0]['id']
m.delete(memory_id=first_id)
print("deleted", first_id)
ImportError on `from mem0 import Memory`. You probably ran pip install mem0 (wrong package). Uninstall it and install mem0ai instead.
openai.AuthenticationError. Env var didn't make it into the process. Quick check: python -c "import os; print(bool(os.getenv('OPENAI_API_KEY')))". Should print True.
First call hangs. Mem0 lazy-downloads the embedding model on first use. Ten-second pause on a fresh machine is normal. After that it's local + fast.