Negated question hits affirmative answer
Detect: Evaluation finds opposite-intent paraphrases near one another.
Recover: Add hard-negative tests and stricter intent compatibility.
Reuse validated answers for sufficiently similar requests while preserving tenant, policy, freshness, and task boundaries.
Semantic caching retrieves a previous answer by meaning rather than exact prompt bytes. It typically embeds the incoming query, searches cached query vectors, and applies an acceptance threshold before returning a stored response. The important contract is answer equivalence: two similar questions are not necessarily entitled to the same answer.
A cache entry must carry more than a vector and text. Tenant scope, authorization context, locale, model or prompt revision, source versions, and expiration determine eligibility. Personalized balances, changing prices, and action requests are usually poor candidates. Semantic caching differs from provider prefix caching, which reuses computation while still generating a fresh answer.
A prototype measures hit quality on repeated public questions and labels false matches manually.
Production adds metadata gates, per-intent thresholds, invalidation, provenance, and a bypass for sensitive or volatile tasks.
At enterprise scale, track false-hit rates by tenant and language, control cache cardinality, and test revocation propagation independently of expiration.
Excludes personalized, action-oriented, or rapidly changing requests.
Maps eligible questions into a versioned similarity space.
Stores answer evidence and filters entries by tenant and policy metadata.
Checks semantic threshold, freshness, and answer compatibility.
Produces and validates fresh answers on a miss before storing eligible results.
flowchart LR
Q["Question"] --> E["Eligibility gate"]
E --> V["Scoped vector lookup"]
V --> A["Similarity and freshness checks"]
A --> H["Reuse validated answer"]
A --> G["Generate fresh answer"]
E --> G
G --> S["Store eligible evidence-backed response"]
S --> VDetermine whether answer reuse is allowed for the request type and data classification.
Resolve tenant, language, policy revision, and source-version constraints.
Embed the question and retrieve nearby entries only within the allowed scope.
Apply calibrated similarity and freshness checks; treat uncertainty as a miss.
Run retrieval and generation, validate the answer, and retain its supporting evidence.
Write a bounded-life entry and measure hits, misses, false matches, and invalidation lag.
Public transport · Illustrative enterprise scenario, not a reported customer outcome.
A transit operator receives many paraphrases of the same baggage and bicycle questions.
Repeated model calls answer stable policy questions while personalized journey requests share the interface.
Reuse policy answers without serving one passenger another passenger’s itinerary.
The cache permits public policy intents and keys eligibility by policy revision and service region.
When the policy changes, its revision invalidates old entries even if their similarity scores remain high.
Track avoided generation work alongside false-hit rate and policy freshness; a higher hit rate is harmful if answer equivalence deteriorates.
| Decision | Benefit | Cost |
|---|---|---|
| Broader similarity threshold | Increases potential reuse. | Raises the chance of a confidently wrong cache hit. |
| Fine-grained scope | Protects tenant and policy boundaries. | Reduces hit rate and increases index cardinality. |
| Short expiration | Limits stale answers. | Forces more generation on stable questions. |
Detect: Evaluation finds opposite-intent paraphrases near one another.
Recover: Add hard-negative tests and stricter intent compatibility.
Detect: Answer provenance references an inaccessible source revision.
Recover: Invalidate by source identifier and recheck authorization on retrieval.
Calibrate thresholds using labeled answer-equivalence pairs.
Store only accepted responses with provenance.
Partition or gate reuse using explicit authorization scope.