Start with retrieval-augmented generation (RAG) if your assistant answers from a large collection, documents change often, or users have different access to them. Try cache-augmented generation (CAG) for a small, stable set of documents that the same audience can read and that leaves room for questions and answers in the model’s context.

With RAG, the application searches for passages when a question arrives and sends the passages to the model. With CAG as proposed by Brian J. Chan and colleagues in 2025, the model processes a chosen set of documents in advance and reuses its key-value (KV) attention states to answer new questions. Lewis et al.’s RAG paper and Chan et al.’s CAG method.

One meeting room, two paths to an answer

A help desk gets this question about the fictional Cedar meeting room.

The Cedar projector says “No Signal” after I plug in my laptop. What should I check first?

Both assistants start from the same two fictional documents. The Cedar quick-start card says the table cable goes to HDMI 1. Section 3 of the shared projector manual says to select the matching input and reseat the cable if the screen still shows “No Signal.”

In the RAG path, the application splits those documents into passages and indexes them ahead of time. When someone asks the question, the search should find the Cedar card’s HDMI 1 instruction and the manual’s troubleshooting passage. The application gives the model those excerpts and the question. If search finds the manual and misses the room card, the model lacks evidence about which input to select. For an example of choosing an embedding model for Korean manuals, see the Kanana embeddings guide.

In the CAG path, the application puts both documents at the start of the model’s input. The model processes that document prefix ahead of time, a step called prefill, and saves the resulting KV states. When the question arrives, the model uses those states to generate an answer without running a document search. For each independent request, start from the saved document prefix. Reset the cache to that prefix after generation to keep one request’s tokens out of the next. Authors’ reference implementation.

Either path could give this answer. Keep document names and section labels in the supplied context so the model can point the user to the instructions.

Select HDMI 1 (Cedar quick-start card). If the message stays on screen, reseat the table cable (projector manual, section 3).

RAG indexes document passages, then searches the index for excerpts when a question arrives. CAG prefills selected documents into a KV cache, then passes the question and cached states to the model. Changes trigger an index refresh or cache rebuild.
Two paths for the Cedar projector question. RAG finds relevant passages when asked. CAG reuses model states prepared from the room card and manual. Open the full-size diagram.

What happens when the source changes?

Suppose a technician moves the Cedar cable to HDMI 2 and revises the card. With RAG, refresh the affected passages in the index and remove the old ones. Search can still return the HDMI 1 instruction while the index is behind the source. Record the source version and check that a request after the update retrieves the new card. An example of how index updates work in Azure AI Search.

With CAG, retire the old cached prefix and prefill the revised documents before serving from the new cache. Tie the cached states to the document version and the model that produced them. If you keep a different bundle for each branch, budget memory for the versions you need to serve. The cached documents still occupy part of the model’s context window, so reserve room for instructions, the question, and generated text. Test whether the model can reliably find the needed detail in the bundle, even when the whole bundle fits. Transformers KV cache guide and Liu et al. on long-context retrieval.

After updating the index or cache, ask the projector question again. Verify that the answer cites the current Cedar card before acting on it. How to check whether a source applies.

If you are trying to fit a crowded prompt into a smaller token budget, see our Headroom guide to context compression.

Choose based on update frequency and access

Shared setup guides that rarely change
Try CAG when the approved documents fit with room to spare and your inference runtime can reuse the prefill. A help desk can share one document prefix across questions from users with the same access.
Branch incident logs that change throughout the day
Start with RAG. Filter by branch and let search pick the relevant log entries. Set an indexing schedule or update trigger based on how soon technicians need new reports to appear.
Staff and technicians have different document access
Have the application check the caller’s identity and permissions before it gives any context to the model. With RAG, filter the search to authorized documents. With CAG, build a cache for each group with the same access or cache only documents shared by all callers. Recheck access before attaching any cached states. Retire affected cache versions when document access changes. An example of document filtering in Azure AI Search.

Document KV caches, response caches, and prompt caching

A response cache saves a finished answer for a matching request. CAG saves the model’s attention states for a document prefix and generates a fresh answer for each question, such as a follow-up about the Cedar room’s input. Conversation history and saved preferences are a separate design choice covered in our AI agent memory guide.

Provider prompt caching reuses work for a matching prompt prefix. You can use it in a CAG-style assistant by making a fixed set of documents the shared prefix. You can also cache common instructions in a RAG assistant while searching for different passages on each request. The application still decides which documents the model sees. Check how the provider handles matching prefixes and expiration. Claude prompt caching documentation.

Compare the first request and later requests separately

Use the same model, document versions, and questions for both paths. Measure index preparation and document prefill separately when they happen ahead of serving. Time the first request with your intended startup policy and measure again with the document cache ready to reuse. Count any loading or cache building that happens on the request. Record time to first token, end-to-end time, and the cost or memory use on your setup.

For answer quality, keep the expected source passage for each question. Ask the Cedar question before and after the card changes to HDMI 2. Include a question the manuals cannot answer and a request from a staff member for a technician-only log entry. Check whether the answer cites the current card and says when the available documents lack the information. Verify that the application keeps restricted text out of the model’s context.

Sources checked November 12, 2026. The room, documents, and answer are fictional. The comparison draws on published research and documentation.

← Back to Comparisons
Tech Guides
Turn a PDF Into Editable Markdown With Docling ↗