AI Glossary Term

What does “KV Cache” mean?

Definition

Stored key and value tensors from previous tokens that let transformers generate new tokens without recomputing past attention.

How KV Cache works

Diagram for KV Cache, layers from top to bottom: Token 1..n: keys and values computed once; Stored in the KV cache; New token: compute only its own key and value; Reuse cached ones for attention.Token 1..n: keys and values computedonceStored in the KV cacheNew token: compute only its own key andvalueReuse cached ones for attention

Example

When a chatbot writes a long reply, it does not recompute attention inputs for every earlier token at each step. It keeps those stored values and only adds those for the newest token.

Why it matters

The cache makes generation much faster, but it uses memory that grows with the conversation length. This is a major factor in serving cost for long contexts.

Common questions

What are keys and values?

Vectors each token produces in attention layers that later tokens use to decide what to focus on.

Why does it limit long contexts?

Cache size grows with the number of tokens, so memory becomes a bottleneck.

How is the cost reduced?

Through quantizing the cache, sharing keys and values across attention heads, and limiting attention windows.

Learn more in our free guides

Test yourself

See also