# 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.

AI and LLM interview question Q326, Inference, performance and cost. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/prompt-cache-vs-semantic-cache-vs-kv-cache

## Say it in 30 seconds

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.

## Say it in 2 minutes

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.

- **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.

*Diagram, Where each cache sits in one request: One request through the three layers. A semantic hit returns the stored answer and never calls the model. The prompt cache reuses a saved start across requests, and the KV cache works inside every reply the model writes.*
1. A new question arrives at your app.
2. A close enough old question returns its stored answer, and nothing else runs.
3. No match, so the request goes on to the model provider.
4. If the start of the prompt matches a saved one, its saved working notes are reused.
5. The 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." Better: They sit in different places and match on different things.
- Trap: "A semantic cache is always cheaper and safe." Better: It skips the model, but a near match can give the wrong answer, so measure it.
- Trap: "The KV cache is a database, like Redis." Better: It 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?

A. Tool definitions and the claims handbook, unchanged, at the top of the prompt
B. The policy holder's name and the claim date inserted at the top of the system prompt
C. A short instruction to answer in plain English
D. The handbook text, unchanged, placed after the tool definitions

**Answer:** B. A name or date at the top changes the start of every prompt, so no saved start matches. Put the changing details after the cached part.

**Quick check:** A semantic cache returns the domestic fee for a question about an international transfer. What went wrong?

A. The model was too small
B. The similarity threshold was loose, so two different questions counted as the same
C. The prompt cache expired
D. The KV cache ran out of memory

**Answer:** B. A semantic cache matches on meaning. A loose threshold lets a near match through, and that returns a wrong answer. The prompt cache and the KV cache do not make that decision.

## Can you answer these from memory?

**Flash cards**

- **Prompt cache, in one line?** The provider reuses saved work for an exact repeated start of your prompt.
- **Semantic cache, in one line?** Your app returns a stored answer for a question that is close in meaning.
- **KV cache, in one line?** The model's working numbers for each token, kept while it writes one reply.
- **What makes a prompt cache hit?** The same prefix, identical up to the marked cache point, and used within its 5-minute lifetime.
- **Biggest risk of a semantic cache?** A near match with a different answer. Set the threshold strict and measure wrong hits.
- **Where does the prompt cache live?** At the model provider, not in your app.

## Likely follow-up questions

- Q055 What is the KV cache, and why does it speed up generation? https://designervenkat.online/interview/ai/what-is-the-kv-cache
- Q088 What is prompt caching, and how does it save money? https://designervenkat.online/interview/ai/what-is-prompt-caching
- Q325 What is semantic caching? https://designervenkat.online/interview/ai/what-is-semantic-caching
- Q324 How do you estimate token cost for a feature? https://designervenkat.online/interview/ai/how-to-estimate-token-cost
- Q145 How do you cache RAG results? https://designervenkat.online/interview/ai/how-do-you-cache-rag-results

## Learn it in depth

- [Prompt Caching](https://designervenkat.online/learn/ai-engineering/prompt-caching)
