Semantic Caching
A caching layer that matches incoming prompts by embedding similarity rather than exact string equality, returning cached LLM responses for semantically equivalent queries
Table of Contents
Structure Diagram
What is Semantic Caching?
A caching layer that matches incoming prompts by embedding similarity rather than exact string equality, returning cached LLM responses for semantically equivalent queries. It is a core concept in Retrieval & RAG within AI / ML.
Core Principles
Traditional exact-match caches miss whenever two users phrase the same question differently (e.g., "How long is the refund window?" vs. "When can I get a refund?").
Semantic Caching stores prior prompt embeddings alongside their LLM responses in a fast vector store (such as Redis). When a new query exceeds a strict cosine similarity threshold (e.g., ≥ 0.94), the cached answer is returned in milliseconds without invoking the LLM.
Practical Takeaways
- Guard against false-positive hits: Queries like "iPhone 15 price" and "iPhone 16 price" have very high embedding similarity but different answers. Use high thresholds (
0.93–0.97) plus entity/number verification or a fast reranker check. - Isolate personalized and ACL-scoped queries: Never serve private user data from a global semantic cache. Scope keys by tenant/permission level or restrict semantic caching to public FAQs.
- Tie cache invalidation to document updates: Pair short TTLs with version tags so policy updates immediately purge stale cached answers.
Notable Examples
- Customer Support FAQ Bots: Resolve 40–60% of recurring shipping and billing questions in ~30ms with zero LLM cost.
- RedisVL & GPTCache: Popular drop-in semantic caching layers deployed inside LLM gateways.
- Documentation Assistants: Absorb traffic spikes when many developers ask variations of the same setup question.