← AI glossary

AI glossary · Advanced · Efficiency & infra

KV cache

A KV cache is a mechanism that stores in memory the intermediate results (Keys and Values) an LLM has already computed, so it can reuse them as it generates text one token at a time.

About this term
Level
Advanced · Specialist terms that need the inner workings
Added
2026-10-08
In plain words It is like summarizing a long book: instead of rereading the book from the beginning every time you write a sentence, you look at the notes you took while reading and write the next sentence. The catch is that the longer the book, the thicker the notebook gets.

How it works

When a Transformer model generates a new token, it refers to all previous tokens through a computation called attention, and in doing so it computes values called Key and Value for each token. First, it reads the entire prompt at once to produce these values and stores them in the KV cache. Then, as it generates tokens one by one, it pulls the values from the cache and computes only the Key and Value of the newly generated token, appending them to the cache. As a result, it does not have to recompute the earlier part every time.

How the KV cache is usedPrompt → Read all at once; Read all at once → KV cache(Store); KV cache → Generate next token(Retrieve); Generate next token → KV cache(Append K·V); Generate next token → Generated answerPromptRead all at onceCompute K·V for alltokensKV cacheStored in GPU memoryGenerate nexttokenRefer to the cacheGenerated answerStoreRetrieveAppend K·V
How the KV cache is used A loop in which the model reads the prompt once to fill the cache, then, each time it generates a token, pulls from the cache and appends the new token's Key and Value.

Why it matters

Without a KV cache, the model repeats the same computations as the answer grows longer, which slows things down sharply. The cache is what lets a chatbot keep producing long answers quickly. On the other hand, the cache takes up a lot of GPU memory, so the longer the context window or the more concurrent users, the more memory becomes the bottleneck. That is why many techniques for cutting inference cost and latency focus on how to use the KV cache more sparingly.

Things to know

A KV cache is not something the model learns; it is temporary storage for reusing computation within a single conversation or request. There are various techniques for saving memory, such as quantization that shrinks the cache into smaller number formats, managing memory in fixed-size blocks, and dropping older parts. When multiple requests share the same beginning, that cache can be reused, which is the basis of prompt caching. Shrinking the cache too much can degrade answer quality, so a balance is needed.

Example

The throughput of inference engines that serve LLMs varies greatly depending on how efficiently they manage the KV cache. As with the news covered on this site, 'vLLM v0.31.0 released… focused on optimizing inference performance for DeepSeek-V4.1-Flash', updates to open-source inference engines often focus on running new models faster and more cheaply, and KV cache management is one of the key factors. In video generation research, how to manage the KV cache when generating long videos is also a research topic.

Where it came up on this site

Related terms