What Is Semantic Caching for LLMs? (2026)
Semantic caching serves a stored answer when a new question means the same thing as an old one - not just when the text matches exactly. Here is how it works, why it cuts cost and latency, the failure mode that bites teams, and where LLM gateways fit.
Published:
Users ask the same handful of questions in a hundred different phrasings. “What is your refund policy?”, “How do I get my money back?”, “can i return this” - one intent, three strings. An exact-match cache treats all three as different, so all three hit the model and you pay for all three. Semantic caching fixes that by keying on meaning instead of text - and on the right workload it turns a large slice of your traffic from a paid, slow model call into a free, instant lookup.
The short definition
Semantic caching stores past LLM responses and serves one when a new query means the same thing as a stored query, even if the wording differs. Instead of comparing input strings, it compares meaning - and that one change is what lets a cache actually help on natural language, where the same question is almost never typed the same way twice.
How it works
Under the hood it is a similarity search over past queries:
- Embed the query. Turn the incoming query into an embedding - a vector that captures its meaning.
- Search the cache. Compare that vector against the vectors of previously seen queries, usually by cosine similarity in a vector store.
- Check the threshold. If the closest match scores above a similarity threshold you set, return its cached answer. If nothing clears the bar, call the model, then store the new query, its embedding and the response for next time.
The whole trick lives in step 3. Two queries that mean the same thing land close together in vector space, so “how do refunds work” retrieves the answer originally generated for “what is your refund policy.” A served hit skips the model entirely - no output tokens billed, and a response in milliseconds instead of seconds.
Semantic vs. exact-match caching
| Exact-match cache | Semantic cache | |
|---|---|---|
| Key | Literal input string | Meaning (embedding) |
| Hit on rephrasing | No | Yes |
| Extra cost per query | None | One embedding + vector lookup |
| Main risk | Almost none | False hit on “similar” but different queries |
| Tuning needed | None | Similarity threshold |
Exact-match caching is safe and nearly free but rarely hits on conversational input, because users almost never repeat themselves verbatim. Semantic caching hits far more often, at the cost of an embedding call per query and one new problem exact-match never has - deciding how similar is similar enough.
Why it matters - cost and latency
Two wins, both real on the right traffic:
- Cost. A cache hit skips generation, so you pay zero output tokens for it. On support bots, FAQs and internal assistants where the same questions recur constantly, hit rates can be high enough to move the bill meaningfully. It pairs naturally with the other techniques in how to reduce LLM costs.
- Latency. A vector lookup returns in milliseconds; a model generation takes seconds. For repeat questions, semantic caching is the difference between an instant answer and a spinner.
The savings scale with how repetitive your traffic is - high-repeat workloads benefit enormously, one-off creative generation barely at all.
The failure mode that bites teams
The thing that makes semantic caching powerful is also its risk - it serves an answer for a query it decided was close enough, and “close enough” is a threshold you guessed. Set it too loose and you get false cache hits, where two queries look similar in embedding space but genuinely need different answers, so the user gets a stale or wrong response. Set it too tight and you barely beat exact-match. Tuning that threshold against real traffic is the actual work of running a semantic cache.
Two hard rules follow:
- Never semantically cache personalized, per-user or time-sensitive answers. “What is my account balance?” from two users is semantically near-identical and must never share a cached response. Semantic caching suits stable, general knowledge, not live or user-specific data.
- Watch it in production. Because a bad hit is silent - the user just gets a subtly wrong answer - you need observability on cache hits and the answers they served, not blind trust in the hit rate.
Where the tools fit
Semantic caching usually lives in an LLM gateway that sits in front of your model calls. Portkey is an open-source gateway that routes to 1,600-plus models and includes caching, fallbacks, budgets and guardrails. The gateway self-hosts free under Apache 2.0, but the honest caveat is that real logging, traces and analytics - the part you need to actually watch cache behavior - require its managed paid tier. Its billing caps logs rather than requests, so requests keep flowing past the cap while logs stop recording.
Helicone also offers caching as an open-source proxy, but the honest note matters more than the feature - it was acquired by Mintlify in March 2026 and placed in maintenance mode, shipping only security and bug fixes with no roadmap, so it is not a safe pick for new buyers. New teams evaluating a gateway should weigh that against an actively developed option.
Common mistakes
- Caching per-user or live data. Similar-looking queries from different users or different moments must not share an answer.
- Leaving the threshold at a default. Too loose serves wrong answers, too tight kills the hit rate - tune it on real traffic.
- No observability on hits. A false hit is silent, so you need to see which queries got cached answers.
- Expecting savings on creative workloads. Low-repeat, generative traffic gives few hits - the win is on repetitive questions.
The bottom line
Semantic caching serves a stored answer when a new question means the same thing as an old one, cutting cost and latency on repetitive traffic - as long as you tune the similarity threshold and never cache per-user or time-sensitive data. It runs in an LLM gateway like Portkey, and its silent failure mode makes LLM observability on cache hits essential rather than optional.
Frequently Asked Questions
What is semantic caching?
Semantic caching stores past LLM responses and serves one when a new request means the same thing as a stored one, even if the wording is different. It works by embedding each query into a vector and comparing it to cached queries by similarity - if the closest match is above a threshold, the cached answer is returned instead of calling the model. This is different from exact-match caching, which only reuses a response when the input string is identical character for character.
How is semantic caching different from exact-match caching?
Exact-match caching keys on the literal input, so "What is your refund policy?" and "How do refunds work?" are two different keys and both hit the model. Semantic caching keys on meaning - it embeds both queries and sees they are close in vector space, so the second one can be served from cache. Semantic caching gets far more cache hits on natural language, but it introduces a tuning problem exact-match does not have - deciding how similar is similar enough.
Does semantic caching save money?
Yes, when hit rates are meaningful. A served cache hit skips the model call entirely, so you pay nothing for output tokens and return the answer in milliseconds instead of seconds. On workloads with many rephrasings of the same questions - support bots, FAQs, internal assistants - the savings on both cost and latency can be large. The cost you add is the embedding call plus a vector lookup per query, which is far cheaper than a full generation but not free.
What is the risk of semantic caching?
The main risk is a false cache hit - two queries look similar in embedding space but actually need different answers, so the user gets a stale or wrong response. Set the similarity threshold too loose and this happens often; too tight and you get almost no hits. It is also unsafe for anything personalized, time-sensitive or user-specific, where a "similar" question from a different user should not reuse the same answer. Semantic caching suits stable, general knowledge, not live or per-user data.
Explore More
Tool Reviews
Related Articles
- The Best LLM Monitoring Tools in 2026, Ranked for Production Cost and Reliability
- The Best LLM Observability for OpenAI Apps in 2026, by Use Case
- How to Reduce LLM Costs in 2026 - 6 Levers That Actually Move the Bill
- 3 OpenRouter Alternatives for Teams That Outgrew the Hosted Router (2026)
- 4 Portkey Alternatives When You Actually Wanted Observability (2026)
Free Newsletter
Get the LLM Evals Newsletter
Platform comparisons, pricing changes and eval technique deep-dives. No spam.
Related Articles
OWASP Top 10 for LLM Applications Explained (2026)
A plain-English walkthrough of all ten OWASP Top 10 risks for LLM applications - what each one actually means, a concrete example, and how eval, red-teaming and guardrail tools help you catch or mitigate it.
July 28, 2026
glossaryWhat Is a Golden Dataset for LLM Evaluation? (2026)
A golden dataset is your human-verified source of truth - the labeled test cases every eval and regression check scores against. Here is what makes a dataset "golden," how to build and size one, how to keep it from rotting, and where tools fit.
July 28, 2026
Portkey Review