Cache-Craft: Managing Chunk-Caches for Efficient Retrieval-Augmented Generation

Shubham Agarwal, Sai Sundaresan, Subrata Mitra, Debabrata Mahapatra, Archit Gupta, Rounak Sharma, Nirmal Joshua Kapu, Tong Yu, Shiv Kumar Saini

TL;DR

Cache-Craft is a novel system designed to slash the computational overhead of Retrieval-Augmented Generation (RAG) by reusing precomputed Key-Value (KV) caches for individual text chunks. Unlike traditional prefix caching, which breaks if a single word in the prompt changes, Cache-Craft allows for the reuse of "chunk-caches" regardless of their position or surrounding context, achieving up to a 2x reduction in latency and a 1.6x boost in throughput while maintaining high output quality.

What Problem Does This Paper Address?

In RAG systems, Large Language Models (LLMs) generate answers by looking at "chunks" of text retrieved from a massive knowledge base. While we often think of the "decode" phase (generating words one by one) as the slow part, the authors show that for RAG, the prefill phase is the true bottleneck. Prefill time grows quadratically with the length of the input context, and in production systems, it can account for over 77% of total inference time.

Existing solutions like "prefix caching" only work if the entire beginning of a prompt is identical across requests. In RAG, however, the same text chunks are frequently retrieved, but they appear in different orders or are paired with different user queries. This "contextual shift" makes standard caching useless. If you naively reuse a cache from a different context, the LLM’s attention mechanism gets confused, leading to a massive drop in answer quality.

Methods

Cache-Craft introduces several clever engineering and algorithmic "fixes" to make chunk-level reuse possible:

  1. Chunk-Cache Management: It treats the KV-cache as a library of independent, modular units. To make them position-independent, the system mathematically "unwraps" the Rotary Position Embeddings (RPE) before storing them and reapplies the correct positional logic during runtime.
  2. Reusability Metrics: Not all chunks are equally easy to reuse. The authors define Inter-attention (how much a chunk is influenced by what came before it) and Intra-attention (how much it focuses on itself). They use these to calculate a Cache Context Impact (CCI) score to decide if a cache is "stale" or reusable.
  3. Selective Recomputation: Instead of recomputing an entire chunk, Cache-Craft identifies the small subset of tokens (the "top-N") most affected by the new context and recomputes only those. This "fixes" the cache at a fraction of the cost.
  4. Adaptive Early Termination: The system monitors attention layers in real-time. If it notices the LLM is no longer "focusing" on certain chunks in later layers, it stops recomputing them early to save even more cycles.
  5. Hierarchical Storage: To handle massive knowledge bases, it uses a tiered storage approach—keeping hot caches in GPU memory, warm ones in CPU RAM, and cold ones on NVMe SSDs—using layer-wise preloading to hide the time it takes to move data.

Datasets

The authors evaluated Cache-Craft using a mix of real-world and synthetic data:

  • Production Workloads: Two proprietary RAG systems (Sys-X and Sys-Y) used for enterprise SaaS workflows and Q&A.
  • Multi-hop Q&A: 2WikiMQA and MuSiQue, which require reasoning across multiple documents.
  • Single-hop Q&A: SQuAD and DROP.
  • Summarization: CNN/DailyMail and XSUM.

Key Insights and Ideas

  • Prefill is the Enemy: Contrary to the common focus on "tokens per second" during generation, RAG performance is actually dominated by the initial processing of retrieved documents.
  • Contextual "Stickiness" is Sparse: Most tokens within a retrieved chunk are primarily influenced by their immediate neighbors. Only a few tokens at the boundaries or key semantic markers are heavily influenced by the preceding "prefix." By fixing just these "distorted" tokens, you can recover almost all the original model quality.
  • The Power Law of Retrieval: In production, a tiny fraction of chunks (the top 5%) are accessed by 40-60% of all queries. This makes even a modest-sized cache extremely effective.

Key Results

  • Efficiency: Cache-Craft reduced redundant computations by 51% compared to state-of-the-art prefix caching and 75% compared to full recomputation.
  • Speed: On the LLaMA-3-70B model, it delivered a 2x reduction in end-to-end latency and a 1.6x speedup in throughput.
  • Quality: By recomputing only ~30% of tokens, the system maintained 90% of the base ROUGE F1 score, making the output nearly indistinguishable from a full, expensive recomputation.
  • Hardware: The system successfully masked SSD loading latencies, meaning even a massive cache stored on disk didn't slow down the "Time-to-First-Token" (TTFT).

Limitations and Future Work

  • Hyperparameter Tuning: The system relies on a scaling factor ($\alpha$) to balance speed vs. quality. Finding the "sweet spot" currently requires a validation dataset, which might vary between different LLM architectures.
  • Storage Overhead: While the authors show that 150GB of cache fits on modern GPU clusters, extremely large-scale deployments with millions of frequently accessed chunks might still face storage pressure.
  • Cross-Attention: The current work focuses on causal decoder models (like LLaMA). Extending this to encoder-decoder models or models with different attention variants (like sliding window attention) remains a future direction.

Summary updated

BibTeX
@inproceedings{agarwal2025cache,
  author = {Shubham Agarwal and Sai Sundaresan and Subrata Mitra and Debabrata Mahapatra and Archit Gupta and Rounak Sharma and Nirmal Joshua Kapu and Tong Yu and Shiv Kumar Saini},
  title = {{Cache-Craft: Managing Chunk-Caches for Efficient Retrieval-Augmented Generation}},
  booktitle = {Proc. ACM Manag. Data},
  year = {2025},
  url = {https://openreview.net/forum?id=jg6F2ndP5T},
}
Figure