Case & CodeA FIELD GUIDE TO AI
Start learning
Advanced

KV cache — Key-value cache

In plain words

Stored results from part of a model's earlier work. Reusing them can speed up the next step. This cache also takes memory.

The fuller definition

A key-value cache stores attention-related representations from earlier tokens so an autoregressive model can reuse them while generating later tokens.

How it fits together
  1. Earlier tokens

    Compute keys and values

  2. Cache

    Retain reusable state

  3. Next token

    Reuse prior computation

A simplified relationship, not a screenshot or a complete design.

A concrete example

As a conversation grows, its cached sequence state can consume additional memory.

The distinction that matters

Caching reduces repeated computation but does not create unlimited context or permanent memory.

Related terms

Where it is taught

Understand the hardware a local model needs

Source and further reading

Hugging Face · Model inference and quantization

The definition and example are written for this library. The link gives background, official documentation or legal authority as labelled. Legal scope depends on the jurisdiction and current text; product features depend on release and settings.

Lessons, terms, practical guides and sources ESC