Many questions to an AI assistant come back again and again, phrased differently each time. Reusing an earlier answer saves a full round of retrieval and generation. The catch is that two questions can read almost the same and still be about different things: another company, another quarter, another set of files. Reusing an answer in that case is worse than not reusing it at all, because it comes back fast and confident.
I designed the reuse layer that handles this: exact-key lookup plus hybrid semantic retrieval over earlier answers, context and subtask results, with entity, time, scope, freshness and confidence checks, selective NLI validation, and a fallback to fresh processing. The rule it is built on is simple. A missed reuse is acceptable; a wrong reuse is not.
Exact matches aren’t enough, and similarity isn’t safe
An exact cache only helps when the same text comes back. People rarely ask the same way twice: “AAPL” and “Apple”, “Q1 2024” and “first quarter of 2024”, “compare” and “versus” all describe the same request.
Semantic similarity fixes that, and creates the opposite problem. “Apple’s revenue in Q1 2024” and “Apple’s revenue in Q2 2024” are close in meaning and should never share an answer. So similarity is used to find candidates, never to approve them.
How a lookup runs
new question
- 1
Normalize and try an exact match
Map names, tickers, dates and phrasing to a stable key, while keeping the original question. An exact hit still has to pass the checks below.
- 2
Find candidates
Hybrid retrieval over earlier results: exact-term matching for names, periods and metrics, semantic search for questions worded differently. Fetch more candidates than needed.
- 3
Hard checks
Drop any candidate whose companies, time period or scope don’t match the new question, or that is past its freshness window.
- 4
Confidence, and NLI when it matters
Rank what is left and keep only confident matches. Run an NLI check on the cases where similarity alone is not convincing.
Reuse it
As the answer, as supporting context, or as one part of a larger task.
Do the work fresh
No candidate passed every check.
The checks that decide reuse
Entities come from the most reliable source. Names in a question are ambiguous: “Apple”, “Meta” and “AI” can each mean more than one thing. When the part of the system that called the cache has already resolved which company the user means, that answer overrides the cache’s own extraction, which is cheaper but less certain.
Freshness depends on the information. Commentary on recent events goes stale in hours, quarterly figures last until the next report, and a definition barely ages at all. Each stored result carries its own freshness window. Expired results are rejected, and results close to expiry count for less.
Coverage matters more than overlap. When matching a question’s details against a stored result, I preferred a measure of how much of what the user asked for the result covers over a symmetric overlap score. A result that covers Apple and also mentions Microsoft can still answer a question about Apple. A result that is missing the quarter the user asked about cannot.
Where NLI fits
An NLI model can check whether a stored answer actually supports what is being asked, which catches candidates that are close in wording but not in substance. It also adds noticeable time per candidate, and the cache exists to save time. So NLI isn’t on every lookup. It runs selectively, on the cases where similarity and the hard checks leave real doubt.
Three ways to use a hit
A stored result doesn’t have to replace the whole answer. It can be returned directly, passed in as supporting context for a new answer, or used for one part of a larger request that the assistant has broken into steps:
"Compare A and B on revenue
growth and margins"
├─ A revenue growth
│ reused: same company,
│ same period, still fresh
├─ B revenue growth
│ done fresh: no safe match
├─ A margin drivers
│ reused as supporting context
└─ B margin drivers
done fresh
Even when the full question is new, some of its parts may not be.
What changed
The cache started as a way to save latency and model calls and became a reuse layer the rest of the system can rely on. It returns a stored result only when the details match, and otherwise steps aside so the request takes the fresh path.
The measures I would judge it by follow from that rule: how often reuse was wrong (wrong company, wrong period, stale), not just how often it happened, and how much retrieval and generation it saved on the requests where it was right.