LLM Semantic Caching: Skip the Call, Not Just the Tokens
A semantic cache returns a stored answer when a new query means the same thing, so you skip the model call entirely, not just discount its tokens.
AI-drafted, reviewed by Muhammad Qasim Hammad on July 26, 2026. See our AI disclosure.
Table of contents
You turned on prompt caching, your input bill dropped, and you assumed you had solved repeated work. But prompt caching still runs the model on every call. If two users ask the same question in different words, you pay for the full generation twice. A semantic cache can skip that second call entirely.
What is an LLM semantic cache?#
An llm semantic cache is a vector store of past query-to-response pairs that you check before calling the model. You embed the incoming query, search for the nearest stored query, and if cosine similarity clears your threshold you return that stored response at 0 model cost and near-0 latency. Otherwise you call the model.
The word that matters is "semantic." A plain key-value cache only hits when the new request is byte-for-byte identical to an old one, so "reset my password" and "how do I reset my password" miss each other completely. A semantic cache compares the meaning of the two queries through their embeddings, so paraphrases land on the same entry. That is what lets it help real users, who almost never phrase the same intent the same way twice.
The mechanics are a 5-step loop: embed the query, search the vector store, compare the top match against a threshold, then either return the hit or call the model and store the new pair. Open-source tools like GPTCache implement exactly this loop, and Redis ships a semantic cache built on the same idea. You are not inventing anything here, just wiring known parts together.
How is semantic caching different from prompt caching?#
Prompt caching and semantic caching solve different halves of the problem, and they compose. Prompt caching discounts the repeated input prefix but still runs the model, so you always get a fresh generation. Semantic caching can skip the model call outright when a similar query already has an answer. One trims tokens; the other removes calls.
Both major providers document prompt caching as a discount on cached input tokens, not a way to avoid generation. Anthropic's prompt caching docs and OpenAI's prompt caching guide both describe reusing a static prefix (a long system prompt, a document, a tool schema) across calls. The model still reads your changing suffix and generates a new completion every time. That is the right tool when the answer must be fresh but the context is stable.
Semantic caching sits one layer earlier. It asks a blunter question: does this query even need the model? For a support bot answering the same 30 questions all day, the answer is often no. The clean move is to stack them: put a semantic cache in front to short-circuit repeats, and keep prompt caching on for the calls that do reach the model. If you are working through cost broadly, our guide to 7 levers to reduce AI API costs treats caching as one lever among several.
How do you build a semantic cache, step by step?#
You build it as a lookup that wraps your model call: pick an embedding model, store each query with its embedding and response, and on every new query embed and search before you generate. If the nearest neighbor clears the threshold, return the stored answer. If not, call the model, then write the new pair back.
The 5 steps below are the whole thing. Step 5 is the one people skip, and it is where a naive cache goes wrong: an untuned threshold either returns confidently wrong answers or never hits, and a cache with no invalidation will happily serve a price from 3 months ago. Treat tuning and expiry as part of the build, not a later chore.
- Pick an embedding model. Choose one embedding model and use it for both stored queries and incoming ones. Mixing models makes the vectors incomparable and your similarity scores meaningless.
- Store query, response, and embedding. On a miss, write the query text, the model's response, and the query's embedding into a vector store as one record.
- Embed and search on each new query. Embed the incoming query with the same model and run a nearest-neighbor search for the closest stored query.
- Return on a hit above the threshold. If the top match's cosine similarity is at or above your threshold, return its stored response and stop. No model call happens.
- Tune the threshold and set invalidation. Sweep the threshold on real traffic, and add a time-to-live or an explicit purge so stale answers expire.
When does a semantic cache actually pay off?#
A semantic cache pays off when queries repeat in meaning and the correct answer is stable over time. High-repeat, low-volatility workloads are the sweet spot: FAQs, product documentation, onboarding help, and support macros where thousands of users ask the same 20 or 30 things. There the hit rate is high and a stored answer stays correct for weeks.
It is the wrong tool for personalized or time-sensitive answers. A response that depends on the specific user, their account, the current time, or live data must not be shared across users through a cache, because a hit would hand one person another person's answer or a stale fact. The markdown table below and the checklist above draw the line: cache the stable and shared, never the personal or the fresh.
| Layer | What it saves | When to use |
|---|---|---|
| Prompt cache | Input tokens on a repeated prefix; model still runs | Long stable context, answer must be freshly generated |
| Semantic cache | The whole model call on a similar-enough query | High-repeat, stable, non-personalized answers |
The two failure modes both come from the threshold. Set it too low, say 0.75, and loosely related queries collide, so the cache returns a wrong stored answer with full confidence. Set it too high, near 0.99, and only near-identical strings hit, so you get almost no benefit. There is no universal number; a value around 0.85 is a common starting point you then tune against your own traffic and a labeled set of query pairs.
Where should you start?#
Start by measuring how repetitive your traffic really is, then cache only the stable, shared answers. Pull a week of production queries, cluster them by meaning, and count how many collapse into a handful of intents. If a large share does, a semantic cache will remove real calls; if every query is unique, it is overhead.
From there, wrap your model call with the 5-step loop, start the threshold around 0.85, and put a time-to-live on every entry. Keep prompt caching on underneath for the calls that still reach the model. If you are still choosing a provider for those calls, our breakdown of the cheapest AI API in 2026 pairs well with the call-avoidance a cache gives you.
Frequently asked questions
What is an LLM semantic cache?
How is semantic caching different from prompt caching?
What threshold should I use for a semantic cache?
When should I not use a semantic cache?
Which tools implement semantic caching?
Sources
Primary references and vendor documentation used while drafting and reviewing this article.
Written by
Muhammad Qasim Hammad is an AI agent and automation expert and the founder of Cart Gaze LLC (cartgaze.com). He builds product for the love of it: when an idea lands, a working prototype is usually running within hours, built with the same AI agents and automations he sells. He puts his own output at roughly 20× what it was before agents, and the Agentic OS behind this site is the working proof, documented in public with the tools he actually ran and what they really cost.
AI & Automation Services
Want a pipeline like this running in your business?
I'm Qasim — I design and ship AI agents and n8n automations for solo operators and small teams. Tell me what's eating your team's week, and I'll scope a fix.
Related reading
Prompt Caching: Cut Claude and Agent Costs Without Losing Quality
Prompt caching stores the unchanging part of your Claude prompt once and bills every later read at a tenth of the price, same model, same output. Here is the token math, the break-even point, and how to wire it into an n8n agent loop.
Cut Your AI API Bill: 7 Levers That Actually Work
To reduce AI API costs you need levers that change the bill by a verifiable mechanism, not vague advice. This hub names all seven, right-size the model, prompt caching, the Batch API, routing and fallback, local versus API, token discipline, and RAG over long-context, with a
Long-Context vs RAG: When a 200K-1M Token Window Beats Chunking
Now that 1M-token windows ship at flat pricing, should you stuff the whole corpus in one prompt or build a retrieval pipeline? This breaks long context vs RAG into reproducible per-query cost math, the recall limits of big windows, and four variables that decide it.


