AI & agents / Cache Index Lab

Semantic Caching When Models Change: Version, Evaluate, Migrate

A similar question can still require a different answer. Learn which changes invalidate semantic cache entries and how to migrate without silently reusing incompatible results.

Neon semantic caching graphic showing separate model versions and a controlled cache migration path.

A semantic cache can reuse an answer when a new request is sufficiently similar to a previously answered request. That makes the cache more flexible than a lookup based only on identical text, but it also introduces a judgment: does similarity justify reuse? A model change makes that judgment harder. The new request may look familiar while its instructions, source material, permissions, or expected answer have changed.

Successful migration starts by treating cached answers as versioned application results. Similarity is one candidate-selection signal, not proof of correctness. This guide explains how to separate model changes, retain useful provenance, evaluate reuse, and move to a new cache generation without letting old assumptions silently survive the transition.

Distinguish the embedding model from the answer model

The embedding model represents input in a form used for similarity comparison. The answer model produces the response that may be stored. These are different roles, even when a product bundles them into one interface. Changing the embedding model affects how candidates are found. Changing the answer model affects the behavior or quality expected from newly produced answers. A migration plan should name both explicitly.

Microsoft's semantic caching documentation illustrates the distinction with separate chat-completion and embedding deployments, lookup and store policies, and a configurable similarity threshold. It describes reuse for identical prompts and prompts with similar meaning. That establishes the basic mechanism; the application still needs to decide which results are eligible for reuse in its own context.

Separate similarity from eligibility

Two questions can be close in meaning while requiring different answers. “How do I reset access?” may depend on the product edition, the caller's role, and the current policy. “What is my remaining balance?” is even more clearly tied to private, changing state. A semantic match should not override those distinctions. Apply exact eligibility boundaries before evaluating whether a candidate's meaning is close enough.

Use the AI cache index overview to distinguish answer reuse from other caching layers. Reusing a generated answer is a different decision from reusing intermediate computation for a repeated prompt prefix. Treating both as one generic cache can hide whether the system will run the answer model again or simply return an earlier response.

Record the lineage that makes an answer valid

Store an entry's answer-model identifier, embedding-model identifier, prompt or policy revision, source-corpus revision, and relevant output-schema version. Include the reuse scope and any decision-relevant context that the application requires. The right fields depend on the task, but they should explain why the result was considered reusable. A creation timestamp alone cannot reveal that an instruction or reference document changed.

Prefer pinned identifiers where the platform exposes them, and record uncertainty when an alias can change behind the same label. Keep a human-readable reason for invalidation alongside a machine-readable generation. If a future reviewer sees only “version three,” they should still be able to discover whether the change corrected facts, adjusted output format, or replaced the similarity representation.

Use separate namespaces for incompatible embeddings

Do not assume vectors produced by different embedding models can be meaningfully compared just because their dimensions match. Treat a model migration as a new representation space unless the provider supplies an applicable compatibility guarantee and your evaluation supports it. Store the model identity and vector schema with the index. Reject a query that targets the wrong space instead of attempting an undocumented comparison.

Re-embedding does not refresh an answer

You may rebuild a new vector index from retained, permitted source prompts, but that does not automatically make the associated answers current. Re-embedding changes how a record is found; it does not regenerate the answer or repair an obsolete instruction. Evaluate answer eligibility separately before admitting a migrated record to the new namespace.

Version prompts and output contracts

A changed system instruction can invalidate an otherwise accurate cached answer. Suppose the previous application returned a paragraph and the new contract requires a structured object with specific fields. The old response may fail the client even when its content is correct. Include the output-contract revision in the reuse boundary and validate a candidate against the current requirements before returning it.

The prompts chat index guide provides a place to organize those prompt revisions. Do not normalize away distinctions that affect meaning, such as negation, units, or a requested time period. In a migration review, inspect the request normalization rules as carefully as the model identifier. A stable model cannot compensate for a key or representation pipeline that erases important context.

Calibrate the threshold with decision-focused examples

Build an evaluation set containing requests that should share an answer and close-looking requests that must remain separate. Include changed account scope, dates, product versions, permissions, and task intent when they matter to your application. Label the expected reuse decision and explain it. A generic similarity benchmark is less useful than examples that expose the consequences of a wrong match in your actual workflow.

Measure incorrect reuse as well as missed opportunities. A conservative threshold may reduce reuse but avoid returning a misleading answer. The acceptable tradeoff depends on the task, so there is no universal threshold to copy. Recalibrate after an embedding-model change because a numeric score only has meaning within a specified model, comparison method, and evaluation context.

Migrate in a controlled sequence

First, define the new generation and the conditions for admitting records to it. Next, run new lookups against representative requests without serving their candidate answers to users. Compare the proposed decisions with reviewed expectations and newly generated answers where appropriate. Record disagreement reasons so that a threshold adjustment does not hide a missing version boundary or a permissions error.

Then move a limited, appropriate portion of traffic to the new generation, with explicit monitoring and a fallback path. Keep old and new records distinguishable throughout the transition. If you backfill entries, apply the same eligibility rules as a live write. The cache index API design guide explains how generation checks can prevent in-flight work from repopulating an invalidated namespace.

Handle source changes independently of model changes

A model can remain unchanged while the facts supporting an answer become obsolete. Track dependencies at the granularity the application can maintain reliably. If a cached setup answer depends on a policy document, a material policy revision should trigger review or invalidation. Do not rely on semantic distance to notice that the correct answer changed; the wording of the question may be identical.

Broad invalidation is sometimes the clearest initial design. More selective invalidation can preserve reuse, but it requires accurate dependency records. Choose the complexity you can actually operate. When a source revision is unknown, record that limitation and use a conservative eligibility policy instead of inventing a lineage that the system did not capture.

Measure the full path and prepare rollback

Account for embedding calls, candidate retrieval, validation, storage, and fallback generation when evaluating cost or latency. Report savings only from measured workload data, and distinguish an eligible hit from a rejected candidate. A headline hit rate can improve while the system spends more work checking unsuitable results. Track incorrect reuse, invalidation reasons, and the fraction of requests that bypass semantic caching entirely.

Keep a rollback decision separate from a rollback mechanism. Switching back to the previous model does not make previously invalidated content safe. Preserve the generations needed for operational recovery, but only serve entries that still meet current policy and source requirements. Practice the transition with a bounded sample so that recovery does not depend on an untested assumption about old records.

Control admission as well as lookup

Store only responses that satisfy the application's completion and validation rules. A truncated stream, malformed structured object, or unresolved tool failure should not become a reusable answer merely because generation ended. Record why an output was rejected and test that rejection across both model generations. This admission step reduces the chance that a migration preserves an error which the similarity lookup later finds efficiently.

Conclusion: migrate the reuse decision

A semantic cache migration involves more than replacing a model name. Separate embedding compatibility, answer validity, prompt contracts, and source freshness. Version those boundaries, evaluate the decisions that matter, and keep rollback subject to current eligibility rules. This makes reuse explainable and gives a team a practical way to benefit from similarity without treating it as a guarantee.

Continue the reading path through the subjects covered in this article.

Connected reading

Keep the ideas moving.

All Lab articles