Agent Memory Is a Database Problem, Not a Model Problem
The question “how do I give my agent memory?” is the wrong question. It assumes memory is a parameter you tune. It is not. Memory is a data management system with four modules: Representation & Storage ($\mathcal{R}$), Extraction ($\mathcal{S}$), Retrieval & Routing ($\mathcal{Q}$), Maintenance ($\mathcal{U}$). Zhou et al. (2026) formalize this as $\mathcal{M}_{sys} = \langle \mathcal{R}, \mathcal{S}, \mathcal{Q}, \mathcal{U} \rangle$ and evaluate 12 systems across 5 workloads (LoCoMo, LongMemEval, DB-Bench, LongBench, MemoryAgentBench). The results are humbling.
No Single Backend Wins
| Architecture | Backend | Wins On | Loses On |
|---|---|---|---|
| Stream-and-Reflection (MemoryBank, MemoChat) | In-context / KV-cache | Short horizon, low latency | Capacity, long-horizon stability |
| Hierarchical Tiered (MemGPT/Letta, MEM1, MemAgent) | Vector + context window | Cost control, explicit promotion/eviction | Retrieval fidelity on fuzzy queries |
| Knowledge Graph (Zep, Mem0g, Cognee) | Neo4j / graph DB | Temporal queries, entity resolution | Semantic similarity, schema rigidity |
| Composite Hybrid (A-MEM, MemOS, SimpleMem, MemoryOS, LightMem, Mem0) | Vector + Graph + SQL + BM25 | Best overall — routes per query type | Operational complexity, cost, latency |
A-MEM (composite hybrid) wins on effectiveness (RQ1) and retrieval fidelity (RQ2) by anchoring dense vectors to structured “atomic notes” with semantic links, then traversing locally. Zep wins on update robustness (RQ3) because its temporal knowledge graph natively versions entities. MemGPT wins on operational cost (RQ5) by keeping hot memory in-context and cold in vector DB. There is no Pareto optimum.
The Four Modules You Actually Control
$\mathcal{R}$ — Representation & Storage
Logical: Token sequences (flat), Graphs (entities + relations + time), Composites (text + metadata + embeddings + links).
Physical: In-context (transient), Single-engine (vector or graph or SQL), Multi-engine (all of the above).
Decision: If your workload is “what did the user say about X last month?” → graph. “Find semantically similar bugs” → vector. “Exact fact lookup” → SQL/keyword. Hybrid = all three.
$\mathcal{S}$ — Extraction
Three strategies, increasing structure:
- Raw concatenation (MEM1, MemAgent) — dump tokens, let attention sort it out. Cheap, fails at scale.
- Schema-free semantic (Mem0, LightMem) — LLM distills free-form facts or entropy-gated vectors. Flexible, noisy.
- Schema-constrained structured (Zep, Mem0g, A-MEM, Letta, MemOS) — LLM populates rigid triplets / typed payloads. Higher precision, requires schema design.
Rule of thumb: Start schema-free. Add schema when extraction errors cost you.
$\mathcal{Q}$ — Retrieval & Routing
| Mechanism | Use When |
|---|---|
| Native attention (MEM1) | Context fits, latency critical |
| Dense KNN (Mem0, LightMem) | Semantic similarity, no temporal need |
| Graph traversal (Zep, Mem0g) | “What happened after X?” / entity-centric |
| Agentic routing / function calling (Letta, SimpleMem) | Query is ambiguous, needs planning |
| Multi-stage hybrid (A-MEM, MemOS) | Production workloads — route by query type |
Routing is the product. A-MEM’s “dense anchor + local graph traversal” cuts retrieval latency 40% vs pure graph by narrowing candidates first.
$\mathcal{U}$ — Maintenance (The Ignored One)
Conflict resolution (user said X, now says Y), capacity management (evict/promote), semantic consolidation (merge duplicates, infer relations). Most systems punt. MemGPT has explicit promotion/eviction. Zep versions automatically. A-MEM runs a background consolidator. If you don’t design $\mathcal{U}$, your memory rots. Stale facts accumulate. Contradictions multiply. Retrieval precision tanks.
What This Means for Builders
- Don’t build a memory system. Pick a hybrid (A-MEM, MemOS, Mem0) or compose: vector DB (pgvector/LanceDB) + graph (Neo4j/Kuzu) + keyword (SQLite FTS) + a thin router.
- Design the extraction schema early. Even schema-free systems benefit from “fact type” tags (preference, fact, event, procedure).
- Instrument retrieval fidelity. Log: query → retrieved IDs → judge score (faithful/incomplete/hallucinated). Sun et al. (2025) show LLM-as-judge works for this.
- Budget for maintenance. A nightly consolidator job is not optional. It is the difference between a memory that improves and one that degrades.
- Context window ≠ memory. The window is a cache. Treat it like one: populate it from $\mathcal{Q}$, evict by $\mathcal{U}$, never assume it holds truth.
The Hard Truth
Prompt engineering (“remember this!”) works for 5 turns. It fails at 50, 500, 5000. The model does not learn. The weights do not change. The only thing that persists is what the host writes to $\mathcal{R}$ and retrieves via $\mathcal{Q}$. Memory is infrastructure. Build it like infrastructure.