MarginKV

Storage-efficient KV cache reuse for decoder-only reranking

A reranker reads every candidate document again for every query. MarginKV makes Qwen3-Reranker-0.6B read the document first, so the document's KV cache is built once and reused across queries, then measures how far that stored cache can be compressed (quantization, token pruning, both) before ranking quality drops, whether loading it from disk beats recomputing it, and how much of it a real serving stack actually reuses.

Setup: BEIR SciFact and NFCorpus, BM25 top 100, top 20 reranked, documents truncated to 256 tokens, nDCG@10 and MRR@10 with paired bootstrap CIs. Decision rules were committed before the runs.

Document first, quality kept
SciFact−0.0051[−0.0190, +0.0078]
NFCorpus+0.0058[+0.0003, +0.0118]
nDCG@10, doc-first LoRA vs the original query-first model
Uniform 75% + INT4 KIVI: 4.21x smaller
SciFact−0.00286.27 MiB/doc
NFCorpus−0.00016.27 MiB/doc
nDCG@10 change vs BF16 cache, packed bytes on disk. INT4 KIVI alone: 3.17x smaller, +0.0010 / −0.0009.
Repeats are not hits
SciFact46%16% / 23%
NFCorpus62%29% / 37%
docs that repeat in the query stream / prompt tokens from cache, BF16 / FP8 KV (vLLM)

Table 1: does document-first ordering cost quality?

SystemSciFact nDCG@10 / MRR@10NFCorpus nDCG@10 / MRR@10
BM25
first stage, top 100
0.6791 / 0.64310.3187 / 0.5245
Original query-first
Qwen3-Reranker-0.6B as released
0.7555 / 0.73450.3485 / 0.5662
Query-first LoRA (control)
same MS MARCO training, original order
0.7617 / 0.73960.3504 / 0.5721
Doc-first zero-shot
document first, no training
0.2855 / 0.22190.2350 / 0.3705
Doc-first LoRA
document first, KV reusable across queries
0.7504 / 0.72390.3543 / 0.5879

Length-matched retrain (ablation)

SystemSciFact nDCG@10 / MRR@10NFCorpus nDCG@10 / MRR@10
Original query-first
Qwen3-Reranker-0.6B as released
0.7555 / 0.73450.3485 / 0.5662
Query-first LoRA
trained on MS MARCO passages (Phase 4)
0.7617 / 0.73960.3504 / 0.5721
Doc-first LoRA
MS MARCO passages (Phase 4); the model used everywhere else
0.7504 / 0.72390.3543 / 0.5879
Query-first LoRA, long docs
MS MARCO documents, first 256 tokens
0.7349 / 0.70570.3484 / 0.5767
Doc-first LoRA, long docs
MS MARCO documents, first 256 tokens
0.7300 / 0.70170.3507 / 0.5873
Paired difference, nDCG@10SciFact Δ [95% CI]NFCorpus Δ [95% CI]
Doc-first − query-first, Phase 4 (order gate)−0.0113 [−0.0243, +0.0014]+0.0039 [−0.0021, +0.0099]
Doc-first − query-first, long docs−0.0049 [−0.0181, +0.0089]+0.0023 [−0.0044, +0.0086]
Gap change (pre-registered primary)+0.0063 [−0.0087, +0.0218]
not shown
−0.0016 [−0.0080, +0.0045]
not shown
Doc-first: long docs − Phase 4−0.0204 [−0.0336, −0.0080]−0.0036 [−0.0091, +0.0017]
Query-first: long docs − Phase 4−0.0267 [−0.0426, −0.0118]−0.0020 [−0.0066, +0.0026]

The Phase 4 row is recomputed with the same 10,000-resample bootstrap as the long-doc rows, so its CI differs slightly from Table 1's, which comes from the original evaluation run (1,000 resamples).

Storage vs. quality

Each document's KV cache is stored once and reused for every query, so its size on disk is the cost. Each point is one way to store it: quantized, pruned to a share of its tokens, or both. Packed size per document (real files: codes, scales, headers) against the change in nDCG@10 relative to the uncompressed BF16 cache, with a 95% paired bootstrap CI.

Baseline No measurable loss Within 1 point Loss ±0.002 margin

9 points below this view, drawn as triangles at the edge (lowest: Attention (b) 25%, −0.1637). Use "All points" to see them.

SettingMiB/docvs BF16SciFact Δ nDCG@10 [95% CI]NFCorpus Δ nDCG@10 [95% CI]
Quantization
BF16
uncompressed baseline, shared prefix stored once
26.401.00x0.75060.3538
FP8 per-tensor
e4m3, one scale per tensor
13.202.00x−0.0013 [−0.0042, +0.0006]
Within 1 point
−0.0006 [−0.0017, +0.0006]
No measurable loss
FP8 per-head
e4m3, one scale per KV head
13.202.00x−0.0015 [−0.0043, −0.0001]
Within 1 point
+0.0004 [−0.0010, +0.0020]
No measurable loss
INT8 per-token
symmetric, one scale per head and token
13.411.97x−0.0002 [−0.0008, +0.0004]
No measurable loss
−0.0001 [−0.0015, +0.0013]
No measurable loss
INT4 KIVI
keys per channel, values per token, groups of 32
8.333.17x+0.0010 [−0.0007, +0.0038]
Within 1 point
−0.0009 [−0.0027, +0.0007]
Within 1 point
INT4 per-token
keys and values per token, groups of 32 (diagnostic)
8.253.20x−0.0966 [−0.1200, −0.0742]
Loss
−0.0434 [−0.0550, −0.0323]
Loss
Pruning
Uniform 25%
evenly spaced doc tokens; kept tokens stored in BF16
6.594.01x−0.0617 [−0.0861, −0.0379]
Loss
−0.0194 [−0.0282, −0.0108]
Loss
Uniform 50%
evenly spaced doc tokens; kept tokens stored in BF16
13.241.99x−0.0122 [−0.0277, +0.0029]
Loss
−0.0080 [−0.0134, −0.0028]
Within 1 point
Uniform 75%
evenly spaced doc tokens; kept tokens stored in BF16
19.821.33x−0.0014 [−0.0096, +0.0063]
Within 1 point
−0.0006 [−0.0041, +0.0030]
Within 1 point
Boundary 25%
first 4 + most recent tokens (StreamingLLM-style); kept tokens stored in BF16
6.594.01x−0.1488 [−0.1797, −0.1181]
Loss
−0.0504 [−0.0649, −0.0370]
Loss
Boundary 50%
first 4 + most recent tokens (StreamingLLM-style); kept tokens stored in BF16
13.241.99x−0.0822 [−0.1080, −0.0568]
Loss
−0.0314 [−0.0430, −0.0206]
Loss
Boundary 75%
first 4 + most recent tokens (StreamingLLM-style); kept tokens stored in BF16
19.821.33x−0.0310 [−0.0487, −0.0140]
Loss
−0.0161 [−0.0235, −0.0090]
Loss
Attention (a) 25%
attention the token receives from later doc tokens, length-normalized; kept tokens stored in BF16
6.594.01x−0.0875 [−0.1136, −0.0625]
Loss
−0.0385 [−0.0506, −0.0268]
Loss
Attention (a) 50%
attention the token receives from later doc tokens, length-normalized; kept tokens stored in BF16
13.241.99x−0.0294 [−0.0463, −0.0129]
Loss
−0.0138 [−0.0199, −0.0079]
Loss
Attention (a) 75%
attention the token receives from later doc tokens, length-normalized; kept tokens stored in BF16
19.821.33x−0.0092 [−0.0205, +0.0014]
Within 1 point
−0.0063 [−0.0101, −0.0028]
Within 1 point
Attention (b) 25%
(a) weighted by absolute position; kept tokens stored in BF16
6.594.01x−0.1637 [−0.1939, −0.1340]
Loss
−0.0604 [−0.0742, −0.0468]
Loss
Attention (b) 50%
(a) weighted by absolute position; kept tokens stored in BF16
13.241.99x−0.0416 [−0.0626, −0.0212]
Loss
−0.0231 [−0.0311, −0.0153]
Loss
Attention (b) 75%
(a) weighted by absolute position; kept tokens stored in BF16
19.821.33x−0.0101 [−0.0214, +0.0007]
Loss
−0.0091 [−0.0135, −0.0049]
Within 1 point
Random 25%
one seed per document; kept tokens stored in BF16
6.594.01x−0.0818 [−0.1089, −0.0558]
Loss
−0.0287 [−0.0389, −0.0186]
Loss
Random 50%
one seed per document; kept tokens stored in BF16
13.241.99x−0.0146 [−0.0308, +0.0011]
Loss
−0.0079 [−0.0147, −0.0013]
Within 1 point
Random 75%
one seed per document; kept tokens stored in BF16
19.821.33x−0.0009 [−0.0088, +0.0067]
Within 1 point
+0.0002 [−0.0044, +0.0048]
Within 1 point
H2O-style 25%
accumulated attention; diagnostic, never selected; kept tokens stored in BF16
6.594.01x−0.0383 [−0.0571, −0.0206]
Loss
−0.0113 [−0.0178, −0.0047]
Loss
H2O-style 50%
accumulated attention; diagnostic, never selected; kept tokens stored in BF16
13.241.99x−0.0125 [−0.0256, −0.0009]
Loss
−0.0028 [−0.0070, +0.0011]
Within 1 point
H2O-style 75%
accumulated attention; diagnostic, never selected; kept tokens stored in BF16
19.821.33x−0.0049 [−0.0125, +0.0025]
Within 1 point
−0.0014 [−0.0040, +0.0010]
Within 1 point
Pruning + quantization
Uniform 75% + FP8 per-tensor
prune first, then quantize the kept tokens
9.912.66x−0.0029 [−0.0112, +0.0046]
Within 1 point
−0.0020 [−0.0058, +0.0017]
Within 1 point
Uniform 75% + INT4 KIVI
prune first, then quantize the kept tokens
6.274.21x−0.0028 [−0.0110, +0.0048]
Within 1 point
−0.0001 [−0.0039, +0.0037]
Within 1 point

MiB/doc and ratios are SciFact means (NFCorpus agrees closely). BF16 row shows absolute nDCG@10. Pruning points on the chart are spread ±0.625 MiB around their real size so the methods at one retention don't overlap; the tooltip and table show the real size. Pruned tokens are removed from the stored cache; the shared system and instruction prefix is stored once per corpus and never pruned.

Query explorer: what each cache does to one ranking

Every number above is an average over hundreds of queries. Here is one query at a time: its 20 BM25 candidates, and the rank each stored-cache format gives them. Arrows are the move against BF16; ranks 1 to 10 (bold) are the ones nDCG@10 counts. Click a column header to order the rows by that format.

Loading SciFact queries…

Storage calculator

How much disk does a document KV store need? Pick a corpus size and an average document length. Sizes come from the exact packed file format (codes, scales, headers), with the shared system and instruction prefix stored once per corpus.

FormatPer tokenPer docCorpus totalMeasured filesvs naive
Naive BF16
prefix repeated in every doc
112 KiB34.4 MB111 GB
103 GiB
1.00x
BF16
uncompressed baseline, shared prefix stored once
112 KiB27.7 MB89.0 GB
82.9 GiB
82.9 GiB
fit exact
1.24x
FP8 per-tensor
e4m3, one scale per tensor
56.0 KiB13.8 MB44.5 GB
41.5 GiB
41.5 GiB
fit exact
2.49x
FP8 per-head
e4m3, one scale per KV head
56.0 KiB13.8 MB44.5 GB
41.5 GiB
41.5 GiB
fit exact
2.49x
INT8 per-token
symmetric, one scale per head and token
56.9 KiB14.1 MB45.2 GB
42.1 GiB
42.1 GiB
fit exact
2.45x
INT4 KIVI
keys per channel, values per token, groups of 32
35.0 KiB8.70 MB28.0 GB
26.1 GiB
26.2 GiB
fit −0.37%
3.96x
INT4 per-token
keys and values per token, groups of 32 (diagnostic)
35.0 KiB8.65 MB27.8 GB
25.9 GiB
25.9 GiB
fit exact
3.98x
With 75% pruning (keeps 181 of 241.34 doc tokens)
75% pruning, BF16
keep 75% of doc tokens (any method), stored in BF16
84.0 KiB20.8 MB66.8 GB
62.2 GiB
62.2 GiB
fit −0.11%
1.66x
75% pruning + FP8 per-tensor
prune, then quantize the kept tokens
42.0 KiB10.4 MB33.4 GB
31.1 GiB
31.1 GiB
fit −0.11%
3.32x
75% pruning + INT4 KIVI
prune, then quantize the kept tokens
26.2 KiB6.53 MB21.0 GB
19.6 GiB
19.7 GiB
fit −0.80%
5.28x

Disk: loading a stored cache vs recomputing it

A KV store only pays off if reading a document's cache back is cheaper than computing it again. Each bar is a cold load from disk (page cache evicted first) on NVIDIA GeForce RTX 4090, over 1,000 documents, split into its stages. The dashed line is recomputing the same document's KV with a forward pass.

BF16
26.35 MiB/doc
p50 57.4 ms · 1.67x
FP8 per-tensor
13.18 MiB/doc
p50 21.7 ms · 0.63x
FP8 per-head
13.18 MiB/doc
p50 21.6 ms · 0.63x
INT8 per-token
13.38 MiB/doc
p50 21.6 ms · 0.63x
INT4 KIVI
8.32 MiB/doc
p50 24.5 ms · 0.71x
INT4 per-token
8.24 MiB/doc
p50 22.5 ms · 0.65x
75% pruning + FP8 per-tensor
9.89 MiB/doc
p50 17.0 ms · 0.49x
75% pruning + INT4 KIVI
6.26 MiB/doc
p50 21.5 ms · 0.62x
0102030405060
ms; ratio vs recompute
read file (mean) parse (mean) copy to GPU (mean) decode (mean) p50 total recompute p50 (34.4 ms)
FormatMiB/docCold p50 (p95) msWarm p50 msRead / decode ms (p50)Cold MB/s p50Cold / recompute
BF16
uncompressed baseline, shared prefix stored once
26.3557.4 (64.4)42.734.2 / 0.84951.67x
FP8 per-tensor
e4m3, one scale per tensor
13.1821.7 (24.4)9.914.0 / 4.06650.63x
FP8 per-head
e4m3, one scale per KV head
13.1821.6 (24.0)9.714.1 / 3.96650.63x
INT8 per-token
symmetric, one scale per head and token
13.3821.6 (22.8)9.614.2 / 3.86820.63x
INT4 KIVI
keys per channel, values per token, groups of 32
8.3224.5 (27.5)16.79.0 / 13.13680.71x
INT4 per-token
keys and values per token, groups of 32 (diagnostic)
8.2422.5 (23.6)14.88.9 / 11.34030.65x
75% pruning + FP8 per-tensor
prune, then quantize the kept tokens
9.8917.0 (18.2)8.010.5 / 3.96410.49x
75% pruning + INT4 KIVI
prune, then quantize the kept tokens
6.2621.5 (22.8)15.47.1 / 12.43200.62x

Sizes are the means of the benchmarked documents. One rented GPU's container disk and our own Python loader (two CPU copies per file, unfused INT4 dequant); a zero-copy or GPU-direct loader would change the absolute numbers and possibly the INT4 vs FP8 order. Recompute was measured for this 0.6B model at about 300 tokens.

Serving: does the stored cache actually get reused?

The real BEIR query stream, replayed in order through vLLM 0.34.0 with prefix caching on one RTX 4090: every query in file order, each with its 20 BM25 candidates. Many documents come back for later queries. The question is how much of that a real cache turns into reuse.

SciFact 6,000 requests
Documents that repeat in the stream
46%
Doc-first, unlimited cache (simulated, 64-token blocks)
38%
Doc-first, FP8 KV (341k tokens of cache)
24%
Doc-first, BF16 KV (178k tokens of cache)
17%
Query-first (original model)
0%
NFCorpus 6,460 requests
Documents that repeat in the stream
62%
Doc-first, unlimited cache (simulated, 64-token blocks)
49%
Doc-first, FP8 KV (341k tokens of cache)
37%
Doc-first, BF16 KV (178k tokens of cache)
29%
Query-first (original model)
1%

First bar: share of requests whose document appeared earlier in the stream. Other bars: share of document tokens served from the prefix cache (measured runs: cold cache, concurrency 16).

SettingKV cacheSciFact: prompt hit / doc reuseNFCorpus: prompt hit / doc reusenDCG@10c=1 p50 ms
Query-first (original model)178k tok18.3% / 0.0%19.8% / 0.9%0.7561 / 0.349017.4 / 15.8
Doc-first, BF16 KV178k tok15.9% / 16.9%
44% of unlimited cache
28.6% / 28.6%
58% of unlimited cache
0.7507 / 0.354915.6 / 15.7
Doc-first, FP8 KV341k tok22.5% / 23.7%
62% of unlimited cache
36.9% / 36.8%
75% of unlimited cache
0.7476 / 0.354315.7 / 16.1

Prompt hit: share of all prompt tokens served from cache. Doc reuse: share of document tokens. nDCG@10 and latency as SciFact / NFCorpus. Query-first uses the original model, doc-first the LoRA; each was checked against its own Hugging Face reference. High-concurrency throughput was noisy run to run, so settings are not ranked on it.

Limitations