TL;DR
Reusing precomputed Key-Value (KV) caches across different prompts usually requires expensive recomputation because KV states are highly context-dependent. KV Packet solves this by wrapping cached documents in lightweight, trainable "soft-token" adapters (Headers and Trailers) that absorb boundary artifacts. This allows for direct, recomputation-free cache concatenation, slashing inference latency (TTFT) and computational overhead (FLOPs) while maintaining model accuracy.
What Problem Does This Paper Address?
In Retrieval-Augmented Generation (RAG) systems, Large Language Models (LLMs) frequently process the same documents repeatedly across different user queries. Precomputing and caching the Key-Value (KV) states of these documents offline can drastically speed up the "prefill" phase of LLM inference.
However, standard KV caches are context-dependent: a token's KV state is conditioned on every single token that came before it. If you independently cache Document A and Document B, you cannot naively stitch their caches together at inference time; doing so breaks the model's attention distribution, leading to catastrophic performance degradation. Existing solutions try to fix this "contextual staleness" by selectively recomputing a subset of tokens during inference. While this is faster than a full recompute, it still introduces significant computational overhead (FLOPs) and increases Time-to-First-Token (TTFT) latency.
Methods
The authors introduce KV Packet, a framework that enables context-independent KV caching without modifying the base model's parameters or requiring online recomputation.
The KV Packet Abstraction
Instead of treating a cached document as a raw sequence of tokens, KV Packet wraps each document block with learned, universal soft-token adapters: a Header ($H$) and a Trailer ($T$).
- Offline Cache Generation: Document embeddings are padded with the Header and Trailer tokens at the embedding level before the KV cache is generated. The resulting KV cache is stored in a database as an immutable "packet."
- Online Inference: When a user query retrieves a set of documents, the system performs a lightweight positional alignment (using a closed-form Rotary Position Embedding (RoPE) shift) and directly concatenates the precomputed KV packets. This completely eliminates the need to run attention or feed-forward network (FFN) layers over the document tokens during the prompt processing phase.
Self-Supervised Distillation
To train the Header and Trailer tokens, the authors use a self-distillation objective where the frozen LLM acts as its own teacher.
- Reference Pass: The model processes the full, naturally concatenated context using standard causal attention to generate a target token probability distribution ($P_{teacher}$).
- Student Pass: The model processes the same context using the KV Packet architecture to produce an approximated distribution ($P_{student}$).
- Loss: The adapters are optimized by minimizing the Kullback-Leibler (KL) divergence between $P_{teacher}$ and $P_{student}$. Crucially, the base LLM remains entirely frozen, preventing catastrophic forgetting.
Datasets
The framework was evaluated using Llama-3.1-8B-Instruct and Qwen-3-4B-Instruct across four distinct datasets:
- Needle-in-a-Haystack (NIAH): A synthetic benchmark for simple information retrieval in long contexts.
- Biography: A natural language dataset focused on factual entity extraction.
- HotpotQA: A benchmark requiring multi-hop reasoning over multiple documents.
- MusiQue: A challenging multi-step reasoning dataset with complex document dependencies.
No new benchmarks were introduced in this paper.
Key Insights and Ideas
- The "Boundary Artifact" Hypothesis: The authors discover that the catastrophic failure of naive cache concatenation isn't necessarily due to a lack of deep cross-document semantic understanding. Instead, it is primarily caused by boundary artifacts—abrupt shifts in token distributions and the disruption of "attention sinks" at block boundaries. Naively concatenated documents cause the model to treat the first token of every document as a sequence-initial token, erroneously spiking attention maps mid-sequence.
- Adapters as Shock Absorbers: The learned Header and Trailer tokens act as structural delimiters. Attention map analysis shows that these adapters successfully absorb the "sink mass" (erroneous attention spikes), redirecting the model's focus smoothly back to the actual document content.
- The Power of Heterogeneous Training: While adapters trained on a single domain (like Biography) struggle with complex reasoning tasks, a Universal wrapper trained on a diverse mixture of all datasets generalizes remarkably well across all domains. This makes it a practical, drop-in solution for real-world RAG systems where document domains are unpredictable.
Key Results
- Near-Zero FLOPs: Because KV Packet is entirely recomputation-free, it reduces inference-time computational overhead by 5 to 6 orders of magnitude compared to full recomputation, perfectly matching the zero-overhead baseline of naive concatenation.
- Drastic Speedups (TTFT): In long-context settings, KV Packet delivers massive latency reductions. The authors observed a 19.45× reduction in TTFT on Needle-in-a-Haystack and a 5.81× reduction on MusiQue compared to recomputation-based baselines.
- Maintained Accuracy: KV Packet retains F1 scores comparable to the full recomputation upper bound, significantly outperforming selective recomputation methods (like EPIC and CacheBlend) at low computational budgets.
- KV Compression Compatibility: Unlike recomputation-based methods—which break down when caches are compressed unevenly across layers—KV Packet treats caches as opaque units. It integrates seamlessly with off-the-shelf unstructured KV pruning techniques (such as TOVA, CUR, and KVzap).
Limitations and Future Work
- Out-of-Distribution Generalization: The effectiveness of the adapters assumes that the runtime retrieval corpus is reasonably aligned with the training text distribution. How well these adapters generalize to highly out-of-distribution domains remains an open question.
- Inter-Document Dependencies: KV Packet is optimized for scenarios where retrieved documents are largely independent units. The authors note that its behavior under tightly coupled, dependent document chains (such as sequential multi-step reasoning traces) warrants further investigation.
- Model Scope: Due to the engineering complexity of implementing recomputation baselines, the current evaluation only covers a limited set of model families (Llama and Qwen).
Summary updated