KV Cache
The KV (Key-Value) cache stores the attention keys and values from already-processed tokens so an LLM can generate each new token without recomputing past work — the single largest consumer of GPU memory during LLM inference, and the primary lever for serving throughput.
AIDOLS Research Team · Editorial standards
Full definition
During autoregressive generation, the transformer's self-attention requires the keys and values of every prior token. Caching them turns generation into linear-cost-per-token rather than quadratic. KV-cache size scales with batch size × sequence length × layers × heads × head-dim, often dominating GPU memory for long contexts. PagedAttention (vLLM) and prefix caching are the two highest-impact optimizations.
Why it matters
KV-cache management is the difference between an LLM serving 1 user per GPU and 50. PagedAttention alone can deliver 2–4× throughput; prefix caching cuts cost further when requests share a long prefix (Anthropic, for example, bills cache hits at 10% or less of the base input price).
Example
A SaaS company's RAG endpoint reuses the same 4,000-token system prompt + retrieved-documents prefix across millions of requests. Prefix caching reduces both latency and cost by ~40%.
Next steps
Related terms
- InferenceInference is the process of running a trained AI model on new, unseen inputs to produce predictions, classifications, or generated content — the part that runs every time a user interacts with the system.
- Inference CostInference cost is the dollar cost of running a trained AI model in production — per request, per user, or per business outcome — and the operating expense that determines whether an AI feature has positive unit economics at scale.
- Context WindowA context window is the maximum amount of text — measured in tokens — a language model can read and reason over in one inference call, equivalent to the model's working memory for that turn.
- TransformerThe transformer is a neural-network architecture built around the self-attention mechanism that has become the dominant model design for language, vision, audio, and multimodal AI since 2017.
- Inference ServerAn inference server is the runtime system that hosts trained AI models behind an API, handling request routing, dynamic batching, KV-cache management, scheduling across GPUs, and hardware acceleration — the layer that turns a model file into a production AI endpoint.
More infrastructure terms
- Model ServingModel serving is the runtime infrastructure that hosts a trained model and exposes it as an API for low-latency online inference at scale, handling batching, autoscaling, GPU sharing, versioning, and routing.
- Speculative DecodingSpeculative decoding is an inference technique where a small "draft" model proposes multiple candidate tokens that the large "target" model verifies in a single forward pass, accepting prefixes that match the target distribution.
- Continuous BatchingContinuous batching is an inference scheduling technique that adds and removes requests from a GPU batch every decoding step, instead of waiting for all requests in a static batch to finish.
Source & further reading
Primary source: Kwon et al. — "Efficient Memory Management for Large Language Model Serving with PagedAttention" (vLLM) (2023).
Citation policy: this entry is part of the AIDOLS AI Implementation Glossary and may be quoted for research, journalism, and education with attribution to aidolsgroup.com/en/glossary/kv-cache/.