LLM Inference · KV-Cache Optimization

The context
you already computed.

First surfaced in Tandemly Briefing — 2026-06-02

RAG pipelines re-attach the same retrieved documents to every query. Agents reinject full conversation histories on each turn. Multi-user deployments send the same system prompt millions of times a day. LLM inference engines keep computing the same prefill, over and over, because nothing tracks which context was already seen.

Core concept
ContextPilot sits between LLM applications and inference engines. It identifies shared prompt blocks across users, turns, and sessions, reorders them for maximum cache reuse, and deduplicates repeated content with quality-preserving annotations. The inference engine sees a clean, cache-friendly input. The application sees the same result. No model changes required.
scroll to explore

Prefill is expensive.
And you're paying it twice.

LLM inference splits into two phases: prefill processes the input prompt and decode generates each output token. Prefill is compute-intensive and scales poorly with context length. The KV-cache exists to mitigate this, but it is fragile in ways that matter enormously in production.

The KV-cache stores the attention key-value pairs computed during prefill. When a new request shares an identical prefix with a cached request, the engine skips recomputation for that prefix. In practice, this is extremely common: system prompts, retrieved documents, and conversation histories repeat constantly across requests from different users.

The problem is ordering. KV-cache reuse requires that shared content appears at the exact same position in the token stream. If a RAG pipeline retrieves documents A, B, and C for one user and B, A, and C for the next, neither benefits from the other's cache even though they retrieved identical content. A single token insertion anywhere in the shared prefix invalidates reuse for everything that follows it.

No existing serving layer solves this at scale. Individual applications manage their own caching strategies in isolation. There is no shared index of which context blocks appear across requests, no mechanism to reorder prompts for cache alignment, and no deduplication pass that removes repeated content without degrading quality. ContextPilot fills this gap.

The missing layer

Between the application that constructs prompts and the inference engine that executes them, there is no component that understands cross-request context overlap. ContextPilot introduces exactly this layer: a context-aware middleware that intercepts prompts, finds shared blocks, and restructures them to maximize what the KV-cache can reuse. The inference engine needs no changes. The application needs no awareness of what other users are sending.

Four components.
One middleware layer.

ContextPilot is not a new inference engine or a new cache implementation. It is a layer that sits in front of existing engines like vLLM, SGLang, and llama.cpp, intercepting and restructuring requests before they arrive.

Component 01
Context Index
Cross-request awareness
Tracks which content blocks appear in which requests, building an index of shared context across users, turns, and sessions. This is the foundation: without knowing what is shared, nothing else is possible. The index operates incrementally as requests arrive, with no batch preprocessing step.
Component 02
Reorder
Prefix alignment
Moves shared context blocks to the front of each prompt so the longest possible shared prefix aligns across requests. Because KV-cache reuse requires identical token positions, ordering is everything. Two requests sharing the same five retrieved documents gain nothing from that overlap if the documents appear in different order.
Component 03
Deduplicate
Token budget recovery
Identifies truly identical content within a prompt and replaces repeated blocks with succinct annotations that preserve semantic quality. The annotations are designed so the model retains full understanding of the deduplicated content, maintaining or improving reasoning accuracy while reducing the token count the engine must process.
Component 04
Cache-aware Scheduling
Batch coordination
Schedules requests that share context blocks to execute in the same batch, so the KV-cache is warm for the shared prefix when each request arrives. Works cooperatively with the inference engine's existing batch scheduler without replacing it.
What ContextPilot does not require

No model retraining. No changes to the inference engine's core attention mechanism. No modifications to existing application code beyond routing requests through the middleware. The technique is orthogonal to model architecture and works with any transformer-based LLM served by a compatible engine.

Up to 3x faster prefill.
36% fewer tokens.

Benchmarked against prior SOTA long-context serving methods, ContextPilot delivers large prefill speedups with preserved or improved reasoning quality across multiple deployment scenarios.

4-12x
KV-cache hit rate improvement over baseline serving
3x
Peak prefill latency reduction vs. prior SOTA at matched quality
36%
Reduction in tokens processed after deduplication
0
Model changes, retraining steps, or engine modifications required
Enterprise document QA

RAG pipelines that retrieve the same 5 to 10 documents across hundreds of concurrent queries saw the largest gains. The context index identifies the repeated document chunks immediately, the reorder pass aligns their position in every request's prefix, and the KV-cache hit rate climbs by more than 10x over unstructured serving. Prefill latency dropped to under one-third of baseline at peak load.

Multi-turn memory chat

Agents that inject full conversation history on each turn send a growing prefix where earlier turns are identical across many requests for the same user. ContextPilot's reorder and deduplicate passes align these shared turn blocks and compress repeated content, cutting the effective token count by roughly one-third. Prefill latency improvements compound as context length grows.

Apple Silicon and resource-constrained serving

Token reduction is not just a throughput gain on data-center hardware. On Apple Silicon deployments where memory bandwidth is the binding constraint, fewer tokens per request translates directly to lower peak memory pressure and more headroom for concurrent requests. ContextPilot's gains hold in this setting without engine modification.

Scope and caveats

Gains are largest when prompt overlap is high. Workloads with low cross-request context sharing will see smaller improvements: a deployment where every user sends entirely unique long-form documents will gain little from the reorder pass. Baseline your own workload before extrapolating published reduction figures. The paper reports results across enterprise document QA, multi-turn chat, and constrained-hardware scenarios; gains vary by task type and request distribution.

What this means
for building with LLMs.

The core insight is that prompt prefix overlap is latent value most deployments never capture. Before scaling more hardware, it is worth measuring how much of that value already exists in your workload.

1
For inference infrastructure teams
Profile your prompt prefix overlap before your next GPU purchase. If your workload has significant shared context across requests (common in RAG, agent memory, and multi-tenant system-prompt scenarios), a middleware layer that exploits that overlap may deliver more throughput improvement per dollar than additional hardware. Measure first.
2
For LLM application developers
Prompt construction order matters for cache efficiency. Structure prompts so shared content appears at the start and variable content at the end. This is the minimum the KV-cache needs to work. ContextPilot automates this reordering, but even without it, deliberate prefix design reduces prefill cost in any cache-aware engine.
3
For RAG system designers
Retrieval pipelines that pull the same chunks for many queries are silently paying the prefill cost each time. Tracking which chunks are "hot" across your query distribution is both a retrieval optimization and a serving optimization: those chunks are your best candidates for aggressive caching and prefix alignment.
4
For business leaders evaluating serving costs
Token reduction is cost reduction. Every token that does not need processing is latency saved and compute budget recovered. Before accepting prefill cost as a fixed function of context length, ask your infrastructure team what fraction of that context is shared across requests and whether your serving stack exploits that overlap.

Where to go
from here.

Applying these ideas starts with measurement. You cannot optimize context reuse you have not measured.

1
Measure your prompt overlap now
Log a sample of prompts from a recent production window and compute prefix overlap across requests. Count how many requests share a common system prompt, the same retrieved documents, or identical conversation history segments. This number tells you how much latent value a reorder-and-cache layer could recover.
2
Order shared context first in your prompt construction
Without any middleware, move your system prompt, retrieved documents, and any other shared context to the top of the prompt before variable per-request content. Most cache-aware inference engines (vLLM, SGLang, llama.cpp) will benefit immediately. This costs a refactor, not a hardware purchase.
3
Pilot ContextPilot on a representative workload
ContextPilot is designed to be deployed in front of existing inference engines without changes on either side. Run a representative sample of your query distribution through it and compare prefill latency, throughput, and output quality against your current baseline before committing to full deployment.
4
Track TTFT alongside token count
Time to first token (TTFT) is the user-visible consequence of prefill latency. Add it to your serving dashboard alongside token count and KV-cache hit rate. These three metrics together give you enough signal to know whether a context-reuse layer is doing its job and where to focus further optimization.
5
Read the paper
Jiang, Y., Huang, Y., Cheng, L., Deng, C., Sun, X., & Mai, L. (2026). ContextPilot: Fast Long-Context Inference via Context Reuse. University of Edinburgh. MLSys 2026. arXiv:2511.03475.