What Is KV Cache?

KV cache (key-value cache) is a store of previously computed key and value vectors used during large language model inference. It lets models respond faster by reusing these vectors rather than recalculating them for all previous tokens each time they generate a new token.

How Does KV Cache Work?

At its core, KV cache is a deliberate trade-off: It saves significant compute by storing key and value tensors in memory for a small cost in capacity that pays for itself many times over in speed. 

When an AI model generates a response, it does not produce the whole reply at once. It produces one token at a time, and before generating each new token, the attention mechanism needs to look back at every token that came before. In transformer models, "attention" is the process that determines which previous words matter most to the current word being generated. 

When processing tokens, attention creates three mathematical representations of every token: a key (K), a query (Q), and a value (V). You can think of the query as a request for information, each key as a label used to determine how well a token matches that request, and each value as the information that token can contribute. 

The attention computation then takes into account K, Q, and V for the new token, as well as the key and value for every prior token (queries for prior tokens are not used). This is how the model understands context. Without caching, AI infrastructure would need to recompute the K and V matrices for all prior tokens for every new token, which would grow computationally expensive very quickly. 

KV cache solves this by acting like a notepad—storing K and V matrices as the model processes the input so they don’t have to be recomputed. This makes the model significantly faster, especially in long conversations or when processing long documents. As the model processes the input prompt (the “prefill” phase), it computes K and V tensors for each token at each transformer layer. These tensors represent what the model "knows" about each token in context. Rather than throwing them away, they get stored in GPU memory—that's the KV cache. During the "decode" phase (generating new tokens), the model only needs to compute K and V for the new token and retrieve the rest from cache, reducing the work per step.

The practical impact is significant: The more context a model carries (a long conversation, a lengthy document, a detailed system prompt), the more time the KV cache saves. If the cache gets too full and entries are removed, the model has to redo that work from scratch. Keeping the cache well managed is therefore central to delivering fast, cost-effective inference. 

How NVIDIA Full Stack Reduces the KV-Cache Footprint

NVIDIA Dynamo inference software moves inactive context to NVIDIA CMX context memory storage and returns it before reuse. Faster tool execution with the NVIDIA Vera CPU also shortens the time KV cache sits inactive during tool calls. This prevents long-running agents from unnecessarily tying up valuable HBM. All leading storage partners integrate NVIDIA Dynamo into their AI solutions, allowing inference workloads to scale beyond GPU memory constraints to support very large context lengths with storage.

Applications and Use Cases of KV Cache

KV cache is essential to nearly every deployment of large language models in the current AI ecosystem, especially as mixture-of-expert (MoE) models have become the standard and models use reasoning to solve longer, more complex prompts. 

Agentic AI further highlights the importance of KV cache. AI agents that reason across many steps, call tools, and loop back need to carry context across the full reasoning chain. In transformer-based models, that long-term memory is realized as inference context—the KV cache, which preserves context so the model does not recompute history for every new token. As agent workflows grow more complex and multi-turn, KV cache persistence across agent steps becomes essential infrastructure.

Anywhere a model repeatedly attends to previously seen content, KV cache converts that from redundant compute into a fast memory lookup. The more repetition or shared context in a workload, the bigger the benefit. KV cache applies to virtually every generative AI workload—any application where a model produces more than a single output token. The gains are largest wherever shared or repeated context appears. The following scenarios illustrate where those advantages are most pronounced.

Retrieval-Augmented Generation: When a system retrieves documents and puts them into a long prompt before asking a question, the document content is identical across many similar queries. KV cache lets the system compute the document representations once and reuse them. When users ask questions about a large document that repeats across requests but with different questions at the end, KV cache reuse delivers roughly a 2x speedup in time to first token. 

Long-Context Document Analysis: As models expand context windows—such as when they analyze legal documents or business contracts—the context window can reach millions of tokens. KV cache becomes a bottleneck since it grows linearly with prompt length and must reside in GPU memory during generation. KV cache offloading to host CPU memory or SSD is often what makes million-token contexts practically deployable.

Large-Batch and High-Concurrency Inference: Serving more users simultaneously means holding more active context in GPU memory at once, which puts significant pressure on both memory capacity and bandwidth during the decode phase. NVIDIA NVFP4 KV cache reduces memory footprint by up to 50% compared to FP8, effectively doubling the batch sizes and user concurrency a given GPU can support, while reducing the memory bandwidth consumed by the constant read/writes of the KV cache during decoding.

What Are the Benefits of KV Cache?

Faster Responses

By avoiding repeated work, KV cache dramatically reduces the time users wait for a reply. NVIDIA TensorRT™-LLM’s KV cache reuse can speed up response time by up to 5x when the same system prompt is reused across users, and up to 14x when extended memory is used to hold large conversation histories.

More Users Served on the Same Hardware

Because the model does less work per response, the same AI infrastructure handles more simultaneous conversations. KV cache offloading further helps by shifting idle sessions to secondary storage, freeing GPU capacity for active users and reducing the need to add hardware as demand grows.

Lower Operating Costs

Less repeated computation means lower energy use and lower cost per response. At scale, this allows organizations to pass savings on to end users or reinvest in capacity.

Support for Longer Conversations and Documents

NVIDIA's NVFP4 KV cache format stores the cache in a more compressed form, cutting memory use by up to 50% compared to the previous standard. This effectively doubles how much conversation history or document content the model can hold at once, thus enabling deeper reasoning over longer content without sacrificing accuracy.

Better User Experience

NVIDIA NVFP4 KV cache delivers up to 3x lower response latency compared to earlier formats, making AI applications feel consistently faster and more capable. 

Challenges and Solutions

KV cache comes with trade-offs that engineering teams need to manage. Here are the most common challenges and how they are addressed.

The Cache Takes up Space

GPU memory is limited and expensive. As conversations get longer or more users are served at once, the KV cache grows and can fill available memory, slowing down or blocking new requests.

Solutions

  • Compression: NVIDIA NVFP4 KV cache stores the same information in half the space compared to the previous standard, with less than 1% accuracy loss.

  • Overflow storage: NVIDIA Dynamo can move parts of the notepad to cheaper storage (such as system memory or an SSD) when GPU memory is full, then retrieve it when needed.

When the Cache Is Full, Older Entries Get Removed

If the model later needs that information again, it has to redo the original work, canceling out the speed benefit.

Solutions

  • Smart eviction: NVIDIA TensorRT-LLM lets teams decide which entries are most important to keep (for example, shared instructions used by all users). NVIDIA's internal data shows this approach improves the rate of reusing stored context by around 20%

Conversation History May Be Missing Across Servers

In large deployments running across many servers, a user's request may be sent to a server that does not have their conversation history stored. That server has to rebuild the cache from scratch, adding delay.

Solutions

  • Intelligent routing: NVIDIA Dynamo directs each request to the server most likely to already have the relevant history, avoiding unnecessary rebuild work.

FAQs

KV cache delivers real speed improvements by converting redundant recomputation into a fast memory lookup. The gains grow with how much context is shared or repeated across requests: Workloads with shared system prompts, repeated document content, or long conversation histories see the greatest benefit in both latency and cost per response.

For any organization running AI at scale, response speed and infrastructure cost are major operational factors. KV cache directly reduces how much computation is needed per response, which simultaneously lowers cost and improves the user experience. Organizations that manage KV cache well can serve more users on the same hardware, which is a meaningful advantage as AI workloads grow.

When the GPU memory used for the KV cache fills up, the system must either remove older stored context (requiring the model to redo that work if needed again), limit how long a conversation the model can handle, or add more hardware. NVIDIA Dynamo addresses this by automatically offloading less-active stored context to lower-cost memory and retrieving it when needed, without interrupting the AI's response. 

Retrieval-augmented generation (RAG) is a technique for finding relevant information, such as internal documents or database records, and feeding it to an AI model as context. KV cache is an efficiency technique that stores the AI's work on whatever context it has already received, so it doesn’t repeat that work. The two complement each other: RAG decides what information the model reads, and KV cache makes reading it faster and cheaper.

KV cache works with the transformer architecture used by the vast majority of today's large language models, including models used for text, code, and multimodal tasks. Some newer model architectures handle long sequences differently and don’t rely on a traditional KV cache, though they address the same underlying challenge of processing context efficiently.

Next Steps

NVIDIA TensorRT-LLM

NVIDIA TensorRT-LLM is a production-ready, open source library for running AI models efficiently on NVIDIA GPUs. It includes built-in KV cache optimizations: compressed storage formats (including NVFP4, which halves memory use), intelligent eviction policies that keep the most reusable context in memory, and early reuse techniques that allow shared instructions to be cached before all users need them.

NVIDIA Dynamo

NVIDIA Dynamo is an open source framework for serving AI across many GPUs and servers. At data-center scale, prefill and decode can happen on different GPUs specialized for each task—with compute-optimized GPUs accelerating prefill and memory-optimized GPUs focusing on decode.

NVIDIA CMX

NVIDIA CMX™ is built on the NVIDIA STX modular foundation for AI-native storage. It extends GPU memory with a shared, pod-level context tier optimized for ephemeral KV cache. The NVIDIA BlueField-4™ storage processor powers CMX by managing NVMe SSDs, running storage services, and offloading data integrity and encryption processing.

NVIDIA Full-Stack Co-Design

Get more useful AI work from every byte of memory.

See how NVIDIA full-stack co-design helps AI go further.

Learn how to get more performance from every byte as NVIDIA full-stack co-design solves AI’s memory challenge.