Read only the parts of an AI's memory that matter for this word
Every time a language model writes a word, it looks back over its whole memory of the conversation (the KV cache). With long documents that re-reading is the slow part. RefineKV splits the memory into blocks and keeps a one-line summary of each. For every new word it asks, block by block, "would the summary change the answer?" It opens the full block only when the answer could be yes. Below, the paper's error bound runs live on a simulated attention head: change the threshold and watch which blocks get opened, how much is read, and how far the answer drifts.
Why it matters
Long-context chatbots, coding agents and reasoning models spend most of their time re-reading a huge memory for every word they write, which makes them slow and expensive to run. By opening only the blocks a provable error bound says are risky, RefineKV made the attention step up to 7.6× faster and decoding up to 1.66× faster on Llama-3.1 and Qwen-2.5, while matching full-attention quality at its cautious setting.
The paper
RefineKV: Query-Adaptive KV Cache Compression via Attention-Error Bounds
Kewei Lian, Jiayi Zhai and Anji Liu (National University of Singapore). arXiv:2611.28171 [cs.LG], submitted 20 November 2026. Read on arXiv · PDF · Project page
In plain language: attention mixes stored value vectors vi. Each is weighted by how well the current query q matches that token's stored key ki:
The authors first measured how much of the cache each query really needs. On their data, keeping 90% of a query's attention weight needed only 17.6% of the cache. But the needed pieces were different for every query, and together they covered 96.4% of it. So throwing parts of the cache away for good (eviction) is bound to hurt some later word. The choice of what to read has to be made fresh for every query.
RefineKV cuts the cache into contiguous blocks C and stores each block's mean key k̄C and mean value v̄C. A summarised block acts like |C| copies of its mean, so it gets weight p̂C ∝ |C| exp(q·k̄C/√d). The output error splits into attention moving between blocks plus value blur inside them. Both are controlled by the block's distortion δC = maxi∈C |q·(ki − k̄C)|/√d, which says how differently the block's tokens respond to this query. The paper proves (Eq. 4):
Here VC is the largest value norm in the block and Vmax the largest overall. Blocks with RC > τ are opened and read token by token. The rest are read as their single summary. The risk mixes importance (p̂C) with distortion (δC). An important block must be very uniform to stay summarised, while an unimportant one can be messy. Computing δC exactly would mean reading the block, so the paper uses cheap upper bounds from stored per-block extremes. One is the axis-aligned box bound (Eq. 83), from each block's coordinate-wise min and max keys. The other is a diagonal-ellipsoid bound (Eq. 87).
Try it: one attention head over a 1,024-token document
The "document" is a string of topics, each 20–120 tokens long. A token's key is its topic's direction plus some scatter (head size d = 32). Each decoding step's query drifts from one topic to the next, the way a model's focus moves while it writes. Everything below is recomputed live: exact attention, the paper's risk score RC for every block, the mixed exact-plus-summary attention, and its error.
How to use it
- Start at the defaults: τ = 0.01 (the paper's cautious setting), 32-token blocks and the box bound. Only a few orange blocks are opened, mostly where attention is high and the block straddles a topic change. The error stays well under a percent, while only a small share of the cache is read (12% at step 0, about a third on average over the run).
- Press ▶ Play. The query's focus wanders and different blocks open at each step, while the purple "opened at least once" band keeps growing. This is the paper's motivating finding: small per-query sets, a large union. That is why a fixed eviction rule fails and per-query selection works.
- Look at the importance–distortion plot. The threshold line is tilted: important blocks (high p̂C) must have tiny distortion to stay summarised, while unimportant ones can be messy.
- In the trade-off plot, compare orange (RefineKV) with blue (open blocks by importance only). At the same reading budget, accounting for distortion usually gives lower error. In this simulation it won on 30 of 32 sampled steps. Grey is an idealised oracle that knows the exact top tokens without reading anything. RefineKV gets close to it without that knowledge.
- Switch to Exact (oracle) δC. On average slightly fewer blocks open (in this simulation about 10 of 32 per step instead of 10.5), because the box bound is loose: its coordinate-wise extremes can come from different keys. The ellipsoid bound sits in between in some settings.
- Raise key scatter or query sharpness and more blocks become risky. Try larger blocks: cheaper summaries, but blurrier ones.
Demo maths: a synthetic single head (no grouped-query attention). N = 1,024 tokens, d = dv = 32. There are 24 topic vectors with N(0, 1) components, and keys k = t + σ·N(0, I). Values are a per-topic mean plus noise, scaled so that a typical ‖v‖ ≈ 1. The query is |q| · unit(a blend of two topic vectors that hops every 8 steps, + 0.5·N(0, I) noise). Blocks are contiguous. Opened tokens enter the softmax with exp(q·ki/√d); each summarised block enters once with weight |C| exp(q·k̄C/√d) and value v̄C, as in the paper. "Entries read" counts opened tokens plus one per summarised block. The selection pass also reads per-block metadata (k̄C, plus min/max keys for the box bound), which is not counted. On these synthetic keys the summed bound 2ΣRC is loose, and can exceed the trivial bound 2Vmax. The paper reports how often that happens on real models (its Table 11). RefineKV only uses the per-block terms to rank and threshold blocks. The oracle curve keeps the top-n tokens by exact αi and renormalises. The 17.6% / 96.4% figures, τ = 0.01 and the speed-ups are from the paper; every other number on this page comes from the simulation.