Semantic Caching for LLM Applications: Save Calls Without Wrong Answers
How semantic caching reuses answers for similar questions using embeddings, choosing similarity thresholds, scoping cache keys, invalidation and risks.
Published December 1, 2026
Users ask the same questions in different words: "how do I reset my password", "forgot password help", "can't log in, need reset". An exact-match cache misses all of these. A semantic cache embeds each question, finds previously answered questions that are similar enough, and returns the stored answer, saving an LLM call and returning instantly.
The concept
On each request, the question is embedded and compared against cached question embeddings. If the best match exceeds a similarity threshold, its answer is returned; otherwise the LLM is called and the new question-answer pair is stored. The cache key should also include anything that changes the correct answer: user role, plan, language, tenant, and the version of your prompt and knowledge base.
The danger is false hits. "How do I cancel my order?" and "How do I cancel my subscription?" may be very similar in embedding space but need different answers. Conservative thresholds, scoping by category, re-ranking the candidate match, and excluding personalised or time-sensitive questions keep the cache from serving wrong answers.
How it works
What to cache
| Cache this | Do not cache this |
|---|---|
| Generic FAQs, how-to questions | Account-specific answers ("my order status") |
| Static documentation answers | Time-sensitive data (prices, availability) |
| Classification of common inputs | Anything containing personal data |
| Expensive summaries of fixed documents | Creative tasks where variety is expected |
Choosing a threshold
Practical examples
Semantic cache with Redis vector search (sketch)
Scope by tenant and prompt version.
def cached_answer(question, tenant, version, threshold=0.93):
vec = embed(question)
hit = redis_vector_search(index="qa_cache", vector=vec, k=1,
filter=f"@tenant:{{{tenant}}} @version:{{{version}}}")
if hit and hit.score >= threshold:
return hit.answer
answer = llm_answer(question)
redis_store("qa_cache", vec, question=question, answer=answer, tenant=tenant, version=version, ttl=86400)
return answerExact cache first, semantic second
Cheapest check first.
key = sha256(normalise(question) + tenant + version)
if (a := redis.get(key)): return a
return cached_answer(question, tenant, version)Invalidate on content changes
Bump the knowledge-base version when docs are re-indexed.
KB_VERSION = os.environ.get("KB_VERSION", "2026-11-30") # new value → old entries no longer matchCommon mistakes
- Low thresholds that return answers to different questions.
- Caching personalised answers and leaking them to other users.
- No invalidation when documents or prompts change.
- Not measuring hit rate and false-hit rate separately.
Key takeaways
- Semantic caches match questions by meaning, not exact text.
- Scope keys by tenant, role, language and content version.
- Use conservative thresholds and avoid caching personal or time-sensitive answers.
- Monitor hit rate and audit samples for false hits.
FAQ
How much can it save?
It depends on how repetitive your traffic is; FAQ-heavy support bots benefit most.
Should cached answers expire?
Yes. TTLs plus version-based invalidation keep answers fresh.
Can I cache partial work instead?
Yes, caching retrieval results or embeddings is often safer and still saves time.