AI GLOSSARY · AI CONCEPTS
KV cache
Definition
A KV cache stores the key and value vectors a Transformer has already computed for earlier tokens, so a model generating text one token at a time can reuse them instead of recomputing them. It trades memory for speed.
Also called: key-value cache, KV caching, KV cache in LLMs, KV cache transformer, key value cache.
In plain language
An autoregressive Transformer can generate one token at a time, using earlier tokens as context. Without a memory aid, the model would redo the same calculations for the earlier text at every step. A KV cache is that memory aid: it keeps intermediate results from the earlier text so they can be reused. Think of keeping notes on a long conversation instead of rereading it from the start each time. The cache takes memory. A dynamic full-attention cache can grow with processed text, while static caches preallocate storage and sliding-window or chunked layers can stop growing at their configured limits. Hugging Face's documentation says the cache can become a bottleneck for long-context generation, which is why a long input can run a model out of memory.
Technical definition
In an autoregressive Transformer, attention uses key and value vectors for earlier tokens. Hugging Face's Transformers documentation says these are calculated every time because the model predicts one token at a time, and that a KV cache stores the calculations so they can be reused without recomputation. Dynamic full-attention caches grow as generation proceeds; static caches preallocate memory, and sliding-window or chunked layers have bounded cache growth. The same documentation says it can occupy a significant portion of memory and become a bottleneck for long-context generation, and it describes offloading the cache to the CPU and quantizing it as ways to trade speed for lower memory use. The vLLM paper (Kwon et al.) states that each request's KV cache is very large and changes size dynamically, and that poor management can waste memory through fragmentation and duplication, which limits batch size.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Skill by Skill Almanac · Illustrative, not executed
local-model-sizing 57/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- The skill works out whether an open-weight language model will run on a given GPU, Mac or PC, with a script that computes weight, KV-cache and overhead memory per quantization.
- Why it exercises the concept
- Its one-line description names KV-cache memory as one part of the fit estimate, next to the model weights. That is the cache this entry defines.
Guide · Illustrative, not executed
Self-Hosting an AI Agent: What You Take On
- What you see
- A guide to what you take on when an AI agent runs on your own machine, including the model server and the check that a model fits your hardware.
- Why it exercises the concept
- Self-hosting is where memory costs fall on you rather than on a service provider. The guide mentions the context cache only in passing, as one of the things competing for memory, so it is a contrast case about fit.
Guide · Illustrative, not executed
What Is an LLM? The Facts Agent Users Need
- What you see
- A guide distinguishing language-model objectives, with an illustrative causally masked Transformer decoder and a contrasting bidirectional BERT example.
- Why it exercises the concept
- KV caching here concerns an autoregressive decoder's generation loop, not every language model described by the guide. The guide does not discuss the cache itself.
How it shows up when you use agents
You do not usually see a KV cache directly in Claude Code, Codex or Cursor. It lives inside the service or the local server that runs the model. You feel its effects as limits: how long a prompt a model can take, how many requests a server can handle at once, and whether a local model runs out of memory partway through a long session.
If you run a model yourself, for example behind a local coding agent, the cache is a memory cost on top of the model weights. Hugging Face's documentation notes that it can become a bottleneck for long-context generation, so a model that loads fine can still fail once the conversation grows. For dynamic full-attention caches, processing longer sequences can increase stored K/V data. Allocated memory also depends on the cache strategy and concurrent requests, not just the context window limit. The inference step reads the cache as each new token is produced.
What breaks when this is misunderstood: people size a GPU by the weight file alone, then hit out-of-memory errors in long agent runs. Another mistake is thinking the cache is something the model learned. It holds values computed from the input of a particular request, which is different from the weights learned in training.
Next action: when planning a local setup, include the cache in your memory estimate (the local-model-sizing skill is built to do this) and test with the longest prompts you expect. See also Transformer and Token.
Common confusions
- KV cache versus prompt caching. The KV cache is the stored attention computation described here. Prompt caching is a name used for features offered by services, and a vendor's own documentation defines how a given service does it. Check that page rather than assuming the two are the same.
- KV cache versus model weights. Weights are learned in training. The cache holds values computed from the input; its used capacity and allocated memory depend on the cache strategy.
- KV cache versus the context window. The window is the amount of text a model can take in. The cache is the stored computation for the text already processed.
- Exact versus reduced-precision caching. Equivalent full-precision exact caching reuses attention values rather than deliberately changing the computation. Quantized caches reduce precision, so they cannot be assumed to produce numerically identical results.
Related terms
Terms that mention KV cache
More in AI concepts
Sources
- Cache strategies (KV cache), Hugging Face (accessed 2026-11-24)
- Efficient Memory Management for Large Language Model Serving with PagedAttention — Kwon et al., arXiv (accessed 2026-11-24)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.
Review record
Last verified
Drafted by Claude (original draft) and Codex (automated revisions); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .
Change log (5)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
- : First version.
- : Verifier pass: Narrowed concurrency claim and guide wording.
- : Required source-scope correction applied; independent affected-claim recheck pending.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.