Glossary

Cache-augmented generation

An alternative to RAG that preloads a small knowledge base into a long-context model and caches its processed state, so questions are answered without a retrieval step.

Cache-augmented generation (CAG) is an alternative to retrieval augmented generation in which the whole knowledge base is loaded into the model’s context window ahead of time and its processed state is cached, so questions are answered without a retrieval step. It works when the knowledge fits in the window and changes rarely. The term comes from a December 2024 paper titled “Don’t Do RAG: When Cache-Augmented Generation is All You Need for Knowledge Tasks” by Brian J. Chan, Chao-Ting Chen, Jui-Hung Cheng and Hen-Hsen Huang.

How cache-augmented generation works

CAG has three steps. The documents are placed in the prompt of a long-context model and processed once. The model’s internal attention state for that prefix, the KV cache, is saved. Each new question is then appended to the cached prefix, so the model answers with the full knowledge base in view without reprocessing it. Between sessions the cache is reset to the document prefix by discarding the tokens added by earlier questions.

The idea is close to the prompt caching offered by model APIs, which bills a repeated prefix at a lower rate and returns faster. CAG is the design choice to rely on that cached prefix as the knowledge source instead of retrieving passages for each query.

CAG vs RAG

Aspect

Cache-augmented generation

Retrieval augmented generation

Knowledge source

Whole corpus preloaded in context

Passages retrieved per query

Corpus size

Must fit in the context window

Limited by storage, not the window

Retrieval errors

None, since nothing is selected

Wrong or missing passages possible

Latency per query

Low once the cache is built

Adds a search step

Updates

Rebuild the cache when content changes

Re-index the changed documents

Context per query

The full corpus, cached or not

Only the retrieved passages

The paper reported that CAG matched or beat RAG pipelines on question-answering benchmarks with lower response times, on knowledge bases small enough to fit in context. RAG vs CAG covers the comparison in more depth, and RAG vs long context the wider debate.

Limits

Size is the first limit. Even a window of a million tokens holds a few thousand pages at most, and most company knowledge bases are larger. Accuracy is the second. Models use long inputs unevenly: facts in the middle are recalled less reliably, the effect known as lost in the middle, and accuracy falls as input grows, described as context rot. Research summarised on the reduce token costs page puts a model’s effective context at roughly 50 to 65 percent of its advertised window.

Cost is the third. Caching lowers the price of a repeated prefix without removing it, so every question still pays for the full corpus, and provider caches expire after a set time. Freshness is the fourth: any change to the documents means rebuilding the cache, which is manageable for a fixed manual and awkward for a wiki that changes daily, the problem covered under stale knowledge. Prompt caching won’t save you and why “just use long context” fails in production go further into the trade-offs.

When CAG is a good fit

CAG suits a small, stable reference set that most questions draw on: a product manual, a policy handbook, a set of FAQs or the rules of a game, as in a narrow documentation assistant. It also suits a single long document studied in one session. A common hybrid uses retrieval to pick a few whole documents and then loads them into context, which keeps CAG’s simplicity without requiring the whole corpus to fit. For knowledge about a user that grows across sessions, an agent memory layer fits better than either.

CAG and Exabase

Exabase sits on the retrieval side, and it is useful in CAG setups as well. Extract turns PDFs, Word files, web pages, audio and video into clean text, and adding ?format=markdown returns a readable Markdown document ready to place in a prompt, which is the preparation step CAG needs. When the corpus outgrows the window, Deep Search retrieves sub-document passages instead, and its precision setting keeps the prompt short. Memory holds per-user facts that do not belong in a shared cache, at a few hundred tokens per request in place of full history.

Keeping cached documents current is a scheduling job: a Worker can re-extract changed files daily or weekly so the next cache rebuild uses current text. The token cost calculator estimates what each approach costs for your volumes, and the extraction results guide shows how to fetch output as Markdown.

FAQs

What is the difference between CAG and RAG?

CAG loads the whole knowledge base into the model’s context once and answers every question from it; RAG retrieves a few relevant passages per question. CAG avoids retrieval errors but only works when the knowledge fits in the context window.

Is CAG the same as prompt caching?

Prompt caching is the mechanism and CAG is the design that relies on it. Prompt caching stores the processed state of a repeated prefix; CAG puts the knowledge base in that prefix so no retrieval is needed. Prompt caching vs memory compares caching with a memory layer.

How large a knowledge base can CAG handle?

Whatever fits in the context window after leaving room for the question and answer, and in practice less, since recall degrades on very long inputs. Testing recall on your own documents at the planned size is the safest way to find the limit, and a needle in a haystack test is a quick start.

Is CAG cheaper than RAG?

Usually not per query. Even with caching discounts, each question carries the full corpus in context, while RAG sends only a few passages. CAG can be simpler to build and faster to answer, which may matter more for a small corpus.

Does CAG eliminate hallucinations?

It removes one cause, retrieval that misses the right passage. The model can still misread or overlook facts in a long context, so answers need the same checks as in RAG.

Can I use Exabase with cache-augmented generation?

Yes, for preparing and maintaining the documents. Extract produces Markdown for the cached prefix and Workers keep it current. When the corpus is too large to cache, Deep Search over a Base provides the retrieval side.

Related pages: RAG vs CAG, RAG vs long context, Prompt caching, KV cache, Context window, Naive RAG, RAG pipeline, Reduce token costs, Prompt caching won’t save you, Best RAG infrastructure.

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.