The memory footprint of the key-value (KV) cache constrains the practical use of long-context models, and it dominates cost when one prefilled context must later serve many different queries. In this reusable setting, query-agnostic compression trades cost against quality: lightweight estimators are cheap but less accurate, whereas full-context reconstruction scoring is more accurate yet reprocesses the entire prompt. We introduce KV2, a query-agnostic KV-cache compression method based on selective reconstruction. KV2 first uses a lightweight proxy scorer to identify informative in-context tokens, then reprocesses only this subset to compute final eviction scores. On RULER, Needle-in-a-Haystack, and LongBench, KV2's margin over baselines widens as the budget tightens: on RULER 16K at a 2% KV-cache budget it improves the average score over the next-best baseline by more than 40 percentage points, and on LongBench it attains the highest average across 2%-10% budgets at lower compression-stage runtime and peak memory than full-context reconstruction. Reusable KV-cache compression thus does not require reprocessing the full context. Our code is available at https://anonymous.4open.science/r/KVsquared-0B97.
Figures & tables
Figure 1: Overview of KV². After prefilling the context cache KVc , the method computes proxy scores as a lightweight estimate of which in-context tokens are most informative. KV² then selects the query tokens KVc,selectedquerytokens , runs Selective Reconstruction (SR) on these selected queries to obtain cache scores, and then evicts low-scoring KV entries before later decoding reuses the compressed cache.
Figure 2: Chunked processing in KV 2 . The context is split into chunks. Each chunk proposes its own reconstruction queries, and the resulting local scores are merged into one global eviction decision.
Figure 3: Detailed view of KV² inside one chunk. Proxy scores first select the ordered reconstruction set Qr . These reconstruction queries are then encoded against the shared cache, and the final score for a cached position is the maximum attention it receives during selective reconstruction.
Method
Single-doc QA
Multi-doc QA
Summ.
Few-shot / Cls.
Synth. Count
Code
Avg.
NrtvQA
Qasper
MFQA-en
Hotpot
2Wiki
MuSiQ
GovRep
QMSum
MultiN
TREC
TrivQA
SAMSum
PCount
PR-en
LCC
RB-P
Llama-3.1-8B-Instruct
Full
30.21
45.53
55.01
56.01
46.65
31.28
35.13
25.28
27.25
73.00
91.64
43.80
8.91
99.50
63.38
56.64
49.33
KV Size = 2%
KeyDiff
17.24
12.11
16.71
26.07
20.44
5.06
21.65
18.36
10.99
17.00
91.34
36.60
6.00
25.50
12.66
48.75
24.16
KVzip
12.54
11.10
18.98
24.80
21.78
8.69
11.39
17.40
7.36
5.00
87.47
32.31
2.50
4.00
18.20
51.75
20.95
Table 1: LongBench results across KV-cache budgets for Llama-3.1-8B-Instruct and Qwen3-8B . For both, KV² gives the strongest average performance at tighter budgets, with KVzip becoming closer at 10% retention.
Figure 4: RULER 16K score versus compression ratio for Qwen3-8B . The largest gap appears in the severe-budget regime (compression ratio > 90%), where KV 2 remains much more robust than the compared baselines.
Figure 5: Needle-in-a-Haystack results at a 5% KV-cache budget on Llama-3.1-8B-Instruct across context lengths and needle depths.
Figure 6: Compression-stage runtime (left) and peak memory (right) versus chunk size for single-pass KV 2 compared with KVzip. For KV 2 , the value in parentheses in the legend denotes the reconstruction percentage retained from the proxy-selected query set in the first stage. Missing bars indicate out-of-memory configurations.
Figure 7: RULER 4K score versus compression ratio for Llama-3.1-8B-Instruct when KV 2 is paired with different first-stage proxy scorers.
Figure 8: RULER 4K score versus reconstruction percentage for Llama-3.1-8B-Instruct (left) and Qwen3-8B (right). In the legend, KV Size denotes the final retained KV-cache budget.
Figure 9: RULER 4K score with refinement iterations. Most gains appear in the first few passes, after which improvements diminish. The legend lists the first-stage proxy scorer and the retained reconstruction percentage.
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 10: Compression-stage runtime (left) and peak memory (right) versus chunk size for iterative KV 2 . Additional refinement passes increase runtime roughly in proportion to the number of passes, while peak memory is driven mainly by chunk size and changes much less with the number of iterations. All curves use a fixed 2% reconstruction percentage; the number in parentheses in the legend denotes the number of refinement iterations.
Figure 11: RULER 4K score versus KV retention ratio for Llama-3.1-8B-Instruct (left) and Qwen3-8B (right). KV 2 is more robust than lightweight heuristics at small budgets, while KVzip becomes more competitive as more KV entries are kept.
The key-value (KV) cache is the primary memory bottleneck in long-context LLM inference. Existing approaches attack it from opposite ends: eviction methods permanently discard tokens, degrading performance whenever a discarded token later proves essential, while quantization methods retain all tokens at low precision but offer limited compression. We propose AnchorKV, a compression scheme that shrinks the cache by 20× without discarding a single token. AnchorKV represents the cache using a small set of anchors stored exactly, expresses every other token through its most similar anchor, and refines only those whose approximation most affects the model's output. AnchorKV consistently preserves accuracy across models and datasets, retaining 99% of the full-cache score at the 70B scale, while keeping the entire context at a fraction of its cost.
Malik Khalaf, Yara Shamshoum, Nitzan Hodos +2
Department of Computer Science, Technion - Israel Institute of Technology
Long-context language models are limited by the memory footprint of the key-value (KV) cache. Existing training-free KV compression methods usually rank tokens by one importance signal -- attention, recency, layer-wise allocation, or key distinctiveness -- which becomes brittle when useful context is globally distinctive, locally episodic, or immediately relevant. We introduce NestedKV, a key-only KV cache compression method inspired by the Continuum Memory System in Nested Learning. NestedKV maintains global, block-level, and sliding-window key anchors, scores tokens by multi-time-scale cosine anomaly, and combines the resulting rankings with a training-free outer learner using head-adaptive mixing and surprise-gated token routing. The score is paired with adaptive per-head budgets and requires no training or LLM modification. Across RULER (4k--32k), LooGLE, LongBench, LongBench-E, InfiniteBench, and MMLU-Pro on Qwen3 and Llama-3.2 models, NestedKV is strongest when the retained cache is small. On Qwen3-4B, it improves over KeyDiff by up to 19.10 points on RULER and 19.29 on LongBench at r=0.75; at r=0.95, it retains 37.32 on LongBench versus 17.55 for KeyDiff.
Hong Chen, Xiang Liu, Yubo Gao +5
The Hong Kong University of Science and Technology (Guangzhou) · Jimei University
Long-context large language model (LLM) inference is increasingly constrained by the memory footprint and decoding cost of key-value (KV) caches, limiting sustainable deployment on resource-constrained hardware. Existing KV cache eviction methods typically apply heuristic token scoring over all heads in GQA-based LLMs. These methods ignore the different functionalities of attention heads, leading to the eviction of critical tokens and thus degrading the performance of LLMs. To address this issue, we propose CompressKV, a resource-efficient KV-cache compression framework for GQA-based LLMs. Instead of aggregating attention scores from all heads, CompressKV identifies Semantic Retrieval Heads (SRHs) that capture both the initial and final tokens of a prompt and semantically important mid-context evidence, and uses them to select tokens whose KV pairs should be retained. Furthermore, CompressKV allocates cache budgets across layers according to offline estimates of layer-wise eviction error. Experiments on LongBench and Needle-in-a-Haystack show that CompressKV consistently outperforms existing KV-cache eviction methods across memory budgets. Notably, it preserves over 97% of full-cache performance using only 3% of the KV cache on LongBench question-answering tasks and achieves 90% accuracy with just 0.7% KV storage on Needle-in-a-Haystack. These results demonstrate an improved resource--performance trade-off for long-context LLM inference. Our code is publicly available at: https://github.com/TUDa-HWAI/CompressKV
Xiaolin Lin, Jingcun Wang, Olga Kondrateva +3
Technical University of Darmstadt, Darmstadt, Germany · University of Notre Dame, Notre Dame, IN, USA · Technical University of Ilmenau, Ilmenau, Germany