Semantic caching lets an LLM application reuse a previous answer when a new request can safely use the same response. The application compares the meaning of the requests, so differently worded questions about the same return policy can share an answer.
Use the similarity score to find a candidate. Before serving it, check the details that can change the answer, such as the region, document version, and permissions.
How an LLM semantic cache works
A semantic cache stores a representation of a prior request alongside a reusable response and its eligibility rules. For a new request, the application generates an embedding and searches for similar entries within the permitted scope. If an eligible answer passes the threshold and freshness checks, return it. Otherwise, run the normal retrieval or generation path. The vector search guide explains how the matching step differs from keyword search.
A vector store such as Redis can hold and search candidate embeddings. The application still decides whether the candidate is safe to reuse. Start with public, stable FAQ answers and store only responses that meet your quality rules.
Semantic caching vs. prompt caching
An exact-match response cache can reuse an answer when its request key matches. A semantic response cache can reuse it across paraphrases, subject to the same eligibility rules. Provider prompt caching speeds up processing of repeated input prefixes. The model still generates a response to the current request.
These approaches can work together. You might check an exact-match cache first, use semantic lookup for approved public questions, and rely on provider prompt caching when you still need a new answer.
How to tune the similarity threshold
Build a test set of requests that should share answers and requests that should stay separate. For example, “How long can I return a jacket?” and “What is the return window for a jacket?” may share a response. An outlet order and a regular order may need different answers. Keep shipping region, order type, and policy version as explicit filters when they change the outcome.
Try several cutoffs against the same labeled examples. Some systems report similarity, where higher scores mean closer matches. Others report distance, where lower values are closer. Re-evaluate the cutoff when you change the embedding model, data, or similarity metric.
How to keep cached answers correct
Keep the source version with each cached answer. Expire entries after a defined interval, and invalidate affected answers promptly when the source policy or access rules change. Verify authorization before serving an entry. For personalized queries, use the normal path unless the cache has the appropriate isolation and permission checks. See the agent caching guide for cache keys, expiration and invalidation.
How to measure whether caching helps
Track accepted hits, misses, and incorrect hits separately. Compare p95 latency and total cost per correct response against the uncached path. In an example test, 28 of 100 requests passed the cache gate and reviewers found two wrong reuses. The hit rate was 28%, and the incorrect reuse rate among hits was about 7%. Report both so a rising hit rate does not hide more wrong answers.
Frequently asked questions
Can semantic caching work with RAG?
Yes. A valid hit can skip retrieval and generation. Include document versions or another freshness check, and fall back to retrieval when a cached answer is no longer supported.
What is a good semantic similarity threshold?
It depends on the embedding model, score convention, and workload. Tune it on labeled examples from your own application, including cases where wording is close but the correct answer differs.
Can a semantic cache retain private information?
It can retain anything your application stores. Start with approved public answers and keep personalized responses out of a shared cache. Apply access checks and retention limits to both requests and responses.
Does semantic caching always cut costs?
Caching adds lookup, embedding and storage costs. Compare total cost per correct answer and end-to-end latency over a representative set of requests.

