What is Cache-Augmented Generation (CAG), and how is it different from RAG?
RAG (Retrieval-Augmented Generation) searches a vector database for matching document chunks each time a question arrives and pastes them into the prompt. CAG (Cache-Augmented Generation) loads a company's approved knowledge into the model's context ahead of time and keeps it in the GPU's key-value (KV) cache, so every question reuses that cached context without a separate search step.
Key facts
- RAG lookup
- Embed the question → vector search → rerank → insert top chunks → generate
- CAG lookup
- Knowledge compiled in advance → reused from GPU KV prefix cache → generate
- RAG is better for
- Very large or fast-changing collections (millions of documents)
- CAG is better for
- Bounded knowledge such as handbooks, policies, product catalogues and FAQs
- Main CAG limit
- Knowledge must fit the model's context budget, so it is compiled and selected first
- Who uses CAG
- Koya AI uses an agentic form of CAG for every tenant
How RAG works
Documents are split into chunks and turned into embedding vectors stored in a vector database. At question time the question is embedded too, the nearest chunks are retrieved (often reranked), and they are added to the prompt. The answer quality depends on the search step finding the right chunk. Chunks that are split badly, or a question worded differently from the document, can cause misses.
How CAG works
Instead of searching at question time, the approved knowledge is compiled into blocks in advance and placed at the start of the model's context. Inference servers such as vLLM keep the computed attention state for that shared prefix in GPU memory (the KV prefix cache), so later questions reuse it rather than reprocessing the documents. There is no embedding model and no vector database in the path.
Keeping the cache correct
The risk with any cache is serving stale content. In Koya, editing or deleting a document bumps a version number (an "epoch") in Redis; every server sees the new epoch and rebuilds that tenant's cached context, so removed content stops being used straight away.
Which should you choose?
Choose RAG if you need to search a huge, constantly growing archive. Choose CAG if your assistant answers from a defined body of approved material and you care most about consistent answers and fewer moving parts. Some systems combine the two: CAG for the core handbook, retrieval for the long tail.
Frequently asked questions
Is CAG faster than RAG?
Usually, for bounded knowledge: CAG skips the embedding and vector-search steps and reuses cached context. The gain shrinks if the knowledge is too large to keep cached.
Does CAG remove hallucinations?
No method removes them completely. CAG reduces one cause, a retrieval step that misses the right passage, and Koya's prompts instruct the model to say when the documents do not cover a question.
What does 'agentic' CAG mean?
The assistant can also decide to call tools, such as an order-lookup or leave-request API, instead of only answering from the cached documents.