SAFE-KV: Causal Suffix Repair for Behavior-Preserving Non-Prefix KV Cache Reuse in RAG
Organizations: Carnegie Mellon University, Pittsburgh, PA, USA
Abstract
Retrieval-augmented generation (RAG) reuses the same documents across many requests, making non-prefix KV-cache reuse attractive. Yet a cached document state is not reusable text: it is a context-conditioned causal state whose keys and values depend on the prefix, position, and preceding documents under which it was computed. We formulate non-prefix KV reuse as a behavior-preservation problem with full prefill on the exact prompt as the reference, and introduce SAFE-KV, which repairs a composed cache by re-encoding the causal suffix from a selected start document. On Qwen2.5-7B-Instruct, prefix-conditioned composition preserves only 47.2% of HotpotQA-500 and 37.8% of 2Wiki-500 full-prefill answers; SAFE-KV with risk-guided K2 selection restores 99.8%/98.4% (donor-copy protocol) and 100.0%/98.4% with actual suffix forwarding. Document-only and fixed-window repairs recover far less, because the document states after the repaired region keep histories that omit it. Reuse without repair is exact up to four documents and degrades at sixteen, where suffix repair recovers 98-100%. Faithful repair re-encodes most of the context, so in a single-request L40S study SAFE-KV's operating rule serves every workload by full prefill. SAFE-KV thus establishes the causal-state contract for non-prefix reuse and a validated repair mechanism that meets it.
Figures & tables
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Path | Ans. eq. [95% CI] | Token exact | Gold EM | Changed-wrong |
|---|---|---|---|---|
| Full prefill | 1.000 | 1.000 | 0.920 | 0 |
| Donor-copy Risk K1 (diagnostic) | 0.640 [0.50, 0.76] | 0.640 | 0.600 | 18 |
| Actual-forwarding Risk K1 | 0.440 [0.30, 0.58] | 0.440 | 0.440 | 27 |
| Experiment | Key result | Interpretation | Design decision |
|---|---|---|---|
| External 7B composition | Prefix composition preserves only 47.2% HotpotQA and 37.8% 2Wiki full-prefill answers. | Non-prefix document reuse is a behavioral problem even after matching the instruction prefix. | Make full-prefill behavior preservation the primary contract. |
| Document-only repair | On Noise16, oracle evidence-document patching reaches only 54.4% equivalence. | Gold evidence labels are not causally closed cache repair units. | Repair causally closed units rather than evidence documents. |
| Downstream windows | On 2Wiki-100, w4 reaches 79.0% equivalence at 72.9% patch ratio; suffix K1 reaches 97.0% at 79.3%. | Repair quality changes sharply when the recomputed region crosses the causal frontier. | Use suffix closure rather than a fixed local window. |
| Linked intervals | On Noise16, oracle linked intervals reach 80.0%, below oracle suffix closure at 93.6%. | Human-plausible reasoning chains do not always match transformer cache dependencies. | Keep linked intervals as a negative ablation. |
| Adaptive suffix | On Noise16, risk adaptive suffix keeps 86.8% equivalence at 57.9% patch ratio versus risk suffix K2 at 88.8% and 69.9%. | Budget can be traded for fidelity, but aggressive trimming increases residual drift. | Present SAFE-KV as a quality–budget family. |
| Learned selector | On external selector diagnostics, synthetic-trained learned selection has near-zero evidence recall. | Selector learning is sensitive to supervision shift; the stable contribution is the repair contract. | Use lightweight query/risk selectors in the main paper and report the learned-selector failure. |
| Work | Reuse setting | Main goal | Full-prefill safety oracle? | Repair granularity? | Matched random controls? |
|---|---|---|---|---|---|
| vLLM/PagedAttention | serving cache management | throughput/memory efficiency | no | no | no |
| LMCache | cache storage/transfer/reuse layer | system reuse | no | no | no |
| Prompt Cache | modular prompt reuse | latency reduction | limited | no | no |
| CacheBlend | non-prefix chunk fusion | serving efficiency + quality | partially, systems-focused | selective token recompute | not this framing |
| Cache-Craft | chunk-cache management for RAG | TTFT/throughput with quality control | no (task accuracy) | selective token recompute | no |
| KVLink | independent document cache reuse | speed + QA with adjustment/training | limited | no | no |
KV-Cache Reuse
Key-value (KV) cache reuse lets language models reuse previously computed attention states to cut repeated prefill work and serving latency.
See all 73 papers