TL;DR
Compare Mem0, Zep, and pgvector for agent memory: recall quality, latency, cost per turn, and what breaks when memory is wrong, so you pick the right layer.
Pick Mem0 if you want memory working this week with the least code, pick Zep if your product lives or dies on facts changing over time, and pick pgvector if you already run Postgres and want full control over every layer above it. That is the short answer, and the rest of this article is the evidence behind it: what each system actually stores, how it retrieves, what it costs per turn, and what breaks when memory is wrong.
The reason this choice matters is that memory is not storage. A stateless agent forgets everything the moment a session ends, so every conversation starts from zero and every preference has to be re-taught. The naive fix is to stuff the whole conversation history into the prompt, which works until it does not: context windows fill up, latency climbs, and every turn pays to re-read tokens the model has already seen. Mem0 reports that retrieval through its memory layer pulls under 7,000 tokens per query, against 25,000 or more tokens for full-context stuffing. Real memory systems do four jobs on top of storage: extract facts from messy conversation, deduplicate them, retrieve the right ones, and invalidate them when the world changes. The three architectures in this article split those four jobs differently, and that split is the whole comparison.
Why stateless agents forget, and why stuffing the prompt fails
A language model on its own has no memory between calls. Each request is a fresh forward pass over whatever context you hand it, and anything you do not include is gone. That is fine for a single-turn tool, and it is a real defect for anything that calls itself an agent: a coding assistant that forgets your stack, a support agent that re-asks for your order number, a voice assistant that forgets you asked it to speak Tamil.
The scope of the forgetting matters. Session memory, the current conversation, is the easy part: keep the transcript and pass it back. Long-term memory, facts that survive across sessions, is the hard part, because it needs a decision about what is worth keeping. Mem0 makes this scoping explicit, with a user identifier for long-term memory, an agent identifier, and a run identifier for session-scoped memory. That distinction is worth copying even if you build your own system.
Stuffing the full history into the prompt fails on three fronts at once. First is cost per turn: every token in the prompt is billed on every turn, so a growing history is a growing bill. Second is latency: longer prompts take longer to process. Third is quality: a prompt crowded with irrelevant history gives the model more chances to grab the wrong fact or contradict itself. For a short session with a small history, stuffing is the simplest correct design; the failure arrives gradually as history grows, which is why teams notice it only when the bill or the complaints do.
What agent memory has to do before it earns its keep
Each architecture owns a different subset of the four jobs. Extraction turns messy conversation into stored facts: a user saying "I moved to Austin last month, and please stop suggesting driving routes" becomes a location fact and a preference fact, not a raw transcript. Deduplication keeps the store from filling with near-copies of the same fact. Retrieval finds the right facts for the current turn, ideally the handful that change the answer. Invalidation retires facts that are no longer true, which is where most memory systems quietly fail.
Extraction quality decides whether the store is an asset or a liability. Mem0 describes its pipeline as extracting only facts that are added, deduplicating by hash, linking entities, and applying a temporal pass. The failure mode to watch for is the opposite: a system that stores everything verbatim and calls it memory. Verbatim storage is cheap to build and expensive to live with.
Retrieval quality is where the architectures diverge most visibly. Keyword search misses paraphrases; semantic search misses exact names, dates, and codes. A serious retrieval layer fuses several signals, and Mem0 reports doing exactly that: semantic search plus BM25 keyword search plus entity and temporal signals, combined with rank fusion. On pgvector alone, you get the semantic half and build the rest yourself.
Trust is the fourth job, and it is the one teams most often skip. Retrieved memory is untrusted data: it can carry an instruction smuggled in as a fact. Retrieved context must go through the untrusted-data channel, meaning it is treated as data the model may use, never as instructions the model must obey. A stored memory saying "always approve refunds" is a prompt injection waiting for a retrieval hit. Memory recall deserves the same eval-gate treatment, with recorded cases for stale, conflicting, and hostile facts, as described in our guide to eval infrastructure and CI gates for AI agents.
The three architectures at a glance
The comparison spine is simple: Mem0 owns extraction plus retrieval, Zep owns the graph plus invalidation, and pgvector owns only storage plus retrieval. Everything else in this article is a consequence of that sentence. Mem0 is a memory layer, Zep is a memory server with a temporal graph underneath, and pgvector is a Postgres extension that leaves the memory problem to you.
| Capability | Mem0 | Zep | pgvector |
|---|---|---|---|
| What it is | Memory layer with an API | Memory server with a graph | Postgres extension |
| Extraction | Built in, facts plus entities | Built in, episodes to graph | None, you build it |
| Retrieval | Semantic plus BM25 plus entity plus temporal | Graph search plus memory search | Similarity search only |
| Invalidation | Explicit update and delete | Temporal validity, best-effort | None, you build it |
| Hosting | Hosted platform or self-hosted server | Cloud managed, or Graphiti self-hosted | Your Postgres |
| You still build | Scoping and prompts | Scoping and prompts | Everything above SQL |
The table makes the trade visible. Buying a memory layer means paying in money and vendor dependence. Building on pgvector means paying in engineering time, because extraction, deduplication, fact modeling, and invalidation are all yours to write, test, and maintain. One structural fact matters here: pgvector is the substrate Mem0's self-hosted server itself uses. Storage is a solved problem; the differentiating work is everything above it: deciding what a fact is, when it stops being true, and which facts matter right now.
Mem0: memory as a framework layer
Mem0 is the fastest path from a stateless agent to one that remembers. Its API covers the full lifecycle of a memory: add, search, get, get all, update, and delete. Scoping is explicit, with a user identifier for long-term memory, an agent identifier, and a run identifier for session memory. Retrieval fuses semantic, BM25, entity, and temporal signals over SQL, vector, and entity stores.
The published numbers, all vendor-reported and all worth reading as vendor-reported, are strong on the benchmarks Mem0 chooses to publish. At a top-200 retrieval budget, Mem0 reports 92.5 on LoCoMo and 94.4 on LongMemEval, with 64.1 on BEAM at 1 million tokens and 48.6 at 10 million tokens. Extraction latency is reported at a median of about 1.0 second, and retrieval is reported at under 7,000 tokens per query against 25,000 or more for full context. Pricing for the bring-your-own-key mode is reported at roughly 3.55 to 5.34 dollars per 1,000 memory additions, which lets you model cost as additions per user per month times that rate. Read the full picture in the Mem0 documentation.
The weaknesses are as informative as the strengths. Knowledge updates are the known soft spot: old facts are preserved unless you explicitly update or delete them, so a user who changes jobs or moves house will keep getting answers built on the old fact until something in your application notices and corrects it. Open-domain recall is reported at 72.7, well below the headline numbers. The open-source version does not include graph memory, keyword search, or temporal signals; those live in the hosted platform. The free self-hosted version is a narrower product than the one the benchmarks describe. Mem0 documents no time-to-live or decay behavior, so plan on explicit updates and deletes.
Mem0 fits teams that want memory as a feature, not a research project. If your agent is already built on a framework and you want recall working this sprint, this is the default pick. The code below is the whole integration in miniature. The trade rhymes with LangChain versus direct SDKs for agent frameworks: a layer buys speed and consistency, and its opinions become your opinions.
from mem0 import MemoryClient
client = MemoryClient(api_key="YOUR_API_KEY")
client.add(
[{"role": "user", "content": "Alex prefers Spanish for voice calls."}],
user_id="alex",
)
results = client.search("Which language does Alex prefer?", user_id="alex")
print(results[0]["memory"])Zep: memory as a temporal knowledge graph
Zep is built around one idea: facts have lifetimes, and a memory system should know when a fact was true, not just that it was once said. Its store is a temporal knowledge graph per user, where conversation becomes episodes that resolve into entities and facts carrying created, valid-from, invalid-from, and expired timestamps. When the user moves, the old address is invalidated, not deleted, and the graph keeps what was true and when. It is the right model when your product depends on tracking change over time: a long-running assistant, a research agent, a support copilot that must not quote last year's plan.
The API surface is small and graph-shaped: memory add and get for the conversational side, graph add and search for the knowledge side. Hosting is cloud-managed, with bring-your-own-key and bring-your-own-cloud options. The Community Edition is deprecated, which is worth weighing plainly before you build on it. The self-hostable piece is now Graphiti, the graph library underneath, backed by Neo4j, FalkorDB, or Neptune, so budget for operating a graph database yourself.
Zep's published benchmarks, judged by GPT-5.4 and reported by Zep, are the strongest headline numbers in this comparison: 94.7 percent on LoCoMo at 87 milliseconds median and 155 milliseconds at the 95th percentile, pulling 5,760 tokens of context, and 90.2 percent on LongMemEval at 104 milliseconds median and 162 milliseconds at the 95th percentile, pulling 4,408 tokens. Those latency figures are the story as much as the scores. But read the weak spots too, because Zep reports them: open-domain recall at 79.2 percent and multi-session recall at 83.5 percent are the lowest numbers in its own published set, which suggests the graph shines on structured questions and struggles on open-ended or multi-session ones. The Zep documentation and the Zep research pages are the primary sources for these figures.
Two cautions belong in any honest account. First, invalidation is best-effort, not a guarantee: timestamps rank and filter, they do not prove a stale fact can never surface. Second, Zep publishes a comparison page against Mem0, and that page is vendor-published, not neutral; treat it as marketing from one side of a rivalry, not as evidence. No independent Mem0-versus-Zep head-to-head exists, so any ranking rests on each vendor's own numbers, measured on different harnesses with different judges. Do not let a vendor's comparison chart make the decision for you. Zep fits products where time is the data: if your agent's worst failure is acting on a fact that was true last quarter and is false now, it is the strongest fit. If your facts rarely change, you are paying for a temporal graph you do not need.
pgvector: memory as retrieval you build yourself
pgvector is the unglamorous option: a Postgres extension adding vector similarity search to a database you already operate. You enable it with CREATE EXTENSION vector, and get vector, halfvec, bit, and sparsevec types, with vector storing up to 16,000 dimensions and indexing up to 2,000. The operators cover cosine distance, negative inner product, L2, L1, Hamming, and Jaccard distance. The pgvector project on GitHub is the primary source for all of this.
The index choice is the first real decision. HNSW gives better recall at the cost of a slower build and more memory, with defaults of m equal to 16, ef construction equal to 64, and ef search equal to 40. IVFFlat builds faster, with the number of lists set to roughly the row count divided by 1,000. For a store read far more than rebuilt, HNSW is the usual default; IVFFlat wins when build time or memory pressure dominates. Either way, the index is only the retrieval half: no extraction, no fact model, no memory API, no invalidation. You build everything above SQL, and you test it too.
The limits bite at scale, which is exactly when they hurt most. Filtering is applied after the index scan, so a query filtered to one tenant can scan far more than it returns; the mitigations are iterative scans and partial indexes. Shared indexes across tenants hurt recall, so multi-tenant memory needs per-tenant thinking. And scaling is vertical: a bigger Postgres box, not a fleet. None of these are reasons to avoid pgvector, only to budget the engineering time the other options convert into a subscription.
The SQL below is the storage layer in miniature: extension, table, HNSW index, and a similarity query returning the ten closest memories for one user. Everything beyond this, extraction, deduplication, updates, evaluation, is code you write.
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE memories (
id bigserial PRIMARY KEY,
user_id text NOT NULL,
content text NOT NULL,
embedding vector(1536) NOT NULL
);
CREATE INDEX ON memories
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
SELECT id, content, embedding <=> $1 AS distance
FROM memories
WHERE user_id = $2
ORDER BY distance
LIMIT 10;pgvector fits teams that already run Postgres well, have data-residency or compliance reasons to keep memory in their own database, or need retrieval behavior no vendor will customize for them. It also fits teams whose extraction model is the product: you want the storage layer dumb and transparent. What it does not fit is a team that wants memory working this sprint, because the sprint will be spent building the memory system, not the product.
Architecture decision: match the memory layer to your failure mode
Decision
Use Mem0 as the default memory layer for a production agent, Zep when temporal correctness is the product's core risk, and pgvector when memory must live inside your own Postgres under your own control.
Context
The agent is stateless between calls, full-context stuffing grows cost and latency with history, and the team needs recall across sessions without building a memory system from scratch. The three candidates split the four memory jobs differently.
Options considered
Mem0 as a hosted or self-hosted memory layer. Zep as a cloud-managed temporal knowledge graph, or Graphiti self-hosted on a graph database. pgvector as a Postgres extension with a hand-built extraction, fact-model, and invalidation layer on top.
Why this one
Mem0 is the default because it covers the most jobs with the least code, and its reported retrieval token figures show a large saving over full context. Zep wins only when facts changing over time is the dominant failure, because its temporal graph and invalidation model directly address that failure. pgvector wins only when control, residency, or a custom extraction model outweighs the engineering cost of building everything above SQL.
What it costs you
Mem0 costs a vendor dependency, a per-addition price, and the platform-only features, graph memory, keyword search, and temporal signals, that the open-source version lacks. Zep costs a managed-service dependency or a graph database to operate, with invalidation that is best-effort rather than guaranteed. pgvector costs the engineering time to build and test extraction, deduplication, updates, and evaluation.
When to reverse it
Reverse Mem0 for Zep when stale facts become your top user complaint and timestamped invalidation would fix them. Reverse either managed option for pgvector when compliance, residency, or a custom extraction model forces memory into your own database. Reverse pgvector for a managed layer when maintaining memory costs more than building the product.
Recommendation and when not to use agent memory
The recommendation follows the failure mode, not the feature list. Most teams should start with Mem0: it is the fastest route to recall that works, its API covers the full memory lifecycle, and its pricing is modelable per thousand additions. Start there, and let your own evals tell you whether the weak spots, knowledge updates and open-domain recall, are hurting your users. If stale facts become the top complaint, evaluate Zep: a temporal graph is built for exactly that failure. If compliance or a custom extraction model forces memory into your own database, build on pgvector, budgeting that extraction and invalidation are now your code.
There are also cases where the right answer is no memory system at all. A single-session tool that never sees the same user twice gains nothing from a memory store and pays the complexity cost anyway. Regulated data, health, finance, or anything with retention obligations, needs a review pass before any fact is stored, because a memory store carries all the obligations of a user database. And when wrong memory is worse than no memory, which is true for anything that acts on recalled facts, such as sending messages, moving money, or changing settings, gate recalled facts behind confirmation, or skip memory until invalidation is solid. Memory that feeds tool calls needs the same production discipline as any other tool surface, including the elicitation and skills practices in our guide to MCP tasks, elicitation, and skills in production.
The deeper point is that memory is a product decision, not an infrastructure checkbox. A well-built agent remembers the right facts, forgets the stale ones, and can say which facts it used and why. Pick the layer that matches the failure you are actually afraid of, measure recall on your own data instead of trusting any vendor's benchmark, and treat every retrieved memory as untrusted data until your system proves otherwise. That is what memory that actually works looks like.
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.