Version embedding models, dimensions and normalization rules as one index contract, then cut over only after query parity checks.
Embedding migrations: keep query and document vectors in one space
Record the vector contract
An embedding is meaningful only relative to the model and preprocessing that produced it. Store model ID, revision, vector dimension, distance metric, text normalization and any title-prefix policy beside each index generation. A query vector from model B must not be compared to document vectors from model A merely because both have 768 coordinates. Even identical dimensions do not imply shared geometry. Embedding diagnostics belong before promotion.
Build a separate generation
Create a new index rather than overwriting old vectors in place. Re-embed every active, permitted document revision; index tombstones and access metadata at the same time. Reject vectors with non-finite values, wrong dimensions or an empty source span. Keep the old index available while the new one is validated. If the model changes its tokenizer or input prefix, capture that too; a silent query-side change can look like an index outage.
Compare on the same judgments
Run a frozen query set against old and candidate indexes with the same permission snapshot. Report recall at the candidate cutoff, first relevant rank, exact-ID failures and latency by query family. A higher average similarity is not evidence of better retrieval because score scales move with models. Inspect newly missed answer-bearing passages, especially minority languages and long documents. Release gates turn this comparison into a decision.
Switch and recover
Point readers to one versioned alias only after the candidate is complete and validated. Include the generation ID in result metadata and cache keys. Keep the previous alias target for a rollback window, then retire it under the corpus deletion policy. A rollback must restore matching query encoder and document index together. A mixed pair can return plausible neighbors while quietly losing relevant evidence.
Worked contract
from dataclasses import dataclass
from math import isfinite
@dataclass(frozen=True)
class VectorContract:
model_revision: str
dimensions: int
metric: str
def accept_vector(values: list[float], query_contract: VectorContract,
index_contract: VectorContract) -> tuple[float, ...]:
if query_contract != index_contract:
raise ValueError("query and index vector contracts differ")
if len(values) != index_contract.dimensions or not all(map(isfinite, values)):
raise ValueError("invalid vector")
return tuple(values)
active = VectorContract("receipt-embed-r8", 3, "cosine")
assert accept_vector([0.2, 0.4, 0.8], active, active) == (0.2, 0.4, 0.8)
try:
accept_vector([0.2, 0.4, 0.8], VectorContract("receipt-embed-r9", 3, "cosine"), active)
except ValueError:
pass
else:
raise AssertionError("mixed embedding generations were accepted")Performance and operating cost
Validating one d-dimensional vector takes O(d) time and O(d) output space here. Re-embedding N passages costs N model calls plus index construction and temporarily doubles vector storage during overlap. Migration planning should include that peak, query encoder rollout, cache invalidation and a measured rollback window.
Common Mistakes
- Assuming equal vector dimensions imply compatible embedding spaces.
- Replacing document vectors before deploying the matching query encoder.
- Comparing raw similarity scores across model versions as if they shared a scale.
- Deleting the previous generation before rollback and permission tests pass.
Validation drill
Take 83 judged queries with identifier, paraphrase and multilingual slices. Build a candidate index under a new model revision, verify dimension and access metadata, then record recall and latency deltas before moving the alias.
Read next
- Filtered vector search: measure ANN recall inside the permitted set
- Retrieval release gates: evaluate slices before changing an index
- Index freshness: publish complete revisions and remove stale chunks
- Embedding retrieval recall and collapse checks
