Say goodbye to RAG and embrace CAG: the road to innovation of knowledge tasks

Written by
Silas Grey
Updated on:June-20th-2025
Recommendation

Embrace CAG and open a new chapter in knowledge task processing. CAG, with its preloading and caching technology, brings revolutionary breakthroughs to long-context LLM.

Core content:
1. CAG core principle: fusion of preloading and caching
2. Three operation stages of CAG: external knowledge preloading, reasoning, cache reset
3. CAG vs. RAG: all-round advantages in efficiency, accuracy, and system architecture complexity

Yang Fangxian
Founder of 53A/Most Valuable Expert of Tencent Cloud (TVP)

With the rapid development of artificial intelligence technology, large language models (LLMs) have become the core force in the field of natural language processing. In order to enhance the ability of LLMs to handle knowledge-intensive tasks, retrieval-augmented generation (RAG) once became the mainstream solution. However, RAG has exposed many problems in practical applications, such as retrieval delays, document selection errors, and high system complexity. With the emergence of long-context LLMs, a new paradigm, cache-augmented generation (CAG), came into being, bringing disruptive changes to the processing of knowledge tasks.


The core principle of CAG: the clever combination of preloading and caching


CAG makes full use of the powerful information storage capacity of long-context LLM, and its core mechanism lies in the deep integration of preloading and caching technology. In actual operation, the operation of CAG is mainly divided into three stages, each of which contains unique technical logic.

External knowledge preloading


Before the CAG system is started, a collection of selected documents related to the target application needs to be preprocessed. This process includes operations such as text cleaning and format unification to convert the original documents into a form suitable for LLM processing. Subsequently, LLM encodes the document collection through a series of complex neural network calculations. In this process, LLM converts text information into an internally recognizable semantic vector representation and stores it in a key-value (KV) cache. This pre-computed KV cache is like a "knowledge warehouse" that encapsulates the LLM's reasoning state for the document collection. It is worth noting that no matter how many subsequent query requests there are, the computational cost of processing the document collection only needs to be borne once, which greatly reduces the overall computational overhead of the system.

reasoning


When a user enters a query, the system loads the precomputed KV cache into the LLM together with the user query. At this point, the attention mechanism inside the LLM establishes a connection between the preloaded knowledge context and the user query, and extracts knowledge information related to the query by quickly retrieving and matching the semantic vectors in the KV cache. Subsequently, the LLM gradually generates responses based on the extracted information and its own language generation capabilities. Since all relevant knowledge has been stored in the KV cache in advance, the entire reasoning process does not require real-time retrieval, avoiding retrieval delays and errors, and can generate answers quickly and accurately.

Cache reset


To ensure that the CAG system remains efficient across multiple inference sessions, the cache reset mechanism plays a key role. Since the KV cache grows in an append-only manner, the amount of data in the cache will continue to grow as the number of inferences increases. When the memory resources occupied by the cache reach a certain threshold, or when a new collection of documents needs to be processed, the cache needs to be reset. CAG's cache reset operation is very efficient. It achieves fast reinitialization by truncating newly added tokens without reloading the entire cache from disk, which greatly saves time and resources and ensures the system's continued fast response.

CAG vs. RAG: All-round advantages highlighted

CAG experiment comparison data:

Brief summary:

Comparison Dimensions

RAG

CAG

Efficiency (response time)

Processing tasks require real-time retrieval, which takes a long time. The response time is greatly extended in large data set scenarios.

Through preloading and caching mechanisms, the reasoning process is smooth and fast, and the response time is significantly shorter than RAG in various scale data processing.

accuracy

The quality of retrieval depends on the algorithm and document selection, which may lead to retrieval bias and inaccurate answers.

Preload all relevant knowledge at once to provide a complete and unified context for the model, so that the answers generated are more accurate and contextual.

System architecture complexity

Need to integrate multiple components, complex system structure, high development and maintenance costs

Simplify the architecture, reduce component interaction and coordination, and reduce development and maintenance difficulty and cost

Application prospects and outlook of CAG

Currently, various manufacturers are constantly breaking through the limitations of model context. OpenAI's latest GPT-4.1 supports millions of token context processing capabilities and can parse long content of more than 500,000 words at a time; Google Gemini Advanced was updated in March 2025, and the context window was expanded to 1 million tokens. Combined with Flash Thinking 2.0 technology, it can achieve significant improvement in reasoning efficiency in complex tasks.

Domestic manufacturers have also achieved remarkable results. Ali Tongyi Qianwen Qwen2.5-Turbo has reduced the processing time of 1 million tokens from 4.9 minutes to 68 seconds by virtue of the sparse attention mechanism; MiniMax-Text-01 launched on the National Supercomputing Internet Platform has achieved ultra-long context support for 4 million tokens.

These technological breakthroughs enable CAG to process larger knowledge sets. In the future, as the context window moves toward tens of millions of tokens, CAG is expected to be deeply applied in enterprise-level knowledge management, scientific research assistance, complex process automation, multimodal content generation and other fields. At the same time, with the continuous optimization of the model architecture (such as MoE hybrid experts, linear attention, etc.), CAG will further reduce computing costs, promote the deep integration and innovative application of artificial intelligence technology in more fields, and is expected to become the mainstream paradigm for knowledge task processing.