Cache-augmented generation (CAG) is a technique in which the entire relevant knowledge collection is loaded into a language model’s context window in advance, its key-value (KV) cache is precomputed and stored, and every later query is answered on top of that cached state without a retrieval step. In the field of Retrieval & knowledge, CAG is positioned as a simpler alternative to retrieval-augmented generation (RAG) for knowledge sets small enough to fit in a long context.
The approach became practical once models offered context windows of 128,000 tokens or more and inference servers supported prefix caching. Its central promise is to remove retrieval errors and retrieval latency at the cost of a fixed context budget and higher memory use per session.
How cache-augmented generation works
CAG runs in three phases. First, the documents are cleaned, concatenated and placed into a fixed prompt prefix, usually after the system instructions. Second, the model processes that prefix once in a prefill pass, producing the attention keys and values for every token, which together form the KV cache. Third, for each user query the server loads the stored cache, appends only the new question tokens and generates an answer.
Because the transformer has already computed attention states for the knowledge prefix, the expensive prefill work is paid once and amortized over many queries. After each answer, the cache is truncated back to the knowledge prefix, so earlier questions do not accumulate in the context.
| Phase | What happens | When it runs |
|---|---|---|
| Knowledge preloading | Documents assembled into a fixed prefix | Once per knowledge update |
| Cache precomputation | Prefill pass stores keys and values | Once per model and prefix |
| Cached inference | Query appended to the stored cache | Every request |
| Cache reset | Context truncated to the prefix | After each answer or session |
Cache-augmented generation compared with RAG
The essential difference is where selection happens. RAG uses a retriever, embeddings or BM25, to choose a few relevant chunks per query, so the model sees only a fragment of the corpus. CAG lets the model see the whole corpus every time and relies on the attention mechanism to find relevant passages. This removes failure modes such as poor chunking, a weak embedding model or a missed document.
The table compares the two architectures on dimensions that usually drive the design decision.
| Dimension | Cache-augmented generation | Retrieval-augmented generation |
|---|---|---|
| Knowledge size | Bounded by the context window | Practically unbounded |
| Per-query latency | Low; no retrieval or full prefill | Retrieval plus prefill of chunks |
| Retrieval errors | None; whole corpus is visible | Missed or irrelevant chunks possible |
| Infrastructure | Model server with cache storage | Vector index, retriever, pipelines |
| Knowledge updates | Recompute the whole cache | Re-index only changed documents |
| Memory per session | High; full KV cache in GPU memory | Moderate; short contexts |
Neither approach is universally better. CAG suits small, stable, frequently queried knowledge; RAG suits large, growing or permission-filtered collections. Hybrid systems cache a core set of documents and retrieve the long tail on demand.
CAG should also be distinguished from semantic caching, which stores previous answers and returns them when a new query is similar, and from fine-tuning, which writes knowledge into model weights. CAG changes neither the weights nor the answers: it caches only the internal attention state of the source text, so every response is still generated fresh from the full material. This makes CAG easy to update compared with fine-tuning, and more faithful than answer caching when questions vary in wording or detail.
When teams decide between the approaches, the practical test is simple. If the complete corpus fits comfortably in context, changes rarely and is shared by all users, CAG usually reduces moving parts. If any of those conditions fails, a retrieval layer remains the more robust and economical choice.
Sizing and configuring a CAG deployment
The first design question is whether the knowledge fits. A useful rule is to keep the cached prefix well below the model’s maximum context, leaving room for the query, instructions and answer, and to verify that answer quality does not drop at that length. KV cache memory grows linearly with prefix length, and for large models a cache of 100,000 tokens can occupy tens of gigabytes, depending on layer count, attention heads, precision and whether grouped-query attention is used.
| Parameter | Typical range or choice | What it affects |
|---|---|---|
| Cached prefix length | 10,000 to 200,000 tokens | Coverage versus memory and accuracy |
| Cache precision | 16-bit, or 8-bit quantized | Memory use versus small accuracy loss |
| Cache storage | GPU memory, CPU memory or disk | Reload latency and concurrency |
| Refresh frequency | Per release, daily or on change | Freshness versus recompute cost |
| Document ordering | Most important material first or last | Attention to critical passages |
Many hosted model APIs expose the same mechanism as prompt caching, which bills cached prefix tokens at a reduced rate and returns faster first tokens. Self-hosted stacks implement it through prefix caching in the inference server.
Limitations, risks and common mistakes
Long-context models do not attend equally well to every position. The lost-in-the-middle effect means facts buried in the middle of a very long prefix may be overlooked or confused, so a working CAG system must be evaluated on questions targeting every region of the corpus.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Answers ignore relevant documents | Lost-in-the-middle attention | Reorder or shorten the prefix |
| Outdated answers | Stale cache after content change | Automate cache recomputation |
| High serving cost | Large caches per concurrent session | Share one cache, quantize it |
| Data leakage between users | One cache mixing restricted content | Separate caches per permission level |
- Access control is coarse: everything in the cache is visible to every query that uses it.
- Any change requires recomputation: editing one paragraph invalidates the cache from that position onward.
- Citations are harder: without retrieved chunks, source attribution depends on prompt instructions.
The short version
Cache-augmented generation means giving an AI model all the reading material before anyone asks a question. The model reads it once and keeps its notes. Each new question is answered from those notes. Nothing needs to be searched again.
Compare it to a student who memorizes a short handbook before an exam. That student answers quickly and never picks the wrong page. It only works when the handbook is short enough to remember. If the handbook changes, the student has to study it again.
Where it makes a difference
A software company runs an internal help assistant for its support staff. The relevant material is a product manual of about 60,000 tokens, updated once per release. The first version used RAG, but agents complained that answers sometimes missed steps spread across several chapters, because the retriever returned only five chunks.
The team switches to cache-augmented generation. At each release, a job precomputes the KV cache for the full manual and stores it on the inference server. Questions now reuse that cache, so the time to first token drops noticeably, and multi-chapter procedures are answered completely. Evaluation on 200 historical support questions shows fewer incomplete answers. The trade-off is accepted knowingly: the cache is recomputed on every manual update, and confidential customer records stay in a separate RAG pipeline with per-user access checks.