# RAG vs Memory: What AI Developers Need to Know

Part of: [AI Agent Memory](https://ninadpathak.com/articles/agent-memory/)

RAG selects evidence for one request, and memory governs state across requests. Memory that only recalls is RAG over old chats.

Canonical: https://ninadpathak.com/articles/rag-vs-memory/

By Ninad Pathak (https://ninadpathak.com/about/). Published 2026-04-19, updated 2026-11-18.

<!-- evidence-three: October 3, 2026 is the publication date printed on liao.gg/blog/agents-dont-need-memory -->
"It's All Just RAG" is a section heading in [a post Kevin Liao published on October 3](https://liao.gg/blog/agents-dont-need-memory) about memory plugins for coding agents. RAG selects source evidence for the current request, and memory governs state that has to survive, change or expire across requests, so the heading is an accusation that these products store and recall and do nothing else.

I wrote 11 guides for Mem0 and ran its team of 13 writers in early 2026, and Mem0 sells this kind of memory layer, so weigh this page with that in mind. My argument is that Operator, the Markdown workspace Liao built to replace those plugins, is a memory system by that definition, and a better one than the plugins the post attacks.

<figure class="np-figure">
  <a class="np-figure-zoom" href="https://ninadpathak.com/static/images/diagrams/rag-vs-memory/two-inputs.svg"><picture><source media="(max-width: 712px)" srcset="https://ninadpathak.com/static/images/diagrams/rag-vs-memory/two-inputs.narrow.svg" width="288" height="560"><img class="np-has-narrow" src="https://ninadpathak.com/static/images/diagrams/rag-vs-memory/two-inputs.svg" width="720" height="600" alt="Two inputs feed one bounded context window before the model. Retrieval selects source evidence from documents for the current request. Memory supplies saved state that must survive, change, expire, or return across requests." loading="lazy" decoding="async"></picture></a>
  <figcaption>RAG selects evidence for this request, and memory governs state across requests. Both land in the same bounded context.</figcaption>
</figure>

## What is the difference between RAG and memory?

RAG answers "what do the sources say about this question", and memory answers "what is still true about this user or task". Both put text in front of the model, and both can sit on the same vector index.

[AI agent memory](https://ninadpathak.com/articles/agent-memory/) is the work of keeping what the agent knows about the user or task true as facts change.

| | RAG | Memory |
| --- | --- | --- |
| Job | Select evidence for one request | Keep state across requests |
| Source of truth | A corpus someone else maintains | Records the application wrote itself |
| Goes stale when | The corpus is reindexed late | A later fact contradicts an earlier one |
| Needs | Retrieval, ranking, citation | Write rules, a read policy, supersession (a new fact replaces the old one), expiry, access scope |
| Failure looks like | A confident answer from the wrong passage | An old preference returning as if it were current |

A retriever isn't supposed to decide whether a document is still true, because the corpus owner is meant to have done that. A memory layer has nobody else to ask.

The [context window](https://ninadpathak.com/articles/llm-context-windows/) owns neither job. It is the container both land in, and a large one doesn't decide which of its contents is authoritative.

## Is agent memory just RAG?

A memory system that recalls by similarity alone is RAG over transcripts, and the plugins Liao describes work that way: they cut session transcripts into snippets, store them in a vector database, and "On every prompt, retrieve the top 5 and inject". The post's two sharpest complaints about the result are "The past is treated as truth." and "Agents can't search for what they don't know."

Liao's replacement is Operator, a workspace of Markdown documents the agent reads before a task and maintains after it.

Markdown files are the least interesting part of Operator. Its rules for when to rewrite a document and which documents to load answer each complaint Liao makes about the plugins.

| Liao's complaint about memory plugins | Operator's rule, in the post's words | What that rule is |
| --- | --- | --- |
| "The past is treated as truth." | "Facts should be rewritten when truth changes. No appending." | Supersession: the new fact replaces the old one |
| "Agents can't search for what they don't know." | "At the start of every session, Operator only injects this lean catalog into context" | A read policy: what loads into context, and when |
| Every transcript is mined into snippets | Agents are directed "to record only what the code cannot provide" | A write rule: what is allowed to be stored |

Supersession, a read policy and a write rule are needs listed under Memory in the first table, so a post titled against memory ends up specifying a memory system. The post shows that recall without those rules fails, which criticizes the plugins and supports the idea of agent memory.

A Hacker News commenter, CapitalistCartr, raised the obvious objection on October 4 and took back part of it in the same reply. It [opens with](https://news.ycombinator.com/item?id=49953780) "it look to me like his objections apply to his own solution", and after a look at the repository it grants that the agent doesn't pick documents blind, since "Every scope has a catalog file".

Anthropic's [The components of agent memory](https://www.anthropic.com/research/components-of-agent-memory), from November 6, adds a result on the write rule. Each model got one run of Pokémon Red with a folder of memory files, and "Sonnet 3.7 wrote 413 memory files across 225 folders and earned one badge", and Fable 5 wrote nine files plus a top-level `global.md` and earned four.

Anthropic ran each model once, so this is an observation and no proof. The runs do show what the stronger model chose to write: strategy and tested rules, with nothing it could read off the screen.

Liao and Anthropic disagree on who should repair a bad note. Liao wants documentation written by the working agent with the full picture still in context, "Not some background "dreamer" agent.", and Anthropic's post calls its repair pass dreaming and uses it to check notes against the original transcripts.

Anthropic's reason is that "a note that's wrong from the start or that drifts as the environment changes can be read, and trusted, by Claude in a later session." A note that was wrong when the working agent wrote it is the case a rewrite-on-change rule can't catch, so I think a serious memory system needs the working agent's rewrite and a later repair pass that checks notes against the transcript.

"RAG vs memory" is a question about who is responsible for truth over time. Under RAG the corpus owner is, and under memory your application is, whatever the files look like.

## How do RAG and memory work together in one request?

A RAG pipeline with memory reads memory first to shape the question, retrieves evidence second, and treats the memory write as a separate decision at the end.

1. **Read scoped memory.** Apply identity and access rules before any similarity search, and return only state relevant to this task.
2. **Retrieve evidence.** Use that state to form a better query against the external corpus. Say memory holds "this team deploys to Kubernetes 1.31": that fact puts the version in the query, and only the Kubernetes documentation can say what 1.31 supports.
3. **Assemble a bounded context.** Label which passages are memory and which are sources, and decide in advance which wins when they conflict.
4. **Answer from evidence.** Citations point at source records, never at a memory summary of them.
5. **Decide the write separately.** Nothing becomes durable because the model said it, so the application decides what is worth storing and what it replaces.

The write decision in step five is where Sonnet 3.7's 413-file Pokémon run went wrong. The [five-layer memory hierarchy](https://ninadpathak.com/articles/ai-memory-management/) covers which kinds of record deserve which rules.

Keeping every version of a record, so that a correction can be traced, is the job of [memory versioning](https://ninadpathak.com/articles/memory-versioning/). The rules change again for [voice agent memory](https://ninadpathak.com/articles/voice-agent-memory/), where a caller can cut a reply short.

## Which retrieval methods does agent memory need?

Agent memory needs dense search for meaning, lexical search for exact identifiers, and metadata filters for anything that must never be approximate. Agents make retrieval harder than human search does, because an agent forms its query partway through a task.

A person asks "What were the deployment steps for this service?", and an agent that has already tried the deployment asks "What failed last time?" Both need the same record from different starting points, so a test set built from polished human questions hides the mismatch.

| Problem | Method | What it can't do |
| --- | --- | --- |
| Query and record use different words | Dense retrieval | Match an exact error code |
| An identifier must match exactly | Lexical retrieval such as BM25 | Find a paraphrase |
| Tenant, time range or permission | A metadata filter applied before ranking | Rank by relevance |
| The query lacks the document's vocabulary | [HyDE](https://ninadpathak.com/glossary/hypothetical-document-embeddings-hyde/), which embeds a drafted answer | Serve as evidence, since the draft is invented |
| Constraints are buried in a sentence | [Self-querying retrieval](https://ninadpathak.com/glossary/self-querying-retrieval/), which splits search text from typed filters | Grant access the caller lacks |

Anthropic's [Contextual Retrieval explanation](https://www.anthropic.com/research/contextual-retrieval) uses an error code to show the dense and lexical split, and the [hybrid search guide](https://ninadpathak.com/articles/hybrid-search/) covers merging the two result lists. The metadata filter is the one method ranking can't replace, because an embedding score can't prove a record belongs to the current tenant.

## How do you test RAG and memory together?

Test retrieval, answer use and memory writes as separate assertions, on queries captured from the agent mid-task. Each fixture holds the agent's goal and partial state at that step, the exact query it generated, and the records and access scope that should apply.

Retrieval checks ask whether expected records appear and forbidden ones stay out. Answer checks ask whether the model used that evidence and respected the stored constraints.

The write gets its own assertions: whether the fact was allowed to be stored, whether the conversation supports it and when it expires. A correct answer can produce no durable update at all, and the Pokémon runs suggest that is often the right outcome.

## Should you use RAG, memory or both?

Use RAG when the answer lives in a corpus, memory when state has to return later, and both when stored state shapes the question and outside evidence answers it. Which database holds the records is the last thing to decide.

| The request needs | Use | Because |
| --- | --- | --- |
| Documentation, code, policy or another corpus | RAG | The answer can be checked against the selected records |
| A preference, a prior outcome or a standing constraint | Memory | Your application has to decide what gets stored, what replaces it, when it expires and who can read it |
| Stored state to form the question and sources to answer it | The loop above | Memory shapes the query, and the sources stay the evidence |

Mads Thines's [Agent memory needs its OpenTelemetry moment](https://www.lorekit.io/blog/open-agent-memory-format), from November 7, compares nine memory formats and reduces them to one idea: "a note an agent left for its future self, stored at some address, true for a while." The end of that definition, the limit on how long a note stays true, is the part worth keeping, and no retriever supplies it.

The same survey shows how little agreement there is on forgetting. Instruction files such as AGENTS.md forget only when a person edits them, and GitHub Copilot's repository facts are "Deleted after 28 days unused".

So the practical test for any memory product is to ask what happens to a fact after it stops being true. Operator has an answer, which is to rewrite the fact, and the top-five-snippets pipeline has none.

---

Work with me: email hello@ninadpathak.com, or book a 30-minute call at https://zcal.co/ninadpathak/meet

Services: https://ninadpathak.com/services/
