A semantic cache embeds the incoming request, searches for a previously answered request with a similar meaning, and returns the stored answer when the similarity clears a threshold. Redis LangCache describes the mechanism plainly: if a semantically similar prompt has been answered, return the cached response without an LLM call.
The appeal is obvious for support bots and FAQ assistants. The risk is less obvious: a cache that is slightly too permissive returns a confident answer to a question the user did not ask. This guide covers when to use one, how to tune it and where it breaks.
| Option | Type | Threshold control | Deployment | Notable limit |
|---|---|---|---|---|
| Redis LangCache | Managed semantic cache | Configurable similarity threshold and TTL | Redis Cloud; preview | Preview status, so behaviour may change |
| Portkey cache | Gateway feature | Default 0.95 cosine; plan-gated | Hosted or self-hosted gateway | Semantic cache limited to short, few-message requests |
| GPTCache | Open-source library | Pluggable similarity evaluation | Self-hosted | You own the vector store and eviction |
| Custom pgvector cache | Build your own | Any threshold you implement | Self-hosted Postgres | You own embedding, indexing and evaluation |
How a semantic cache decides
The cache converts a request into a vector, searches a vector index for near neighbours, and compares the best match against a threshold. If the score is high enough, the stored response is returned. If not, the request goes to the model and the new answer is stored.
Every part of that chain is a choice. The embedding model determines what counts as similar. The index determines how quickly you can search. The threshold determines how often you accept a match. The TTL determines how long an answer stays eligible.
Portkey's documentation adds useful specifics: its semantic mode uses cosine similarity with a default threshold of 0.95, applies only to requests under 8,191 tokens and four or fewer messages, requires model and parameters to match, and ignores the system prompt when matching. Those limits describe a short, early-turn chat request, not an agent loop.
When it pays
The best workload is repetitive, short and tolerant of paraphrase. Customer support questions, product FAQs, internal policy lookups and onboarding chats fit. Users ask the same thing in different words, and a close match usually deserves the same answer.
The second condition is answer stability. A cache built on a price list, a policy document or a product catalogue goes stale when the source changes. If the answer changes hourly, the cache needs a short TTL or an invalidation hook, which reduces the hit rate.
The third condition is volume. A cache needs enough repeated traffic to justify the embedding call, the vector store and the evaluation work. At low volume, an exact-match cache or no cache is simpler.
- Short, repeated questions with stable answers.
- A corpus that changes on a known schedule.
- Enough volume to measure hit rate and false positives.
- A clear owner for invalidation.
When it fails
The first failure is a near-miss in a domain where wording carries meaning. How to fix Error A and how to fix Error B can look similar to an embedding model and require different answers. Medical, legal and technical support are full of these pairs.
The second failure is stale context. A cached answer does not know that the user's account changed, the policy was updated or the incident was resolved. A cache that ignores conversation state can answer a follow-up with the previous answer.
The third failure is cross-tenant leakage. If the cache key does not include the tenant, the model, the prompt version and the relevant permissions, one customer can receive another customer's answer. Namespaces are a security control, not a housekeeping convenience.
The fourth failure is prompt drift. Portkey's docs state that the system prompt is ignored for semantic matching. A team that changes the system prompt to add a safety instruction may still receive an old cached answer that was generated under the previous instruction.
Thresholds, TTLs and namespaces
Start with a strict threshold and lower it only against a labelled set of real queries. Build pairs that should match and pairs that look similar but should not. Measure false positives, because a wrong cache hit is worse than a miss.
Set TTL by content volatility, not by storage cost. A price answer may need minutes; a company policy answer may need days. If the source system can emit a change event, invalidate on the event rather than waiting for the TTL.
Namespace by tenant, model, prompt version and, where relevant, locale. A cache shared across models can return a cheaper model's answer to a request that expected the stronger one. A cache shared across prompt versions can defeat a safety change.
- Threshold tuned on real queries, not a demo.
- TTL matched to source volatility.
- Invalidation on source change where possible.
- Namespace per tenant, model and prompt version.
Deployment, keys and data
A semantic cache stores prompts and responses, which means it stores whatever personal or confidential data those contain. Treat the cache as a data store: encrypt it, restrict access, set retention and include it in the residency map.
The deployment options are an in-gateway cache, an application-side cache or a managed cache service. An in-gateway cache is easiest to enforce across teams but may have request-size limits. An application-side cache gives the product team control over keys and invalidation. A managed service shifts operations but adds a subprocessor.
Keys should be scoped per environment and per cache namespace. A cache admin key that can read every tenant's entries is a high-value target; it should not be the same key the application uses to write.
The cost math under flat plans
Semantic caching is usually sold as a token-cost reduction. If your model access is billed per token, the saving is real, minus the embedding and vector-store cost. If your access is a flat monthly plan, the token saving does not appear on the bill.
Under a flat plan, the case for caching is latency, throughput and upstream load. A cache hit can return in milliseconds and free capacity for requests that need the model. That is still valuable, but the business case should be written in response time and capacity, not in dollars per token.
The cost that remains is operational: embedding calls, vector storage, evaluation and the incident risk of a wrong answer. Those costs do not disappear when the model bill is flat.
When a competitor wins
An exact-match cache wins when requests are identical and the cost of a wrong answer is high. A gateway with a built-in cache wins when the team already routes through it and wants one policy surface. A managed cache wins when the team does not want to operate a vector store.
The honest competitor is no cache at all. If the workload has low repetition or the answer changes often, the cache adds a data store, an embedding dependency and a failure mode without a measurable benefit. Measure hit rate and false positives before adding the layer.
When an exact cache wins
An exact-match cache is deterministic, cheap and easy to explain. It works when requests are genuinely identical, such as a fixed report, a repeated system prompt or a scheduled job. It cannot handle paraphrase, but it also cannot return a plausible answer to a different question.
A useful pattern is two tiers: exact match first, semantic match second, model call last. Portkey describes semantic cache as a superset that checks exact match before running semantic search. That ordering reduces unnecessary embedding work and makes the cheap path the default.
Verdict
Use semantic caching when queries are short, repetitive and tolerant of paraphrase, and when you can measure false positives on real traffic. Avoid it for agent loops, multi-turn state, regulated advice and any workload where a near-miss is a wrong answer.
Tune the threshold against a labelled set, namespace by tenant and prompt version, and put the cache in the residency map. If you run on flat-rate API plans, justify the cache on latency and capacity rather than token savings.
Frequently asked questions
What is semantic caching?
A cache that embeds a request, finds a previously answered request with similar meaning and returns the stored response when the similarity clears a threshold.
What similarity threshold should I use?
There is no universal number. Start strict and lower it only against labelled pairs. Portkey documents a default of 0.95 for its semantic mode, but the right value depends on the domain.
Does semantic caching work for multi-turn chat?
Often poorly. Portkey's semantic mode is limited to requests under 8,191 tokens and four or fewer messages, which excludes most agent loops and long conversations.
Can a cache leak data between customers?
Yes, if the cache key does not include the tenant and permissions. Namespace every entry by tenant and enforce access at read time.
Does caching reduce cost on a flat-rate plan?
Not on the invoice. It can reduce latency and upstream load, which may still be valuable, but the token saving does not appear if you pay a fixed monthly price.
Related
Sources
- Redis LangCache documentation · 23 Nov 2026
- Portkey cache documentation · 23 Nov 2026
- GPTCache repository · 23 Nov 2026
- pgvector repository · 23 Nov 2026