Field-tested notes on robotics safety, ROS 2, embedded AI, AI agents, SaaS architecture and the practical systems that connect software to real-world outcomes.

RAG Embedding Migrations: Switch the Encoder and Index Together

Two paired encoder and document-index lanes with an incorrect cross-connection unplugged

The new embedding index is ready. Its document count matches production. Quality checks pass. An operator switches the search alias, and a request already in flight sends a vector from the old encoder into the new index. The database accepts it because the dimensions match. The assistant receives the wrong evidence without an API error.

An embedding-model migration must release the query encoder and its matching document-vector index as one retrieval configuration. Select that configuration once per request, before encoding, and keep it through search. Retain the previous configuration for in-flight work and qualified rollback. An atomic index-alias update is useful, but it cannot retroactively change a vector computed by another service.

Equal dimensions do not identify a vector space

A vector’s length tells the database how many coordinates it must store. It does not tell the database what those coordinates mean. Two encoders can produce 768-dimensional vectors with different neighborhoods. Even the same model family can change behavior through model revisions, input templates, pooling or normalization.

There is also a distinction between identical encoders and a compatible pair. Some retrieval models use different query and document instructions, or separate query and document encoders trained together. The requirement is the qualified pairing, not a rule that both sides must execute identical code.

For externally generated query vectors, make that pairing explicit in application state. For server-side text vectorization, check whether the backend resolves both the vectorizer and target index from one stable collection configuration for the entire request. Moving encoding into the search service can simplify the boundary; it does not establish the guarantee without checking the implementation.

Current vendor guidance already treats migration as more than copying vectors. Qdrant’s embedding migration guide coordinates the query-model change with the collection or named-vector change, and describes an observation period with both representations maintained. Weaviate’s vectorizer migration tutorial covers separate collections and additional named vectors. The remaining application design question is where that choice becomes fixed for a request that spans the cutover.

Give each request a complete retrieval configuration

Avoid two independently reloadable settings called embedding_model and search_alias. Publish an immutable manifest and make the live setting a pointer to its release ID. A request resolves that pointer once. Its embedding call, search call and retries carry the resolved ID.

This illustrative manifest describes one externally encoded route. The identifiers are invented; they are not vendor API fields.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"release_id": "retrieval-B",
"embedding_space_id": "support-space-B",
"query_encoder": {
"artifact": "query-encoder-B@immutable-revision",
"input_template": "query-template-v3"
},
"document_encoder": {
"artifact": "document-encoder-B@immutable-revision",
"input_template": "passage-template-v2"
},
"vector": {"dimensions": 768, "normalization": "l2", "metric": "cosine"},
"target": {"collection": "support_B", "vector_name": "content_B"},
"ingestion": {"parser": "parser-v4", "chunker": "chunks-v7"},
"search_profile": "support-search-v5",
"qualification_record": "qualification-B-17"
}

embedding_space_id is a registry identity assigned to a verified configuration. It is not something to infer from the vector’s numbers or accept from an untrusted caller. The platform owns the manifest, restricts changes to its targets and records the actual model revision used. A provider alias that silently changes weights weakens this guarantee; use a pinned revision where available and requalify when the provider changes it.

The query worker should return the vector with trusted provenance: release ID, embedding-space ID and the actual encoder configuration. Before search, the gateway checks that those identities match its selected manifest, and validates dimensions and finite values. Shape checks remain worthwhile; they just cannot replace provenance.

Use an explicit collection/vector target, or a release-specific alias whose binding is kept stable. A request that pins retrieval-A but still searches a mutable global alias can cross into B anyway. Collection aliases provide indirection; the application still needs to define how long each binding remains valid.

Do not pin user authorization in this manifest. A request may retain encoder A while applying the latest required source permissions and withdrawal rules. Compatibility state and access state have different lifetimes. The existing RAG governance boundary should continue to enforce who may use the retrieved evidence.

Reproduce the silent mismatch with two coordinates

The following Python 3 program uses synthetic unit vectors. Model B swaps the coordinates of model A. Both models retrieve the intended runbook perfectly when queried in their own space. Both retrieve the decoy when paired with the other model’s index.

This transformation deliberately preserves within-space cosine similarities. It isolates the deployment error from any debate about which model has better retrieval quality. Real embedding upgrades need not be related by such a simple transformation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from dataclasses import dataclass

@dataclass(frozen=True)
class Release:
name: str
query_vector: tuple
documents: tuple

# Synthetic unit vectors. B swaps the coordinates of A.
A = Release('A', (1, 0), (('runbook', (1, 0)), ('decoy', (0, 1))))
B = Release('B', (0, 1), (('runbook', (0, 1)), ('decoy', (1, 0))))

def search(vector, release):
# Dot product equals cosine here because all vectors have unit norm.
return max(release.documents,
key=lambda item: sum(x*y for x, y in zip(vector, item[1])))[0]

def request(old, new, switch_at, pinned):
active = old
route = None
vector = None
result = None
# 0: select route; 1: encode; 2: search; 3: response already computed.
for stage in range(4):
if stage == switch_at:
active = new
if stage == 0:
route = active
elif stage == 1:
vector = (route if pinned else active).query_vector
elif stage == 2:
result = search(vector, route if pinned else active)
return result

assert search(A.query_vector, A) == 'runbook'
assert search(B.query_vector, B) == 'runbook'
assert search(A.query_vector, B) == 'decoy'
assert search(B.query_vector, A) == 'decoy'

bad = 0
for old, new in ((A, B), (B, A)): # cutover and rollback
for switch_at in range(4):
naive = request(old, new, switch_at, pinned=False)
stable = request(old, new, switch_at, pinned=True)
assert stable == 'runbook'
assert (naive == 'decoy') == (switch_at == 2)
bad += naive == 'decoy'
print(f'Naive mismatches: {bad}/8; pinned mismatches: 0/8')

The executed result is:

1
Naive mismatches: 2/8; pinned mismatches: 0/8

These are eight deliberately enumerated schedules, not an estimate of production failure probability. The two failures occur when the active release changes after encoding and before search, once during upgrade and once during rollback. The frozen route succeeds because the old encoder/index pair remains available.

The experiment models serial stages, not threads, network retries or a real vector engine. A Python dataclass does not provide distributed atomicity. Its role is to make the invariant visible: the vector and target must come from the same selected release. Your deployment test needs to pause a real request between those two calls and exercise the same schedule.

Separate routing readiness from data readiness

A coherent pair can still search an incomplete or outdated corpus. Keep two independent readiness records: one for the encoder/index pairing and another for the source revisions represented in the candidate index.

Build a candidate from an identified source snapshot and capture changes that occur while it is being populated. If the connector cannot establish a consistent snapshot/change-stream boundary, schedule a controlled ingestion pause or reconcile against a fresh authoritative manifest before serving the candidate. Do not describe a scan of a changing corpus as a snapshot.

Database change streams illustrate why the boundary matters. PostgreSQL’s logical decoding documentation describes exported snapshots aligned with a change stream, and warns that changes can be delivered again after a crash. That is a useful source capability, not a guarantee that a downstream embedding worker has successfully materialized every event.

For each candidate release, reconcile source identity and revision, expected chunk IDs, authorization metadata and withdrawal state. Keep separate progress for each stream partition, and advance the applied watermark only after the corresponding writes are visible through the serving path. A worker that has read event 500 has not necessarily indexed it. A failed batch hidden in a dead-letter queue must prevent a clean readiness receipt for its scope.

Qdrant’s migration documentation explicitly calls out additional work or paused operations for deletes and partial updates. Apply the established RAG deletion and reintroduction controls to both candidate and rollback stores. A late backfill must not make a withdrawn source eligible again. Matching total counts cannot prove this: one missing chunk and one obsolete chunk can cancel out.

Then evaluate each route using its own query embeddings against the same authorized questions and source state. Reusing A’s query vectors to evaluate B measures a broken pairing. Raw similarity scores also need not be comparable across releases; requalify thresholds and any score-dependent reranking logic. Use permission-filtered retrieval tests to separate access exclusions from retrieval failures, and judge whether the evidence actually supports the task.

Rollback is another cutover

A release pointer can change quickly while old requests are still running. New requests select B; admitted A requests finish on A, or are explicitly cancelled and restarted through B from the original query text. A retry must not reuse an A vector against B merely because the A backend is unavailable.

If you restart, consume the existing deadline and attempt budget. Label the new attempt with its new release ID. Any cached query embedding must be keyed by its complete encoder configuration and preprocessing; the original text alone is insufficient. Retrieval-result caches need release identity and current authorization/dependency checks as well.

The operating decision should depend on which pair is ready, not simply on whether an old collection still exists:

ConditionPermitted action
B is qualified; A remains current and serves admitted requestsRoute new requests to B; drain A normally.
B quality regresses; A encoder, index, source revisions and controls are still qualifiedRoute new requests to A; drain or explicitly restart B requests.
A exists but stopped receiving source updates or withdrawalsKeep it ineligible for rollback until replay and reconciliation restore readiness.
A encoder is unavailable while an A request retriesFail within the defined service behavior, or restart the full encode-and-search attempt on a qualified route.
Both routes fail mandatory access or integrity checksWithhold affected retrieval; expose the service failure instead of manufacturing evidence.

Choose a rollback observation window with a named owner and a measurable exit condition. Keep both representations updated during that window, including permission changes and withdrawals. Ending those updates ends immediate rollback readiness. A stored snapshot may still be useful for recovery, but restoring it requires replay and validation before traffic resumes.

The broader model-failover design covers eligible providers, deadlines and workflow state. Here the essential recovery unit is smaller and strict: one query encoder, one document-vector space and one compatible search configuration.

Before retiring A, run an integration exercise that pauses a request after encoding, changes the active release, and then resumes it. Repeat in the rollback direction, during an embedding retry, and with a release-specific target deliberately unavailable. Record selected release, actual encoder revision, target collection/vector, request attempt and outcome. A result labelled A that searched B is a failed release even if the answer happens to look correct.

Assign one retrieval-service owner to that end-to-end evidence. The embedding worker and database can each be healthy while their composition is wrong. The release is ready when a request can cross an upgrade or rollback without losing the identity of the vector space it is searching.