How to measure a semantic cache's false hit rate
A semantic cache that serves a wrong answer looks exactly like one that served a right one: a fast response, a hit in the metrics, no error. This is how to find out how often it happens on your own traffic, and how many checks you need before the number means anything.
What the false hit rate is
A false hit (or false positive) is a request the cache answered with a stored response that was wrong for it: a different intent, a stale detail, an answer that depended on someone else’s conversation. Two ratios get called the false hit rate, and it matters which one you report:
- • Wrong hits ÷ served hits. How often a cached answer is wrong when you serve one. This is what a user who got a cached answer experiences.
- • Wrong hits ÷ all requests. How many of all your answers were wrong because of the cache. This is the one to compare against hit rate, since both share the same denominator.
A cache with a 5% hit rate and a 20% false hit rate (per served hit) is wrong on 1% of all requests. Say which ratio you mean whenever you quote one.
Why your logs can't tell you
A false hit raises no exception and no latency spike, and the user rarely reports it. The cache never called the model for that request, so there is no fresh answer to compare against. Hit rate, latency and cost dashboards all look better when the cache serves more, right or wrong.
Feedback you happen to receive (a thumbs-down, a support ticket) doesn’t fix this. Wrong answers are likelier to be reported than right ones, and most users report nothing, so no rate computed from volunteered feedback can be trusted. You need a sample you chose, not one that chose itself.
Method 1: replay labelled traffic offline
Take a few hundred to a few thousand real requests, find the cache candidate each one would have matched, and label every (request, cached answer) pair as a correct or incorrect reuse. Then replay the stream at each similarity threshold you might use and count hits and wrong hits. This gives you the whole trade-off curve before anything ships, and it is how you set the threshold in the first place.
Its weakness is time. The labels describe the traffic you had. In our replay of real Amazon and Comcast support traffic, a static threshold calibrated for a 2% error rate on the earlier history served wrong replies on 3.95% of requests in the weeks that followed on Amazon (details). An offline number is a starting point, not a measurement of production.
Method 2: audit a random sample of served hits
The only way to measure the live rate is to check some of the hits you actually serve. The procedure:
- 1
Pick a random fraction of served hits
Decide the fraction up front and draw it with a random number, independent of the similarity score, the route and the text. Anything else (only borderline hits, only flagged ones) measures a different population.
- 2
Call the model for those requests anyway
For a picked request, serve a fresh LLM answer instead of the cached one, so no user gets an unchecked answer, and keep both answers.
- 3
Judge whether the cached answer would have been right
Ask whether the cached answer could have been sent unchanged in place of the fresh one. An LLM judge is the usual choice; check it against a small set of human labels before trusting it.
- 4
Report the rate with an upper bound
Wrong audited hits divided by audited hits estimates the false hit rate. Report a one-sided upper confidence bound next to it, not just the point estimate.
- 5
Keep auditing as traffic changes
Track the rate over a rolling window. A threshold that was right last quarter can drift past your target without any change on your side.
Each audit costs one LLM call you would otherwise have saved, so the audit rate is a cost knob: a few percent of hits is usually enough, provided the volume gets you to the sample size below within the window you care about.
How many audits you need
To pin a false hit rate r down to ±h at 95% confidence you need about 1.96² × r(1−r) / h² audited hits:
| True rate r | Margin ±h | Audits needed |
|---|---|---|
| 2% | 1 point | ≈ 750 |
| 5% | 2 points | ≈ 460 |
| 10% | 3 points | ≈ 380 |
| 20% | 5 points | ≈ 250 |
If an audit window finds no wrong hits at all, that doesn’t mean the rate is zero. With n clean audits the 95% upper bound is still about 3 / n: 100 clean audits only show the rate is below about 3%, and 300 below about 1%. Report the upper bound; it is the number a promise can rest on.
Check the judge before you trust it
Labelling thousands of pairs by hand isn’t practical, so audits are usually judged by an LLM asked whether the cached answer could replace the fresh one. That judge has its own error rate. On 100 blind human labels from real support traffic, a non-thinking LLM judge agreed with the human on 68% of pairs and was too strict: it rejected many cached replies the human would have sent. The same model in thinking mode agreed on 77%. Label a hundred or so audits yourself, compare, and adjust the judge’s prompt or model until it agrees with you, before you report its numbers.
Mistakes that skew the number
- • Auditing only borderline hits. The rate among low-similarity hits says nothing about the near-identical ones, and near-identical isn’t always right: short follow-ups like “any update?” can match almost perfectly and still need a different reply.
- • One rate for every route. A cache can be safe on documentation questions and wrong on account-specific ones. Break the rate down by route or intent if your traffic mixes them.
- • Changing the policy mid-window. A new threshold or embedding model starts a new measurement. Don’t pool audits across it.
- • Dropping unanswered audits. If audits that time out or error are the hard cases, leaving them out biases the rate down. Track the completion rate too.
How CacheVerifier does this
CacheVerifier builds the second method in. With randomized auditing on, it picks a random fraction of approved verdicts and returns them as audits: you serve a fresh answer, report whether the cached one would have been right, and GET /v1/monitor/risk reports the approved-call error rate with a conservative upper bound. New accounts start with auditing on. The same labels feed recalibration and drift monitoring, so the measurement and the fix use one stream.
Where to go next
- • When a semantic cache serves the wrong answer — the kinds of false hits and why a similarity score can’t catch them.
- • Semantic cache similarity thresholds — using a labelled replay to set the cutoff.
- • API Reference: randomized audit — the audit flow, the risk endpoint and the sample-size note.
- • Start free