The world’s first unified interface for agent harnessesOpen Source4.6kPowered by UHP

InsightsNov 26, 202610 min read

Your agent's memory is a cache hierarchy: from naive RAG to knowledge graphs

Richard maps agent memory from the KV cache to long-term facts, explains three generations of RAG, and shows why the write path matters.

Richard's original cover for Your agent's memory is a cache hierarchy: from naive RAG to knowledge graphs.

Memory is a hierarchy

Originally published on X and LinkedIn on November 26, 2026. Republished with my original animations. The first GIF also appears in the announcement post.

Every six months someone declares RAG dead.

First long context was going to kill it: Gemini 1.5 shipped a 1M-token window in February 2024. Then agents were going to kill it ("The RAG Obituary", October 2025). Then this year, between July and October, three papers found the opposite: plain retrieval over raw chat history matched or beat purpose-built memory systems.

All three camps make the same mistake. They treat memory as one thing.

Memory is a hierarchy, like a CPU's: firmware, cache, RAM, disk. Each layer has its own size, speed and price, and its own rule for what gets written and what gets thrown away. Most teams build one layer and call it "memory".

I built a vector database in 2023 and pivoted six months in. Since then we've built agent memory for production.

This is the map I wish I'd had:

  • the four layers;
  • three generations of RAG, and where each one broke;
  • the part almost nobody builds: the write path.
Richard's original animation: The four layers of agent memory: weights, KV cache, working memory and long-term memory.

The four layers of agent memory

MemGPT (Packer et al., October 2023) framed an LLM's context as virtual memory, managed like an operating system. Here's the version I use:

  1. Weights (parametric memory). What the model learned in training: enormous, but frozen. "Writing" to it means training or fine-tuning. The original 2020 RAG paper named its two halves "parametric" and "non-parametric" memory.
  2. The KV cache. The model's internal state for every token it has already read. It is the fastest and cheapest layer, but it survives only while the start of the prompt stays byte-for-byte the same.
  3. Working memory. The context window, plus this session's state on disk: the plan, the scratchpad and the compaction summaries. It's what the model can see this turn. The CoALA paper (2023) uses the same name.
  4. Long-term memory. Everything that has to outlive the session:
  • what happened (episodic memory);
  • what's true (semantic memory);
  • how this person wants things done (procedural memory).

None of it is in context by default. Something has to page it in.

RAG is not a layer. RAG is the path that pages layer 4 into layer 3.

That's why "is RAG dead?" is the wrong question. You can't delete the path to your disk. You can only make it smarter.

The KV cache: memory you're already paying for

When a transformer reads your prompt, it computes a key vector and a value vector for every token in every layer. It keeps them so the next token doesn't have to recompute the whole prefix. That store is the KV cache.

It's big. Llama 3 70B has 80 layers, each with 8 key-value heads of 128 dimensions. At 16 bits, that's about 320 KB per token, so a 128K-token context holds about 40 GB of KV cache. Providers can't keep that forever.

They do keep it for a while:

  • On Anthropic's API, reading a cached prefix costs 0.1× the normal input price, or 0.05× on the newest Opus and Sonnet.
  • Writing the cache costs 1.25×.
  • A cached prefix lives 5 minutes, and every hit resets the timer.

The catch: the cache matches the prefix exactly. Change one byte at position N, and everything after N is recomputed and billed again.

Now look at where most memory systems put retrieved memories: at the top of the system prompt, rewritten every turn.

Take an illustrative 100K-token turn with a 3K-token memory block near the top. Everything after that block, about 95K tokens, is written to the cache again every turn instead of read from it. At those prices that comes to about 119K token-units of input per turn, against 14.6K when the memory goes at the end: roughly 8×.

The fix is placement, not content. Order the prompt by how often each part changes:

  1. tools and the system prompt;
  2. standing preferences;
  3. the conversation;
  4. this turn's retrieved memory, last, just before the user's message.

We learned this one in production.

Richard's original animation: How placing retrieved memory after a stable prompt prefix preserves KV cache reuse.

If you build today: log cache_read_input_tokens on every call. If it sits near zero, your memory layer is breaking your cache.

Naive RAG (2020–2023): similar isn't relevant

Lewis et al. introduced RAG in May 2020: a sequence-to-sequence model paired with a dense index of Wikipedia. By 2023 the pattern was everywhere. Gao et al.'s survey (December 2023) named it Naive RAG, "retrieve-read":

  1. Split documents into chunks, often about 500 tokens each.
  2. Embed each chunk as a vector.
  3. Embed the question, then take the top-k most similar chunks.
  4. Paste them into the prompt.

That works for "What does our refund policy say?" It breaks for memory. Here's the failure I use in every talk:

  • January: "Love my dentist in the Mission."
  • March: "I just moved from San Francisco to New York."
  • May: "Find me a dentist near home."

The chunk most similar to the May question is January's, because it mentions a dentist. The March message never mentions a dentist, so it never makes the top-k. The agent books a dentist in San Francisco.

Nothing in naive RAG knows that "home" changed. Similarity has no notion of time, of identity, or of "this replaced that".

The survey lists the symptoms: low precision, low recall, outdated information and redundancy. And the more chunks you paste in, the more the model misses whatever lands in the middle ("Lost in the Middle", July 2023).

Richard's original animation: Why naive RAG retrieves an old dentist preference instead of the current home location.

Advanced RAG (2023–2024): patch every stage

The industry's answer was to patch each step of the pipeline.

Before retrieval:

  • rewrite the question (Rewrite-Retrieve-Read, May 2023);
  • write a hypothetical answer and search with that (HyDE, December 2022);
  • index small chunks but return their parent section (LangChain's parent-document retriever, August 2023).

During retrieval:

  • Hybrid search: run keyword search (BM25, 1994) alongside vector search, then merge the two lists with Reciprocal Rank Fusion (2009).
  • ColBERT (2020): score every token of the query against every token of the document.

After retrieval:

  • rerank the candidates with a cross-encoder (2019);
  • compress whatever survives (RECOMP and LongLLMLingua, October 2023).

The best-known result is Anthropic's Contextual Retrieval (September 2024). Before indexing, it adds a short generated description of where each chunk sits in its document. Retrieval failures fell by 35%. Adding BM25 made that 49%, and adding reranking on top made it 67%.

Every one of these makes the read better. None of them fixes the dentist.

The March message still isn't similar to the question, and nothing marks January's as stale. Advanced RAG optimized the read path. Nobody owned the write.

Richard's original animation: The advanced RAG pipeline: query rewriting, hybrid search, reranking and compression.

Agentic RAG (2023–2025): let the model drive the search

The next step handed the search to the model:

  • Self-RAG (October 2023): the model decides when to retrieve, then critiques what came back.
  • Corrective RAG (January 2024): a grader checks each retrieved document and falls back to web search when they're poor.
  • Adaptive-RAG (March 2024): each question is routed by difficulty to no retrieval, a single retrieval, or many steps.
  • Agentic RAG (named in a January 2025 survey): an agent loop that plans, searches with whatever tools it has, reads, and decides whether it has enough.

Then coding agents took it all the way.

Boris Cherny told the Latent Space podcast (May 2025) that the earliest versions of Claude Code used RAG with a vector index. The team switched to plain agentic search, glob and grep, and it "outperformed everything. By a lot." Five months later, "The RAG Obituary" declared vector retrieval dead.

My contrarian take: grep won code. It loses memory.

Code has names. Every function, file and symbol is a unique string you can search for, and the code on disk is the current truth; git keeps the history.

Your users' lives don't have names:

  • "the thing we discussed about the Q3 budget" has no identifier;
  • the facts are spread across months;
  • the transcript isn't the truth. People change their minds, and the latest statement silently overrides the earlier one.

Grep for "dentist" and you get January, not March.

And an agent that searches from scratch every session pays tokens every time to rediscover the same facts, then forgets them again. Agentic RAG is the most expensive way to forget.

Richard's original animation: An agentic RAG loop plans, searches and critiques its retrieved information.

The 2026 twist: "just use long context" and "raw RAG beats memory"

Two camps say you don't need a memory layer at all.

Long context.

  • The windows: they went from 1M tokens (Gemini 1.5, February 2024) to 10M (Llama 4 Scout, April 2025).
  • The catch: Chroma's "Context Rot" study (July 2025) found that every one of the 18 models it tested got less reliable as its input grew.
  • What we measured: we saw the same thing on BEAM, a benchmark whose conversations run to 10M tokens. Giving the model about 113K tokens of well-chosen memory per question, instead of about 400K, raised accuracy by 3.4 points. On questions we hadn't used to pick the setup, the gain was 2.5 points.
  • The twist: the same cut cost 1.4 points at 1M. The right amount of context depends on scale. It's a cache-sizing problem, not "more is better".

Raw RAG.

  • The papers: between July and October this year, at least three found that plain retrieval over raw chat turns matches or beats explicit memory systems. One found no consistent advantage for six memory systems. Another ranked raw-history RAG first in 6 of 7 settings.
  • My read: I agree with the data, not the conclusion. Most of the systems they tested are RAG with a new name. They extract snippets, embed them, retrieve by similarity and paste them back in. Extraction throws information away, so a lossless read beats a lossy one. That's all those papers show.
  • What they don't test: what memory is for. That means updates, contradictions, forgetting, and carrying one person's memory across agents. On structured tasks such as ledgers and to-do lists, plain RAG struggles (StructMemEval, February 2026).
Richard's original animation: The context and memory evidence compared across long-context and raw-history approaches.

Long-term memory: a knowledge base that writes itself

So what's the difference between a knowledge base and memory? Who writes it.

People curate a knowledge base. Memory is a knowledge base the agent writes itself, from every conversation. It holds three kinds of records (the episodic, semantic and procedural split from CoALA, 2023):

  • Episodic: what happened, when, and who said it.
  • Semantic: what's true now, stored as facts about people and things.
  • Procedural: how this person wants things done, such as preferences and standing instructions.

The write path is where the real engineering is. Here's the shape of ours, in concepts:

  1. Keep every raw turn, word for word, never edited. This is the lossless layer the raw-RAG papers are right about. Don't throw it away.
  2. Extract facts as structure: subject, attribute, value, who said it, when it was said, and when it was true. Those last two are different times. Zep's Graphiti paper (January 2025) describes the same "bi-temporal" idea.
  3. Reconcile; don't overwrite. A new value closes the old one. A contradiction gets a link. Every fact points back to the turn it came from.
  4. Consolidate: session summaries and standing preferences.
  5. Forget deliberately. Agents can retire facts. Only people can erase them.

Now the dentist works:

  • "I moved to New York" closes "lives in San Francisco".
  • At the start of the turn, the read path pages in only what's believed now. It walks the graph from you to home to New York, and attaches the source turn so the model can check it.

Retrieval still matters. It's one read path inside a system that writes.

Richard's original animation: A self-writing memory system extracts, reconciles and versions facts with source history.

Writes are where memory breaks

When our scores went flat, the fixes that moved them most were never prompts. They were fixes to how memory was written.

Here are three kinds of bug we found in our own memory builds. You probably have them too.

Lost order within a day.

  • What happened: every turn in a session was stamped with the session's date at midnight. Two values said on the same day ("the budget is $40K" at 9:02, "make it $55K" at 9:40) looked simultaneous, so "which one is current?" became a coin flip.
  • How often: in one test slice, 6 of our 7 knowledge-update misses were exactly this.
  • Fix: every turn keeps its own time and position.

Silent drops.

  • What happened: the extraction model sometimes left out a required field, and the store refused the record without saying so. About one in ten sessions ended up with no summary.
  • Fix: accept the record, count the slips, backfill, and alert on the count.

Write races.

  • What happened: two writers read the same fact within 80 ms, and both wrote "version 2". Recall then returned two current versions of one fact.
  • Fix: versioned writes with one winner, plus a check that no fact ever has two live versions.

If your memory benchmark is flat, read your writes before you tune your prompts.

One turn through all four layers

Put together, a single turn looks like this:

  1. The stable prefix (tools, system prompt, standing preferences) comes straight from the KV cache.
  2. Working memory supplies the recent turns and the session's notes.
  3. The read path pages in the long-term facts that are believed now, with their sources, at the end of the prompt.
  4. The model answers.
  5. After the turn, the write path extracts, reconciles and consolidates in the background. The user never waits for it.
  6. The weights never change.
Richard's original animation: One agent turn reads the cache, working memory and long-term facts, then writes memory.

My bet

The big labs are already building down this hierarchy:

  • ChatGPT: started referencing all past chats in April 2025.
  • Claude: gained memory in stages from August 2025, and reached the free plan in March 2026.
  • Claude Code: started saving its own memory in February 2026.

Today most of these are files and summaries. Versioned facts with time come next.

My bet: by Q1 2027, every major harness ships a memory layer that writes itself (extract, update, forget), and RAG becomes one read path inside it.

The question I don't see anyone answering yet: how do you evaluate the write path? Today's benchmarks mostly test recall, and they partly measure their own judges.

If you're working on that, I want to hear from you.

→Next

Run your agent through a shared interface

Use HarnessRouter to execute supported harnesses and inspect their task traces.