Zep: A Temporal Knowledge Graph Architecture for Agent Memory
AI agents built on LLMs face a fundamental memory problem: static RAG retrieval cannot handle continuously evolving conversations and business data. Zep solves this by powering agent memory with Graphiti, a temporally-aware knowledge graph engine that outperforms MemGPT on the Deep Memory Retrieval (DMR) benchmark and achieves up to 18.5% accuracy improvements with 90% latency reduction on LongMemEval.
Why Existing RAG Falls Short
Standard RAG retrieves from static document corpora. Enterprise agents need memory that integrates ongoing conversations, reflects changing facts, and synthesizes data across sessions. Fitting entire conversation histories and business datasets into LLM context windows is impractical—and expensive. Zep addresses this by maintaining a dynamic, evolving knowledge graph rather than a static index.
How Graphiti Builds the Knowledge Graph
Graphiti organizes memory into three hierarchical subgraphs:
Episodes store raw input data—messages, text, or JSON—as the non-lossy foundation. Each episode carries a reference timestamp, enabling Zep to resolve relative dates like “two weeks ago” into precise datetimes. Zep implements a bi-temporal model tracking both when events occurred and when Zep ingested them.
Semantic entities and facts form the middle layer. During ingestion, Graphiti extracts named entities using a four-message context window, then resolves duplicates via hybrid cosine similarity and full-text search. Facts (edges between entities) undergo the same deduplication process. Critically, Graphiti handles temporal edge invalidation: when new facts contradict existing ones, the system sets an invalid_at timestamp on outdated edges rather than deleting them. This preserves history while keeping current facts accurate.
Communities sit at the top level. Graphiti uses label propagation to cluster strongly connected entities and generates summary nodes for each cluster. New entities join communities dynamically without requiring a full recompute, reducing latency and LLM inference costs.
Memory Retrieval: Search, Rerank, Construct
Zep retrieves memory through three steps:
- Search combines cosine semantic similarity, BM25 full-text search, and breadth-first graph traversal. BFS expands results by surfacing entities and facts within n-hops of seed nodes, capturing contextual relationships that vector search misses.
- Rerank applies Reciprocal Rank Fusion, Maximal Marginal Relevance, episode-mention frequency weighting, graph-distance scoring, or cross-encoder LLM scoring to prioritize the most relevant results.
- Construct formats the top edges (facts with validity date ranges) and nodes (entity summaries, community summaries) into a context string passed to the agent.
This pipeline reduces average context from 115,000 tokens to 1,600 tokens—the primary driver of the latency gains.
Benchmark Results
Deep Memory Retrieval
| Memory | Model | Score |
|---|---|---|
| MemGPT | gpt-4-turbo | 93.4% |
| Full-conversation | gpt-4-turbo | 94.4% |
| Zep | gpt-4-turbo | 94.8% |
| Full-conversation | gpt-4o-mini | 98.0% |
| Zep | gpt-4o-mini | 98.2% |
Zep edges out MemGPT, though the DMR benchmark has real limitations: 60-message conversations fit easily inside modern context windows, and the questions test only simple fact retrieval.
LongMemEval
LongMemEval presents 115,000-token conversations with temporally complex questions—a far better proxy for enterprise workloads.
| Memory | Model | Score | Latency |
|---|---|---|---|
| Full-context | gpt-4o-mini | 55.4% | 31.3 s |
| Zep | gpt-4o-mini | 63.8% | 3.20 s |
| Full-context | gpt-4o | 60.2% | 28.9 s |
| Zep | gpt-4o | 71.2% | 2.58 s |
The biggest gains appear in the hardest categories. With gpt-4o, Zep improves single-session-preference accuracy from 20.0% to 56.7% (+184%), temporal-reasoning from 45.1% to 62.4% (+38.4%), and multi-session from 44.3% to 57.9% (+30.7%). Single-session-assistant questions declined slightly, indicating room for further work.
Key Takeaway
Zep’s temporal knowledge graph architecture delivers higher accuracy and dramatically lower latency than full-context baselines on challenging real-world memory tasks. To explore Zep and Graphiti, start with the Graphiti GitHub repository and the publicly available experimental notebooks.