What is semantic caching, how is it different from prompt/prefix caching, and what are its failure modes?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Semantic caching stores previous request→response pairs and serves the cached response when a new request is semantically similar: embed the incoming query, nearest-neighbour search over cached query embeddings, and if similarity clears a threshold (e.g., cosine ~0.95), return the stored answer without calling the model at all.
Full worked answer with diagram
Semantic caching stores previous request→response pairs and serves the cached response when a new request is semantically similar: embed the incoming query, nearest-neighbour search over cached query embeddings, and if similarity clears a threshold (e.g., cosine ~0.95), return the stored answer without calling the model at all.
The contrast with prompt/prefix caching is the key point interviewers want: prefix caching reuses computation (the KV cache of an exact, token-identical prefix) - the model still runs and generates a fresh output; it's lossless. Semantic caching reuses the answer on a fuzzy match and skips inference entirely; it's ~100% savings on a hit, but lossy - you're asserting two different strings deserve the same response.
Failure modes, roughly in order of pain:
- False hits: embeddings blur exactly what matters - negation ("refund policy" vs "no-refund policy"), numbers, entity swaps ("reset password for account A vs B"), and dates all embed nearby. A wrong cached answer served confidently is worse than a slow one.
- Context leakage: caching across users can leak personalised or permissioned content. Cache keys must be scoped - per-tenant at minimum, and personalisation-affecting state must be in the key.
- Staleness/invalidation: the cached answer embeds a moment in time - model version, system prompt version, RAG corpus snapshot. Any of those changing must flush or version-partition the cache; teams forget the prompt-version dimension constantly.
- Threshold tuning: too tight = no hits; too loose = wrong answers. Measure hit precision (are hits actually correct?) with sampled human/LLM-judge review, not just hit rate.
Where it shines: high-repetition, low-personalisation traffic - FAQ-style support, public search-ish queries - where 20-40%+ of traffic is near-duplicates. Where to avoid it: personalised, multi-turn, or high-stakes answers. A reasonable middle path: use a semantic hit as a candidate that a small verifier model confirms before serving.
Worth sketching. The threshold and the verifier are the two places this design goes wrong, so put them on the page where they can be argued about.
flowchart TD
Q["Incoming query"] --> E["Embed, nearest-neighbour search<br/>over cached query vectors"]
E -->|"similarity above threshold"| H["Candidate answer"]
E -->|"below threshold"| M["Call the model, store the pair"]
H --> V["Check tenant scope, prompt version,<br/>corpus version, optional verifier"]
V -->|"passes"| S["Serve cached answer, no inference at all"]
V -->|"fails"| M
What a good answer covers
- Semantic caching stores previous request→response pairs and serves the cached response when a new…
- Semantic caching reuses the answer on a fuzzy match and skips inference entirely; it's ~100% savings on…
- False hits: embeddings blur exactly what matters - negation ("refund policy" vs "no-refund policy"),…
- Context leakage: caching across users can leak personalised or permissioned content
- Staleness/invalidation: the cached answer embeds a moment in time - model version, system prompt…
Key terms: response · computation · answer · False hits · Context leakage · Staleness/invalidation · Threshold tuning · hit precision
In the glossary: Semantic caching · Prefix caching · KV cache · RAG
Interviewer follow-ups to expect
Design the cache key for a multi-tenant RAG product. How would you detect that your threshold is causing false hits in production?
- False hits: embeddings blur exactly what matters - negation ("refund policy" vs "no-refund policy"), numbers, entity swaps ("reset password for account A vs B"), and dates all embed nearby. A wrong cached answer served confidently is worse than a slow one.
- Context leakage: caching across users can leak personalised or permissioned content. Cache keys must be scoped - per-tenant at minimum, and personalisation-affecting state must be in the key.
- Staleness/invalidation: the cached answer embeds a moment in time - model version, system prompt version, RAG corpus snapshot. Any of those changing must flush or version-partition the cache; teams forget the prompt-version dimension constantly.
- Threshold tuning: too tight = no hits; too loose = wrong answers. Measure hit precision (are hits actually correct?) with sampled human/LLM-judge review, not just hit rate.
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep