RAGCache: Efficient Knowledge Caching for Retrieval-Augmented Generation

Chao Jin, Zili Zhang, Xuanlin Jiang, Fangyue Liu, Shufan Liu, Xuanzhe Liu, Xin Jin

TL;DR

RAGCache is a specialized multilevel caching system designed to accelerate Retrieval-Augmented Generation (RAG) by caching the intermediate states (KV cache) of retrieved documents. By organizing these states in a "knowledge tree" and utilizing both GPU and host memory, it reduces the time to first token (TTFT) by up to 4× and doubles system throughput compared to state-of-the-art baselines.

What Problem Does This Paper Address?

Retrieval-Augmented Generation (RAG) has become the standard for reducing LLM hallucinations by "injecting" relevant documents into a prompt. However, this comes with a massive performance tax. When you add 1,000+ tokens of retrieved context to a 100-token query, the LLM's "prefill" phase—the initial computation of the prompt—becomes 10× more expensive in terms of compute and memory.

Existing LLM serving systems like vLLM or SGLang optimize for general prefix sharing (like system prompts or multi-turn chats), but they aren't built for the specific patterns of RAG. In RAG, documents are often reused across different queries, but their intermediate mathematical states (the Key-Value or KV cache) are huge and sensitive to the order in which they appear in the prompt. RAGCache aims to bridge this gap by treating retrieved knowledge as a first-class citizen in the caching hierarchy.

Methods

The authors introduce several novel components to optimize the RAG pipeline:

  1. The Knowledge Tree: Since KV tensors are order-dependent (the state of Document B changes if Document A precedes it), RAGCache organizes cached documents in a prefix tree. Each path from the root represents a specific sequence of documents, allowing the system to reuse computations for common document combinations.
  2. Multilevel Caching & PGDSF Policy: GPU memory is fast but tiny. RAGCache extends the cache into host (CPU) memory. To manage this, they use a Prefix-aware Greedy-Dual-Size-Frequency (PGDSF) replacement policy. This algorithm decides what to keep in GPU vs. CPU memory based on access frequency, document size, and the "cost" (time) it would take to recompute those tokens.
  3. Cache-Aware Request Scheduling: The system reorders incoming requests to prioritize those that hit the cache, maximizing the reuse of KV tensors already in GPU memory while maintaining a "window" to prevent request starvation.
  4. Dynamic Speculative Pipelining: Traditionally, retrieval and generation happen sequentially. RAGCache observes that vector databases often find the "correct" top documents early in the search process. It speculatively starts the LLM prefill using intermediate search results, overlapping CPU-bound retrieval with GPU-bound inference.

Datasets

The authors evaluated RAGCache using:

  • MMLU: A massive multi-task language understanding benchmark used here for multi-choice QA.
  • Natural Questions: A dataset of real-world Google search queries.
  • Knowledge Base: A Wikipedia corpus containing ~0.3 million documents.
  • Models: Evaluated on a range of sizes, including Mistral-7B, LLaMA2-7B, Mixtral-8×7B (MoE), and LLaMA2-70B.

Key Insights and Ideas

  • The "Hot" Document Phenomenon: The authors discovered that document retrieval follows a skewed distribution—a tiny fraction of documents (the top 3%) accounts for the majority (60%) of requests. This makes caching extremely high-leverage.
  • Host Memory is Underutilized: While GPU HBM is the gold standard, the PCIe bottleneck to host memory is still faster than recomputing thousands of tokens from scratch. RAGCache proves that a "spill-over" cache in RAM is a viable architectural choice for RAG.
  • Order Sensitivity is a Feature, Not a Bug: By using a tree structure instead of a flat cache, RAGCache respects the fact that LLMs are sensitive to document order, ensuring that "cached" results are mathematically identical to "recomputed" results.

Key Results

  • Latency Reduction: RAGCache reduces the Time to First Token (TTFT) by 1.2× to 4× compared to vLLM and by up to 3.5× compared to SGLang.
  • Throughput Gains: The system achieves 1.3× to 2.1× higher throughput than vLLM.
  • Efficiency: Even with the overhead of moving data between CPU and GPU, the "cache hit" latency is significantly lower than the "full prefill" latency (up to 3.9× lower).
  • Scalability: The benefits hold true even for massive models like LLaMA2-70B, where RAGCache maintained a TTFT below 1.4 seconds while baselines failed to meet basic Service Level Objectives (SLOs).

Limitations and Future Work

  • Static Knowledge Base: The current design assumes a relatively static knowledge base. Frequent updates or deletions in the vector database would require complex cache invalidation logic in the Knowledge Tree.
  • Order Rigidity: The tree structure is highly efficient for fixed sequences, but if users frequently request the same documents in different random orders, the cache hit rate would drop significantly.
  • Memory Pressure: While host memory is larger than GPU memory, it is not infinite. For billion-scale document sets, even a multilevel cache will face significant eviction pressure.

Overall, RAGCache represents a significant step toward making real-time, knowledge-heavy LLM applications economically and computationally feasible.

Summary updated

BibTeX
@article{jin2026ragcache,
  author = {Chao Jin and Zili Zhang and Xuanlin Jiang and Fangyue Liu and Shufan Liu and Xuanzhe Liu and Xin Jin},
  title = {{RAGCache: Efficient Knowledge Caching for Retrieval-Augmented Generation}},
  journal = {ACM Trans. Comput. Syst.},
  year = {2026},
  doi = {10.1145/3768628},
}
Figure