research
Mem0 paper reimplementation
A local-first reimplementation of the Mem0 long-term memory loop for LLM agents with an 8.19x p95 latency improvement.
8.19x p95
Problem
Agents forget. Mem0 proposes a memory loop that extracts facts from conversations and keeps them current. I wanted to understand it end to end and see how fast the memory path could be made.
Approach
- Persist conversation messages, then extract compact candidate memories from each new message pair.
- Compare each candidate against existing memories and choose ADD, UPDATE, DELETE, or NOOP, keeping soft deletes and supersession history.
- Retrieve relevant memories at query time and ground the response in them.
- Local-first by design: SQLite for storage, a persisted job queue for worker-style processing, batched inserts, and optional CUDA acceleration for embedding math and similarity search.
- An evaluation harness with built-in scenarios checks duplicates, contradictions, updates, and retrieval.
Results
- 8.19x improvement in p95 latency on the memory path.
- Deterministic and testable without API keys, with clean seams for real LLM and embedding providers.
Stack
Python, SQLite, PyTorch (CUDA), FastAPI, Ollama (optional).