Semantic caching: how it works, what it saves, where it fails

How semantic caching matches similar questions with embeddings, what it saves per customer after embedding costs, and how to avoid stale or leaked answers.

Brandon Holt
November 28, 2026
9
min read
Summarize
Semantic caching: how it works, what it saves, where it fails

Semantic caching stores an LLM's answer next to an embedding of the question, then returns that answer when a new question lands close enough in vector space, so the model never runs. A cache hit costs one embedding (OpenAI's text-embedding-3-small charges $0.02 per million tokens) and a vector lookup, against the full input and output price of a model call.

Prices checked on November 28, 2026, from OpenAI's pricing page.

It saves the most on support and docs questions that many users ask in slightly different words, and it carries risks that provider prompt caching doesn't. It sits next to prompt caching, batching and model choice in our guide to cutting LLM costs.

How semantic caching works

A semantic cache sits in front of your model call and runs two steps around it. Before the call, your app turns the user's question into an embedding (a list of numbers that places similar meanings near each other) and searches the cache for stored questions nearby. If the closest match clears your similarity threshold, your app returns the stored answer. If nothing clears it, your app calls the model as usual and stores the new question, embedding and answer for next time.

1. embed("How do I reset my password?")
2. search cache for nearest stored question
3. similarity above threshold?  yes: return stored answer (no model call)
                                no:  call model, store question + answer

The similarity threshold sets the trade between hit rate and wrong answers. RedisVL's SemanticCache guide measures cosine distance from 0 (identical) to 2 (opposite) and uses a distance_threshold of 0.1 in its example, where lower is stricter. Redis's managed LangCache API takes a similarityThreshold instead and uses 0.9 in its examples. RedisVL notes that the right value changes with the embedding model, the queries and the use case, so treat any default as a starting point.

Embeddings let "How do I reset my password?" and "I forgot my password, what now?" match, which an exact-match cache would miss. That same looseness lets two questions with different answers match too.

Semantic caching vs exact-match caching vs prompt caching

"LLM caching" covers three different things that sit at different points in the request. Exact-match and semantic caches live in your app and replay whole answers. Provider prompt caching lives at OpenAI or Anthropic and discounts the repeated start of a prompt while the model still writes a fresh answer.

Exact-match cacheSemantic cacheProvider prompt caching
What matchesIdentical request textSimilar meaning, above a thresholdIdentical prompt prefix
What you skip payingThe whole callThe whole call, minus an embeddingMost of the repeated input
Does the answer change?No, it replaysNo, it replays a neighbor's answerNo effect on output
Who runs itYou (Redis, a database, memory)You, or a service like Redis LangCacheOpenAI or Anthropic
Main riskStale answersStale and wrong-match answers, cross-customer leaksPaying for writes that never get read

Source: Redis LangCache and RedisVL docs; Anthropic's prompt caching docs, which say caching has no effect on output token generation.

Provider prompt caching is the safer first step for most products, because the model still writes each answer and Anthropic never shares caches across organizations. For how it prices writes and reads, see Claude prompt caching. A semantic cache saves output tokens too, which prompt caching never touches, and that's where its extra savings come from.

What semantic caching costs and saves

A hit saves the full cost of the call it replaces. Every lookup, hit or miss, costs one embedding, and the vector store adds a fixed hosting bill. The per-customer arithmetic fits in one line:

monthly saving = (questions x hit rate x cost per call)
                 - (questions x embedding cost per lookup)
                 - (that customer's share of vector store hosting)

Example: a help assistant on a $49 plan

Example. A SaaS product on a $49 plan includes a help assistant on GPT-6.2 Sol. Each answer sends 3,000 input tokens (instructions plus retrieved help articles) and writes 400 output tokens. That costs $0.006 of input and $0.004 of output, or $0.010 per answer. Embedding a 50-token question with text-embedding-3-small costs $0.000001.

Northwind's end users ask 4,000 questions a month, mostly the same how-to questions. Birchline's users also ask 4,000, but about their own data, so few questions repeat.

Customer, per monthHit rateModel callsEmbeddingsAI costSaved
Northwind, no cache0%4,000$0.000$40.00$0.00
Northwind, semantic cache40%2,400$0.004$24.00$16.00
Birchline, no cache0%4,000$0.000$40.00$0.00
Birchline, semantic cache5%3,800$0.004$38.00$2.00

Example data. GPT-6.2 Sol at $2 input and $10 output per million tokens, text-embedding-3-small at $0.02; hit rates are assumptions; vector store hosting left out. AI cost rounds to the cent.

The embedding line costs less than a cent per customer, so the hit rate decides whether the cache earns its keep. Northwind's AI cost falls from 82% of the plan price to 49%. Birchline saves $2, which a share of the vector store bill and one wrong answer can wipe out.

Turn on provider prompt caching first and the numbers shrink. If 2,500 of those input tokens are a shared prefix read from OpenAI's cache at $0.10 per million, each answer costs about $0.0053, and Northwind's 40% hit rate saves about $8.40 instead of $16 (ignoring cache writes). Most of what's left is output, which only a semantic cache or a cheaper model removes. For the model side, see Claude Haiku vs Sonnet.

When semantic caching pays off

  • Use it for FAQ-style support, docs search and onboarding questions, where many users ask the same thing and the answer is the same for all of them.
  • Skip it for answers that depend on the user's own data, agent runs that call tools, anything time-sensitive, and features where a slightly wrong answer costs more than the model call (billing, legal, medical).

The risks: stale answers, wrong matches and leaks between customers

A semantic cache replays an answer someone else got, sometimes weeks earlier. Three failures follow from that, and each has a specific fix.

Stale answers

When you change a price, a policy or a help article, cached answers keep the old version until they expire. RedisVL supports a TTL on entries, but its check() refreshes the TTL on every hit by default, so a popular stale answer can outlive any TTL you set. Pass refresh_ttl_on_hit=False if you want a hard expiry, and delete entries when their source changes. LangCache can delete entries by attribute, so tagging each entry with its source article lets you clear only those.

Wrong-match answers

"How do I delete a project?" and "How do I delete my account?" share most of their words and can sit close together in embedding space. A loose threshold serves the project answer to someone trying to close their account. Build a test set of question pairs from your own logs, label which pairs should share an answer, and tune the threshold until the wrong matches stop. Then sample live hits each week.

Leaks between customers

A single cache shared by every tenant can return Northwind's answer, built from Northwind's data, to a user at Birchline. OWASP's LLM02:2025 Sensitive Information Disclosure describes this failure: a user receives another user's personal data. Scope every lookup by tenant (RedisVL's filterable_fields, LangCache's attributes), and only share entries across tenants when the answer comes from public content. Provider prompt caching avoids this class of bug, since the model writes each answer fresh and Anthropic never shares caches across organizations.

Tools that offer semantic caching

You can build a semantic cache on any vector database, and three tools package the pattern:

ToolWhat it isThreshold settingTenant scoping
Redis LangCacheSemantic caching service with a REST API and Python and JavaScript SDKs; generates embeddings for you; in previewsimilarityThreshold (0.9 in examples)attributes on store and search
RedisVL SemanticCacheOpen-source Python library on your own Redisdistance_threshold, cosine distance 0 to 2filterable_fields plus a filter_expression
GPTCacheOpen-source Python library from Zilliz with pluggable embeddings, storage and vector storessimilarity_threshold in ConfigNot documented in the README

Source: Redis LangCache, RedisVL and GPTCache docs, checked November 28, 2026.

LangCache also supports an exact search strategy alongside semantic search, so one call can try an exact match first. GPTCache's README says the maintainers no longer add support for new APIs or models, which matters if you plan to stay on it for years. Redis's docs estimate LangCache savings as output token cost times hit rate, treating the input savings as offset by embedding and storage costs.

How to measure semantic caching savings per customer

A cache hit leaves no trace on your provider bill, so you have to log it yourself. Record four fields on every lookup:

  • Customer and feature, the same IDs you use for billing.
  • Hit or miss, plus the similarity score.
  • Avoided cost on a hit, taken from the token counts you stored with the original answer.
  • Embedding cost, from the question's token count.

Saving per customer is the sum of avoided cost minus embedding cost, compared against that customer's remaining model spend. Track hit rate per customer and per feature, and compare the thumbs-down rate on cached answers with fresh ones. A hit rate that climbs while ratings fall means the threshold is too loose for your current traffic.

Lancelot sees the other half: each customer's model cost against what they pay, after the cache has done its work, and it flags large prompts sent without provider caching. For customers still costing more than they pay, it acts within limits you set, such as a throttle, a cheaper model you approved or a hold at the plan's normal daily spend, and every action starts as a suggestion you can undo (Margin intelligence).

Questions about semantic caching

What is semantic caching for LLMs?

Semantic caching stores past LLM answers with an embedding of each question and returns a stored answer when a new question is similar enough. It skips the model call on a hit, so you pay for one embedding and a vector search instead of input and output tokens.

What is the difference between semantic caching and prompt caching?

Semantic caching replays a whole stored answer for a similar question, and you run it. Prompt caching is a provider discount on a repeated prompt prefix, and the model still writes a fresh answer. Anthropic says prompt caching has no effect on output.

What similarity threshold should I use for a semantic cache?

Start strict and loosen with evidence. RedisVL's example uses a cosine distance threshold of 0.1, and Redis LangCache's examples use a similarity threshold of 0.9. Tune it on labeled question pairs from your own logs, since the right value depends on the embedding model.

How much does semantic caching save?

It saves roughly your hit rate times the cost of a call, minus embedding cost. In the example, a 40% hit rate cut one customer's monthly AI cost from $40 to $24, while a customer with a 5% hit rate saved $2.

Is semantic caching safe for multi-tenant apps?

Only with tenant scoping. A shared cache can return one customer's answer, built from their data, to another customer. Filter every lookup by tenant ID, using attributes in Redis LangCache or filterable fields in RedisVL, and share entries only for answers drawn from public content.

How do I cache LLM responses?

Start with an exact-match cache keyed on the normalized request, which never serves a wrong neighbor. Add a semantic cache when logs show many paraphrased repeats, scope it by tenant, set a TTL, and turn on provider prompt caching for the calls that still reach the model.

Semantic caching is one of several levers on the same bill, next to prompt caching, batching and routing to smaller models. Our guide to cutting LLM costs covers how to combine them for products that resell AI.

Keep reading

All dispatches →
Are AI companies profitable? What the reported margins show
AI unit economics
/
9
min read

Are AI companies profitable? What the reported margins show

Input vs output tokens: what each costs and why output is 5x
Running AI in production
/
9
min read

Input vs output tokens: what each costs and why output is 5x

Semantic caching: how it works, what it saves, where it fails
Running AI in production
/
9
min read

Semantic caching: how it works, what it saves, where it fails

OpenAI Batch API and Anthropic batches: pricing and limits
Running AI in production
/
9
min read

OpenAI Batch API and Anthropic batches: pricing and limits

Get the numbers when they change.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
New dispatches and model price changes. Unsubscribe anytime.