Prompt Cache vs Semantic Cache vs KV Cache
Where each cache sits, what it matches on, what it saves and where it goes wrong, explained simply for your AI interview.
In short
A prompt cache is the model provider reusing saved work for an exact repeated start of your prompt. A semantic cache sits in your app and returns an old answer for a similar question. The KV (key and value) cache is the model's working memory inside one reply.
13 min readIntermediateCommon · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
Three caches, three places. The KV cache lives inside the model server and holds the working numbers for one reply. A prompt cache sits at the provider and reuses the same starting text, but only on an exact match. A semantic cache sits in my app or gateway and returns an old answer when a new question means the same thing. The first two save work without changing the answer. The semantic one skips the model, so a near match can be wrong, and that is the risk I would measure first.
All three save work by keeping something the first time and reusing it later. They differ in what they keep, where they keep it, and how they decide that something matches.
The KV cache lives inside the model server. It holds the key and value numbers the model works out for each token, a small piece of text, so each new word is cheap to make. Without prompt caching, it is thrown away when the reply ends. A prompt cache is a provider feature. If the start of my prompt is identical to a recent request, the provider reuses the saved work for that start. The match is exact, so fixed parts like tools, instructions and policy text go first, and the customer's details go last.
A semantic cache sits in my app. It stores a finished answer, and when a new question has a similar meaning, it returns the old answer without calling the model. That saves the most, but a near match can be wrong. So I set a strict threshold, key the cache by account type, and check a sample of hits by hand.
Interviewers want the place, the match rule and the risk for each one. The first two change speed and cost but not the answer. The semantic cache changes the answer itself, so it needs measuring.
What are these three caches, in plain words?
Each of the three saves work by keeping something the first time and reusing it later. What differs is what it keeps, where it keeps it, and how it decides that a new request matches.
Picture a hospital pharmacy. The standard ward order is prepared once and reused for every patient on the ward. The common questions from nurses, with their answers, sit on a board, so a nurse who asks something close to a board question gets that answer. The pharmacist's working notes on one prescription exist only while that check is open.
An AI app has the same three ideas. The prompt cache is the ward order, kept by the provider. The semantic cache is the board, kept by your app. The KV cache is the working notes, kept by the model server while it writes one reply.
Key words
- KV (key and value)
- Short for key and value. The model works out these numbers for each token and looks back at them for earlier words.
- Prompt prefix
- The start of a prompt, before the part that changes with each user.
- Token
- A small piece of text, roughly a word or part of one. Models read and bill by the token.
- Embedding
- A list of numbers that stands for the meaning of a piece of text.
- Similarity threshold
- How close two questions must be before an old answer is returned.
What is a prompt cache, and when does it hit?
A prompt cache is a feature of the model provider, such as Anthropic or OpenAI. The provider keeps the processed start of your prompt for a short time. A later request with the same start can reuse that saved work, so it is faster and cheaper on the input side.
Where each cache sits in one request
Customer question
a new message arrives
Semantic cache
in our app: similar question seen?
Stored answer
hit: this is the reply, no model call
Model provider
Prompt cache
same start of prompt seen?
KV cache
working memory for each reply
Reply
one answer to the customer
- 1A new question arrives at your app.
- 2A close enough old question returns its stored answer, and nothing else runs.
- 3No match, so the request goes on to the model provider.
- 4If the start of the prompt matches a saved one, its saved working notes are reused.
- 5The model writes the reply using its KV cache.
The match is exact, and strict. Anthropic's docs put it plainly:
“Cache hits require 100 percent identical prompt segments, including all text and images up to and including the block marked with cache control.”
Anthropic
So the order of the prompt matters. Anthropic's cache covers tools, the system prompt and messages, in that order, up to the marked block. OpenAI likewise says the whole rendered prefix has to match. Fixed material goes first, and the parts that change go last.
The cache also expires. By default it lives for five minutes, and each use refreshes it at no extra cost. A slow stream or a quiet hour can let it lapse.
Worked example. An insurance claims assistant sends a 30,000-token claims handbook with each of 4,000 customer questions a day. Without a cache, that is 120 million tokens of the same text. With a cache, the first request writes the handbook and later requests read it. A write costs 1.25 times the normal input price. On a model with the standard 0.1x read price, a read costs 0.1 times. If questions arrive often enough to keep the cache fresh, meaning each saved copy is reused before it expires, the handbook part costs about a tenth of its usual price: 1.25 plus 3,999 reads at 0.1 is about 401 units, against 4,000 without the cache. These are made-up numbers for illustration.
The reply itself is not made cheaper by the prompt cache. Anthropic is clear about that.
What is a KV cache, and how is it different?
Inside the model, each token gets a key and a value in every layer. The model uses them to look back at earlier words. A KV cache stores those pairs, so each new word does not redo the work for every earlier word. OpenAI and Hugging Face, the AI model library, both describe the same state:
“When the model processes input tokens, it must calculate intermediate states, known as key-value (KV) states.”
OpenAI
“A KV cache stores these calculations so they can be reused without recomputing them.”
Hugging Face
The same saved states can be reused between requests. vLLM, an open-source serving engine, keeps them as blocks and reuses a block when a new request starts the same way. It calls this prefix caching. The KV cache inside one reply is the model's own working memory. A prompt cache keeps that same kind of saved state across requests for a while. OpenAI says its prompt cache stores key-value (KV) tensors, not the tokens themselves, so a later request with the same start can skip the work.
Keeping them apart matters in a shared system. In vLLM, a cache salt (a label mixed into the lookup key) is added to the first block, so only requests with the same salt can reuse its blocks. Anthropic keeps caches apart by organisation, and on the Claude API also by workspace.
Tip
Don't mix it up with a key-value store like Redis, the database that keeps named values for an app. The KV cache is a set of numbers inside the model, and your app never reads it.
What is a semantic cache, and where does it go wrong?
- Prompt cache
At the model provider
Reuses an exact saved start of the prompt. Saves input work and time, not the reply.
- KV cache
Inside the model server
Working memory for one reply, so each new word is cheap to make.
- Semantic cache
In your app
Returns a stored answer for a similar question. It can skip the model entirely, and it can be wrong.
A semantic cache sits in your app or your API gateway. Each question and its final answer are stored with an embedding, the list of numbers that stands for the meaning of the text. A new question gets its own embedding. If it is close enough to a stored one, the old answer comes back and the model is never called.
Microsoft's example for Azure API Management uses a separate embeddings deployment, which is the model endpoint set up just for that lookup.
The threshold decides most of the result. AWS tested this on 63,796 real chatbot queries and their paraphrases. At a threshold of 0.75, its benchmark cut inference cost by up to 86% and kept 91% answer accuracy. At the loosest setting, 0.50, 94.3% of queries hit the cache, and the accuracy of those cached answers fell to 87.5%. Looser settings bring more hits and more wrong answers, so the threshold is a trade-off between cost and correctness. That was one setup, with Claude 3 Haiku answering the questions. Your numbers will differ, so measure them.
Tip
Start strict, then loosen only where your own sample of cached answers still holds up.
Scope matters too. Microsoft's example keys the cache by the subscription ID, the ID of the Azure subscription that owns the calls, so one subscription's cached answers never reach another. Your version should do the same with whatever separates your customers.
Worked example. A bank's support assistant gets a question about the fee for a late card payment. An hour later a customer asks about a late payment on a joint account. The meaning is close, but the fees differ by account type. A loose threshold returns the card answer to the joint-account customer, which is a complaint waiting to happen. The fix is a strict threshold plus an account-type key, so only customers with the same account type share an answer.
How would you cache answers for a claims assistant?
A claims assistant reads a long handbook, a set of tools, and one customer's claim on every call. Here is the order I would build the caches in.
- 1
Put the fixed parts first
Tool definitions, instructions and the handbook go at the top, unchanged. Anthropic advises placing static content there, because the cache needs an identical start.
- 2
Put the customer's details last
Name, claim number and dates come after the cached part, so they never break the match.
- 3
Use a semantic cache only for shared answers
Questions with one answer for everyone, such as opening hours, can use a semantic cache with a strict threshold.
- 4
Key the cache by customer
Claim answers must never cross customers. Add a key such as the policy holder's ID, so each answer stays with its owner.
- 5
Measure wrong hits every week
Sample cached answers, check them against the policy, and loosen the threshold only while the sample stays clean.
What does the interviewer want to hear?
A strong answer covers
- Three layers: the app, the provider and the model server.
- Prompt cache: exact match on the start of the prompt, saves input work and time.
- KV cache: the model's working numbers inside one reply.
- Semantic cache: a similar meaning returns an old answer, skipping the model, and can be wrong.
- The threshold, and how you measure wrong hits.
- Fixed content first, customer details last, and keys that keep customers apart.
Common traps
Trap"They are three names for one cache."
BetterThey sit in different places and match on different things.
Trap"A semantic cache is always cheaper and safe."
BetterIt skips the model, but a near match can give the wrong answer, so measure it.
Trap"The KV cache is a database, like Redis."
BetterIt is working memory inside the model for one reply, and your app never reads it.
Can you spot the cache problem?
Spot the cache problem
Your claims assistant builds its prompt the same way for every customer. Which line breaks the prompt cache on every call?
Quick check
A semantic cache returns the domestic fee for a question about an international transfer. What went wrong?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
Learn it in depth
Last updated on 27 November 2026
Building an assistant that repeats the same long context on every call?
I design and build AI products and agents, the screens and the system behind them. Book a short call and tell me how many calls you expect and how much of the text repeats.