Skip to content
Ali Hassan, home

Blog7 min read

Semantic caching for LLM apps: when it saves money

Semantic caching serves a stored answer when a new question means the same as an old one. See how it works, what it risks, and when it cuts your bill.

By Ali Hassan, Senior engineer for SaaS and AI products

Semantic caching stores the answer the first time a question is asked, then serves it again when a later question means the same thing in different words. For FAQ-style traffic that repeats itself, semantic caching can cut the model calls you pay for. It also carries real risks: a near-match that is not the same question, one user's data shown to another, and stale answers that outlive the facts. Here is how it works, where it fits, and where it bites.

What is semantic caching?

Semantic caching reuses an LLM response for a new query that means the same as one you have answered before, not only one that is spelled the same. The incoming question becomes an embedding, it is matched against stored questions by nearest-neighbour search, and if a close match exists, the saved answer is returned without calling the model. Redis describes it as reusing responses for queries that are semantically similar, not just byte-identical.

Repeats are common, and each one is pure cost. Redis puts the price of running the full embed, retrieve and generate pipeline on every repeat at 10x to 100x a plain cache lookup. A semantic cache sits in front of the model and tries to answer before the model runs at all.

How is it different from exact-match and prompt caching?

Three things get called caching, and they do different jobs. An exact-match cache keys on the literal text, so it hits only when a query is spelled the same and misses a reworded version of the same question. Provider prompt caching discounts a repeated prompt prefix but still runs the model from start to finish. A semantic cache matches by meaning and skips the model on a hit.

Cache typeMatches onDoes the model still run?Best for
Exact-match cacheIdentical textYes, on any new textRepeated identical calls
Prompt cachingA shared prefixYes, on every callLong, stable system prompts
Semantic cacheMeaning, by embeddingNo, on a hitParaphrased questions

The gap shows up in the bill. A reused prefix under prompt caching can drop to about 5% of the input rate, which is a real saving, but you still pay the model to write 100% of your answers. A semantic cache hit pays the model nothing at all.

How does a semantic cache work?

  • Embed the incoming query into a vector.
  • Search the stored question vectors for the nearest neighbour, by cosine or L2 distance.
  • Apply a distance cut-off: close enough, serve the cached answer; too far, call the model and store the new question and answer.
  • Filter the search by metadata, such as tenant, locale or model version, so a hit can only come from the right scope.
  • Give each entry a time-to-live so stale answers age out on their own.

The parts are off the shelf. RedisVL ships a SemanticCache with a default distance cut-off of 0.1. If you already run Postgres, pgvector gives you the same cosine, L2 and inner-product distance and an HNSW index to search it, so the cache is one more table rather than a new service.

What are the risks of semantic caching?

The core danger is serving a confident answer to a question the cache only resembled. A cache that saves money on 30% of calls is worthless if it is wrong on 1% of them and nobody notices. Three failure modes cause that, and all of them are quiet.

  • A wrong answer on a near-miss. "What is your refund policy?" and "Can I get a refund on a used item?" sit close in a vector space but want different answers. Set the cut-off too loose and far-apart questions start matching; too tight and almost nothing hits.
  • Data leaking across users. An answer built from one tenant's data must never match another tenant's query. Scope every lookup by tenant and locale inside the search, not in code that runs after it.
  • Stale answers. An entry outlives a price change or a policy update unless a time-to-live expires it. Keep the cache non-authoritative and rebuildable, so you can clear it when the source of truth moves.

Where does semantic caching fit, and where not?

It fits where the same questions arrive over and over in different words: FAQ bots, help desks, internal knowledge assistants. A help desk fielding 100,000 calls a month sees many of them repeat, and Redis reports that this pattern can cut token spend by 30% or more without a measurable quality drop. It is a poor fit where every query is unique or personal.

  • Good fit: high-volume support and FAQ traffic, public answers, a knowledge base that changes slowly.
  • Poor fit: personalised replies, data that changes by the minute, one-off analytical queries, and any answer where a near-miss is costly, such as legal or medical replies.

What does semantic caching save?

The saving is the share of calls the cache serves times the cost of a call it replaces, minus the cost of running the cache. Take a support assistant that makes 100,000 model calls a month, 2,000 input and 400 output tokens each, on GPT-6.1 Sol at $2 per million input and $10 per million output tokens. That is an $800 monthly bill.

Assume, only as an illustration, a 30% hit rate, the floor Redis cites for repetitive traffic. None of this is measured on my own projects. Thirty thousand of those calls then skip the model, which takes the bill toward $560, before the small cost of embedding each query and running the search. Change the hit rate and the saving moves with it, so the honest version of this sum uses a number you measured. You can try your own figures in the API pricing calculator.

Which tools do semantic caching?

  • Redis. RedisVL ships a SemanticCache, and a managed LangCache, with embedding, a distance cut-off, a TTL and metadata filters on a Redis Search HNSW index. One FT.SEARCH runs the nearest-neighbour match and the tenant filter in a single pass.
  • GPTCache. An open-source semantic cache for LLMs that sits in front of the model, with pluggable vector stores such as FAISS, Milvus, pgvector and Qdrant. Its README headlines up to 10x lower API cost and 100x faster responses, though it ships no benchmark behind those numbers.
  • pgvector. If you already run Postgres, store the question embeddings and answers in a table and query them with cosine distance and an HNSW index. I weigh it against a hosted store in pgvector versus Pinecone.

When should you bring in help?

Semantic caching is one lever among several, and it only pays once you know your hit rate and what a call costs today. Guess the cut-off wrong and you either serve wrong answers or save nothing, so the first step is to measure a month of real traffic: how many questions repeat, how close the repeats are, and what each answered call costs.

On Evoriqa, my multi-tenant support platform, retrieval runs per tenant on pgvector, so I scope every vector lookup by tenant as a matter of course; a cache would ride the same index and the same boundaries. On an AI audit reviewer I built for a CPA firm, logging tokens put a review at a measured $0.24 to $0.28, not a guess. If your model bill is climbing faster than your traffic, an LLM cost and RAG quality audit measures cost per request on your real traffic and says whether a cache, a cheaper model or a shorter prompt saves the most.

From the work

  • AI reply grounded in cited help-centre content, shadow-mode draft metrics per channel, and metered AI credits in billing.

    Evoriqa

    My own SaaS: a multi-tenant AI customer-support platform, live in production, built by the person who also pays its inference bill.

    Live in production

    • Next.js
    • TypeScript
    • PostgreSQL
  • Exception report, upload screen and style-guide admin of an AI tool that reviews financial statements for $0.24 each.

    AI audit reviewer

    A draft financial-statement package goes in; a categorised exception report comes back in about 90 seconds, at a measured $0.24-0.28 per review.

    • Python
    • FastAPI
    • Anthropic Claude

The offer this article leads to: AI accuracy and cost audit, typically $1.5k-$3k.

Tell me what you’re building and where it’s stuck.

I’ll tell you the cleanest path forward, including if it’s “don’t build that.”

Email only, on purpose: it reaches me, not a sales team.

Or write tocontact@alihassan.dev

Ali Hassan in a dark winter jacket, looking off to one side, standing in a stone courtyard with a minaret and cloudy sky behind him.