RefineKV: Query-Adaptive KV Cache Compression via Attention-Error Bounds

Kewei Lian, Jiayi Zhai, Anji LiuarXiv 2026

Imagine you’re trying to finish a massive 1,000-page novel. Every time you want to write a one-sentence summary of the current chapter, you are forced to re-read every single page you’ve already finished just to make sure you haven't missed a callback.

That is essentially what a Large Language Model (LLM) does during "long-context" decoding. It stores past information in a KV (Key-Value) cache, and as that cache grows to hundreds of thousands of tokens, the simple act of reading that "memory" becomes a massive bottleneck.

The authors of RefineKV have a better idea: what if you only re-read the specific paragraphs that matter for the current sentence, and just skim a one-sentence summary for the rest?

TL;DR

RefineKV is a query-adaptive method for compressing the KV cache that decides, on the fly, which parts of a model's memory need high-resolution attention and which can be safely summarized. By using a mathematically derived "risk score" to bound approximation errors, it achieves up to a 7.6x speedup in the attention phase and 1.66x faster decoding overall, all while maintaining near-perfect output quality.

What Problem Does This Paper Address?

In the world of LLMs, "context is king." But context is also expensive. During autoregressive decoding (generating text one token at a time), the model stores "Keys" and "Values" for every previous token in a KV cache. For a 128k-token context, this cache is enormous.

Most existing solutions try to shrink this cache by eviction (throwing away "unimportant" tokens forever) or merging (permanently squashing tokens together). The problem? As the authors show in Figure 1, while any single query only needs a small subset of the cache (~17%), different queries need different subsets. If you delete a token now because it seems useless, you might need it ten tokens later.

Figure 1: Left: Each query needs only a small KV subset, but together these subsets cover nearly the entire cache. For each query, we select the highest-weight KV entries needed to retain p% of its total attention weight. The figure compares sizes of these per-query subsets and their union across queries, alongside the resulting attention output error. At roughly 10% output error, each query needs only a small subset of the cache, yet their union covers most KV entries. Right: Query- adaptive methods surpass query-independent methods. Oracle query-adaptive top-k attention achieves a markedly better perplexity–access trade-off than representative eviction baselines. Our method recovers a substantial portion of this advantage without oracle access.

The challenge is Query-Adaptive Access: how do we decide which parts of the full cache to read for this specific query without reading the whole thing first?

Methods

RefineKV introduces a "coarse-to-fine" approach. Instead of looking at individual tokens, it partitions the KV cache into clusters (e.g., blocks of 32 tokens).

  1. Summarization: For each cluster, the model precomputes a compact representative (the mean Key and Value) and some metadata about how much the keys in that cluster vary.
  2. The Risk Score ($R_C$): This is the core innovation. For every new query, the model calculates a "risk score" for each cluster. This score is derived from a formal upper bound on the attention-output error. It balances two factors:
  3. Importance: How much does the query "care" about this cluster? (Approximate attention mass).
  4. Distortion: How "messy" is this cluster relative to the query? If the keys in a cluster are all over the place, a simple average won't represent them well.
  5. Selective Expansion: If a cluster’s risk score exceeds a threshold ($\tau$), the model "expands" it, reading the original, high-resolution KV entries. If the risk is low, it just uses the compact summary.
Figure 3: REFINEKV Pipeline. Prefill phase: The KV cache is partitioned into contiguous clusters, and a representative key-value pair together with auxiliary metadata is computed for each cluster. Decode phase: Each query qt uses the cached summaries to calculate risk score RC. Clusters with RC > τ are expanded, while clusters with RC ≤τ retain only their representatives. The resulting mixed KV sequence is used to compute the output ot. The color depth of each block indicates attention score.

Datasets

The authors evaluated RefineKV across two major models (Llama-3.1-8B and Qwen2.5-7B) using three rigorous long-context benchmarks:

  • LongBench: Tests real-world tasks like summarization and multi-doc QA.
  • RULER: A synthetic benchmark for complex retrieval and aggregation.
  • HELMET: A diverse set of application-oriented workloads.
  • WikiText-2: Used specifically for measuring perplexity (how "surprised" the model is by the text).

Key Insights and Ideas

  • The "Union" Insight: The paper quantifies a crucial gap—while a query only needs a tiny slice of memory, the union of what all queries need covers 96% of the cache. This effectively kills the argument for aggressive, permanent eviction in long-context tasks.
  • Importance vs. Distortion: The risk score isn't just about attention weights. A cluster might have high attention weight but low distortion (meaning all its keys are very similar), allowing it to be compressed safely. Conversely, a cluster with moderate weight but high distortion must be expanded.
Figure 2: The trade-off between Importance and Distortion. High-importance clusters require lower distortion to remain compressed.
  • Mathematical Rigor: Unlike many heuristic-based methods, RefineKV’s selection criterion is grounded in an error bound. The authors show that their risk score correlates strongly ($Spearman \approx 0.95$) with the actual approximation error.

Key Results

  • Efficiency: RefineKV achieves a 7.6x speedup in the attention phase and a 1.66x overall decoding speedup (TPOT) compared to full attention.
  • Quality: At a conservative threshold ($\tau=0.01$), RefineKV virtually matches the accuracy of full attention across all benchmarks.
  • Pareto Frontier: It consistently outperforms popular baselines like SnapKV and StreamingLLM, offering a better trade-off between how much of the cache is accessed and the resulting model accuracy.

Limitations and Future Work

  • Layer-wise Error: The current error bound applies to a single attention head. It doesn't yet account for how small errors might accumulate or amplify as they pass through 32+ layers of a Transformer.
  • Static Clustering: The method currently uses contiguous blocks of tokens. The authors suggest that hierarchical clustering or 2D-spatial clustering (for vision models) could yield even tighter summaries.
  • Modality Agnostic: While tested on text, the logic is modality-agnostic. Future work could apply this to high-resolution video or image processing where KV caches are even more punishing.

Summary updated

Abstract

Repeatedly accessing the full key--value (KV) cache is a major bottleneck in long-context language model decoding. We find that small query-specific subsets can accurately approximate full attention, yet their union covers nearly the entire cache, motivating query-adaptive access for the KV cache. A natural approach is to split the KV cache into clusters, using compact representatives for clusters that incur negligible error while expanding the rest to their original KV entries. We derive a selection criterion from an upper bound on attention-output error, which reveals two complementary factors governing the error: importance measures the impact of a cluster, while distortion measures how faithfully the cluster can be represented. Based on this criterion, we propose RefineKV, a decoding-time query-adaptive KV compression method. Experiments on two models and three benchmarks demonstrate that RefineKV retains near-full-attention quality while achieving up to 7.6x speedup in the attention phase and 1.66x faster decoding, establishing a new quality-latency Pareto frontier.
BibTeX
@misc{lian2026refinekv,
  author = {Kewei Lian and Jiayi Zhai and Anji Liu},
  title = {{RefineKV: Query-Adaptive KV Cache Compression via Attention-Error Bounds}},
  year = {2026},
  eprint = {2611.28171},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.28171},
}
Figure