Reuse non-prefix KV Cache and speed up RAG by 3X with LMCache.

Posted by Nice-Comfortable-650@reddit | LocalLLaMA | View on Reddit | 22 comments

Reuse non-prefix KV Cache and speed up RAG by 3X with LMCache.

Hey r/LocalLLaMA !

A while back, we shared our open-source project LMCache here and were blown away by the incredible support and feedback. Today, our team is thrilled to share more about one of our core components: CacheBlend. Recognized with a Best Paper Award at ACM EuroSys 2025, this technique is a pain killer for efficient RAG applications 

The Problem: Your KV Cache is Wasting Potential

In modern LLM applications like RAG and Agents, we constantly feed the model new context. For example, in RAG, we retrieve relevant documents and stuff them into the prompt.

The issue is that this dynamically retrieved context doesn't always appear at the beginning of the input sequence. Traditional KV caching only reuses a "common prefix," so if the new information isn't at the very start, the cache hit rate plummets, and your GPU ends up recomputing the same things over and over.

The Solution: CacheBlend - 100% Hit Rate, No Compromises

CacheBlend changes the game by allowing for the reuse of pre-computed KV caches regardless of their position in the input sequence.

This means we can finally achieve a 100% KV Cache hit rate in applications like RAG. The performance gains are significant:

How does it work?

CacheBlend intelligently handles the two main challenges of reusing non-prefix caches:

  1. Positional Encoding Update: It efficiently updates positional encodings to ensure the model always knows the correct position of each token, even when we're stitching together cached and new data.
  2. Selective Attention Recalculation: Instead of recomputing everything, it strategically recalculates only the minimal cross-attention needed between the new and cached chunks to maintain perfect generation quality.

For detailed analysis, please refer to the official paper: https://dl.acm.org/doi/10.1145/3689031.3696098

Where can I try it?

Try the newest interactive CacheBlend demo at: https://github.com/LMCache/LMCache-Examples/tree/main/demo-rag-blending

Ask us anything!