Introducing Duet Autopilot.
Learn more
Glossary

Semantic caching

Semantic caching is a technique for storing past LLM responses keyed by the meaning of a query rather than its exact wording. When a new query arrives, the system computes an embedding for it and searches a cache of previously answered queries for anything above a similarity threshold. If a close enough match exists, the system returns the stored response. If nothing matches, the query falls through to the model, and the new pair is added to the cache for next time.

The mechanism is the same vector similarity used in retrieval, applied to a response cache instead of a document corpus. What makes it worth building is redundancy in real traffic: LLM calls are the most expensive and slowest part of most production pipelines, and a large share of real-world queries are near-duplicates of something already asked.

Customer support is the clearest example. Thousands of users ask some version of where is my order or how do I reset my password every day, phrased differently each time. Semantic caching turns that redundancy into savings on both cost and latency, which is why it shows up as a standard layer in production LLM stacks rather than a niche optimization.

How semantic caching works

The flow has three steps. On the first occurrence of a query, the system computes its embedding, sends the query to the model, and stores the embedding-response pair. On every subsequent query, it computes a new embedding and searches the cache for prior embeddings within a configured distance.

A common threshold is cosine similarity above roughly 0.92, though the right number depends heavily on the domain and needs tuning against real traffic. A match returns the stored response without touching the model at all. No match means a normal model call, followed by a cache write so the next similar query gets served instantly.

The similarity threshold is the whole game. Set it too high and the cache almost never fires, because slight rewordings fail to clear the bar. Set it too low and unrelated queries start returning each other's answers, which is worse than no caching at all because it looks correct while being wrong. Threshold tuning is not a one-time setting; it needs production query logs and ongoing monitoring as the query distribution shifts.

Semantic caching versus other caching strategies

Exact-match caching. This hashes the full prompt text and returns a cached result only when the hash matches exactly. It has zero false positives but a very low hit rate, since two phrasings of the same request hash to completely different values despite meaning the same thing.

Semantic caching. Matching by meaning instead of text raises the hit rate substantially, at the cost of needing a well-tuned similarity threshold to avoid false positives.

Prompt caching. This solves a different problem. It is a provider-side feature that caches the processed prefix of a prompt — a system prompt, tool definitions, a long retrieved document — so shared prefixes across requests do not get reprocessed from scratch. A prompt-cache hit still triggers a full model call and a fresh response; a semantic-cache hit skips the model call altogether.

Where semantic caching earns its keep, and where it doesn't

The best fit is high-volume, low-variance, user-agnostic query traffic: public policy questions, frequently asked how-to queries, and any content that does not depend on a specific customer's account state. In those conditions, cache-hit rates in production customer-support workloads commonly land between 15% and 50%, translating directly into proportional savings on inference cost and response latency.

The failure modes cluster around three things. Personalized queries are the biggest trap: a question like what's my account balance is semantically identical for every user but must never be served from a shared cache.

Staleness is the second failure mode, since a policy change, a price update, or a product launch can silently invalidate cached answers unless there is a mechanism to expire or refresh them.

Multi-turn conversations are the third. The meaning of a message depends on what came before it, so caching on the last message alone produces answers that ignore context. A workable system keys the cache on conversation state, not a single isolated turn, and pairs it with per-user scoping wherever personalization is possible.

Semantic caching inside a larger retrieval stack

Semantic caching pairs naturally with a RAG pipeline. Production stacks often cache at two layers: retrieval results, keyed by query embedding, so the same chunks are not re-fetched for near-duplicate questions, and generation results, keyed by a signature of the query plus the retrieved context, so the final answer can be served without a model call at all.

Using both layers captures savings even when a query is new but the retrieved context is unchanged. Cache quality also needs the same scrutiny as any other production component. Sampled human review or automated LLM-as-a-judge evaluation on cache hits catches drift before a bad threshold quietly degrades answer quality across thousands of conversations.

Where semantic caching fits in an AI stack

Semantic caching is not a standalone product; it is a layer that typically sits behind an AI gateway alongside cost tracking, rate limiting, and provider failover, so every request in a system passes through the same cost-control checkpoint regardless of which model ultimately serves it.

In a customer-support agent handling tens of thousands of conversations a day, the combination of a well-tuned semantic cache and careful invalidation rules is often the single largest lever for controlling inference spend without touching model quality. That is why it is one of the first optimizations a production support AI deployment adopts once volume gets large enough to matter.

Deliver the concierge experiences your customers deserve

Get a demo