Glossary

What is KV cache?

In Turkish: KV önbelleği · Topic: Models and training

In transformer models, the practice of storing the “key” and “value” intermediate results already computed for earlier tokens and reusing them, so the same work is not repeated during generation.

How does it work?

The attention mechanism looks at the key and value vectors of all earlier tokens whenever a new token is processed. Once computed, those vectors do not change. The cache keeps them in memory, typically on the GPU. When a new token arrives, only its own key and value are computed and added, so the whole history is not reprocessed at each step. The trade-off is that memory use grows as the context gets longer and as more users are served at once.

Why does it matter?

It is one of the core efficiency methods that lets long replies be generated in reasonable time. In models with long context windows it is among the biggest memory consumers, so it affects server costs and how many people can be served at the same time. This is why a lot of research aims to compress or share the cache.

Example

When chatting about a long document, the model does not reprocess the document at every new word; it reuses the intermediate values already computed for it from the cache.

FAQ

Is the KV cache a chatbot's memory?

No. It is a temporary technical store that speeds up computing a single response. It is unrelated to features that remember information across conversations.

Why does it use so much memory?

Separate vectors are stored for every token in every layer and attention head. Memory needs therefore grow along with the number of tokens.

All terms