Home / AI Architecture & System Design / RAG & Retrieval
Your embedding provider releases a better model. How do you migrate?
30-second answer
Embeddings from different models aren't comparable, so you must re-embed the corpus. Build a new versioned index in parallel, backfill in batches, evaluate it against the old one on the golden set, dual-write new documents to both during transition, then shift traffic gradually and keep the old index for rollback.
Try answering out loud before reading on. The walkthrough below is paced for a 40-minute interview round.
New to these terms? 11 terms on this page are explained in the glossary
0–5 min Functional requirements
This is a data migration with a quality risk attached. Clarify scale and constraints first.
You How big is the corpus, and how often does it change?
Interviewer About 40 million chunks. A few hundred thousand change every day.
You Does the new model have a different vector dimension?
Interviewer Yes: 768 today, 1,024 for the new one.
You Can search have downtime or degraded quality during the migration?
Interviewer No downtime. And we need confidence it's actually better before users depend on it.
You Is there a deadline?
Interviewer The old model's API is deprecated in six weeks.
The core constraint to state out loud: vectors from two different models can't be compared. A query embedded with the new model, searched against documents embedded with the old one, returns meaningless results. So the whole corpus must be re-embedded, and query and document embeddings must switch together.
| # | Functional requirement | Why it matters |
|---|---|---|
| F1 | Re-embed the full corpus with the new model into a new index | Vectors aren't comparable across models |
| F2 | Keep serving search from the old index until the new one is validated | No downtime |
| F3 | New, updated and deleted documents stay correct in both indexes during migration | No data loss at cutover |
| F4 | Compare quality between indexes on an evaluation set and on live traffic | Prove it's better before switching |
| F5 | Shift traffic gradually and roll back in minutes | Limit the impact of surprises |
| F6 | Decommission the old index after a safe period | Cost |
Out of scope: changing chunking at the same time. Doing both at once makes it impossible to tell which change caused a quality difference.
5–10 min Non-functional requirements and estimates
You I'd like to keep chunking identical, so any quality change is attributable to the model. If we also want new chunking, that's a separate migration later.
Interviewer Reasonable.
| Requirement | Target | What it forces in the design |
|---|---|---|
| Availability | Zero downtime | Parallel index, alias-based switch |
| Quality | No regression in any query segment; overall recall@10 improvement | Segmented evaluation, shadow comparison |
| Timeline | Backfill done in ≤ 5 days; full cutover within 3 weeks | Throughput planning, rate-limit increases |
| Consistency | Every live document present in both indexes at cutover | Dual-write, reconciliation counts |
| Rollback | ≤ 5 minutes | Old index kept warm; feature flag |
| Cost | Known upfront | Token and storage estimates |
Back-of-envelope estimates:
- Tokens to embed: 40M chunks × ~400 tokens = 16B tokens.
- Embedding cost: at an illustrative $0.02–0.13 per million tokens, ~$320–2,100. Not the problem.
- Throughput: finishing in 3 days needs 16B / 259,200 s ≈ 62,000 tokens/s, about 3.7M tokens/minute sustained. That's likely above default API rate limits, so request an increase early, or self-host the model: at ~30,000 tokens/s per GPU, 2–3 GPUs for three days.
- Storage: 40M × 1,024 dims × 4 bytes ≈ 164 GB in float32 for the new index, while the old 768-dimension index (~123 GB) still exists. With int8, about 41 GB and 31 GB. Budget for both running for several weeks.
- Dual-write load: a few hundred thousand chunk updates a day is ~3–10 per second on average. Trivial next to the backfill.
10–18 min High-level design
You Build the new index alongside the old one. A backfill job fills it, dual-writes keep both current, and a query router decides which index serves each request, with shadow comparison before any user sees the new results.
Scroll sideways to see the whole diagram.
Components:
- Index v1: today's index (old model). Keeps serving until cutover.
- Index v2: new index with the new dimension and the same chunk IDs.
- Backfill job: reads chunks from the source of truth, embeds with the new model, writes to v2, and checkpoints progress.
- Dual-write: the ingestion pipeline writes every change (upsert or delete) to both indexes during the migration.
- Query router: a feature flag decides the percentage of traffic served by v2, and embeds the query with the matching model.
- Shadow compare: for mirrored queries, runs both indexes and records overlap and quality signals without affecting the user.
The plan over time:
Scroll sideways to see the whole diagram.
Router behaviour:
on query(q, user):
bucket = hash(user_id) % 100 # sticky per user
if bucket < flags.v2_percent:
return search(index_v2, embed_v2(q))
result = search(index_v1, embed_v1(q))
if sampled(flags.shadow_rate):
async compare(result, search(index_v2, embed_v2(q)))
return result
Bucketing by user keeps each person's experience consistent during the ramp.
How it works: a worked example
A study aid: the migration traced day by day, with the actual flag values, counts and comparison numbers you'd look at before each step.
Day 0 · Prepare. Create index_v2 (1,024 dimensions) next to index_v1 (768 dimensions), same chunk IDs. Ask the embedding provider for a rate-limit increase (or reserve 3 GPUs). Turn on dual-write: every upsert and delete from the ingestion pipeline now goes to both indexes.
flags:
embeddings.dual_write: true
embeddings.v2_percent: 0
embeddings.shadow_rate: 0.0
Days 1–3 · Backfill. A job walks all 40M chunks from the source of truth in batches of 2,000, embeds with the new model, writes to index_v2, and checkpoints the last chunk ID every batch so a crash resumes where it stopped.
backfill progress day 2 14:00 chunks 26.1M / 40.0M rate 61k tokens/s errors 0.002% (retried)
Day 4 · Reconcile. Compare counts and spot-check content hashes per source:
source v1 chunks v2 chunks missing extra
confluence 18,402,113 18,402,113 0 0
drive 15,880,421 15,880,402 19 0 ← re-queued and fixed
tickets 5,717,466 5,717,466 0 0
Days 5–7 · Shadow. shadow_rate: 0.05. For 5% of live queries, the router also searches index_v2 asynchronously and logs both result lists. Daily report:
top-10 overlap (v1 vs v2): mean 0.62
golden set recall@10: v1 0.84 → v2 0.89
segment: error codes / IDs v1 0.91 → v2 0.90 (within noise)
segment: non-English queries v1 0.71 → v2 0.83
judge preference on 1,000 differing v2 better 41%, same 44%, v1 better 15%
No segment regresses, so ramp.
Days 8–14 · Ramp by user bucket: v2_percent: 5 → 25 → 50 → 100, watching click-through on citations, thumbs-down and "no results" rates at each step. Each user stays on one index (hash of user ID), so their experience is consistent.
Day 15 · Cutover. v2_percent: 100. Keep index_v1 warm and dual-written for a week: rollback is setting the flag back to 0, which takes effect in seconds. Then stop dual-writing and delete index_v1 (frees ~123 GB).
Where each piece runs:
| Component | Runs as | Example technology | If it fails |
|---|---|---|---|
| Backfill job | Batch workers with checkpoints | Kubernetes job / Spark; embedding API or 2–3 GPUs | Resume from the last checkpoint |
| Dual-write | Step in the ingestion pipeline | Writes to both indexes in one job; retries per index | A failed write to v2 is queued for retry; v1 stays authoritative |
| Query router | Flag check in the query service | Feature-flag service | Defaults to v1 |
| Shadow compare | Async workers | Queue + comparison job writing to the warehouse | Shadow data lost; users unaffected |
| Two indexes | Same search cluster or two clusters | ~164 GB + ~123 GB float32 (or ~41 + ~31 GB int8) | v1 serves until cutover |
18–32 min Deep dive
You The three places this goes wrong are the backfill, consistency during migration, and deciding whether v2 is really better. Where should I start?
Interviewer The backfill. How do you re-embed 40 million chunks reliably?
Deep dive 1 · The backfill job
- Work units: partition chunks into ranges (by chunk ID or hash) of ~10,000. Workers take a range, embed it in batches of 100–500 texts, write to v2, and mark the range done in a progress table. A crash restarts only the current range.
- Idempotent writes: upsert by
chunk_id, so retries are safe. - Rate control: a token bucket sized to the provider's limit, with backoff on 429s. Track tokens per second against the plan.
- Priority order: embed the most frequently retrieved ~20% of chunks first. If the deadline slips, v2 already covers most real queries.
- Read from the source of truth: chunk text comes from the document store, not the old index, so any chunks corrupted in v1 don't propagate.
- Validation as it goes: count per range, spot-check vector norms and dimensions, and run a small evaluation on completed partitions.
Interviewer Documents keep changing for the five days of backfill. How do you avoid missing updates?
Deep dive 2 · Consistency during migration
Scroll sideways to see the whole diagram.
- Turn on dual-write before the backfill starts. Then any change made during the backfill is written to v2 directly. If the backfill later processes the same chunk, versions decide which write wins.
- Version every write: each chunk has a
content_version(or update timestamp). v2 accepts a write only if its version is newer than what's stored, so an old backfill write can't overwrite a newer dual-write. - Deletes: dual-write deletes to both. The backfill skips chunks marked deleted in the source.
- Reconciliation before cutover: compare chunk counts and a sample of chunk IDs and versions per partition between the document store, v1 and v2. Fix any gaps.
Deep dive 3 · Proving v2 is better
- Offline: run the golden set (queries with labelled relevant chunks) against both indexes. Compare recall@10 and MRR per segment: short keyword queries, long questions, code and identifiers, each language. Leaderboard gains don't always transfer to your data.
- Re-tune what depends on scores: reranker thresholds, hybrid fusion weights and "no relevant result" cutoffs were calibrated on v1's similarity distribution, so re-tune them on v2.
- Shadow: mirror ~5% of live queries to both and record overlap@10, the score distributions, and how often v2 finds documents users later click.
- Canary: serve 10% of users from v2; compare thumbs-down rate, citation clicks and "no answer" rate against v1 users. Then 50%, then 100%.
Interviewer What if v2 is worse for one segment, say code queries?
Options: investigate first (often analyzers or chunk prefixes interact differently with the new model), boost BM25's weight for that segment in hybrid search, or delay cutover. Don't ship a known regression silently.
Deep dive 4 · Rollback and clean-up
- Rollback: flip the flag back to 0% v2. Because dual-write continues, v1 stays current, and rollback takes seconds.
- Keep v1 for two weeks after 100%, still dual-writing, then stop dual-writes and delete it.
- Embedding cache: if you cache query embeddings, key the cache by model version to avoid mixing.
- Pin versions: store
embedding_modeland version on every chunk, and pin the provider model version, so a silent model update can't corrupt the index.
32–37 min Trade-offs
| Decision | Chosen | Alternative | Why |
|---|---|---|---|
| Approach | Parallel index + gradual cutover | In-place re-embedding | Mixed vectors during migration would break search |
| Chunking | Unchanged | Re-chunk at the same time | Isolates the cause of any quality change |
| Backfill order | Most-retrieved chunks first | Arbitrary order | Most queries benefit early; protects the deadline |
| Consistency | Dual-write from day 0 + versioned writes | Backfill then catch up from a change log | Simpler to reason about; no catch-up window |
| Validation | Golden set + shadow + canary | Leaderboard scores | Your data and queries decide |
| Old index | Kept warm two weeks | Delete at cutover | Instant rollback for the cost of storage |
| Stopgap | None | Learned mapping from new to old vector space | Lossy; only worth it if re-embedding is truly impossible |
Build first: versioned dual-write and the progress-tracked backfill, then the offline evaluation, then router and shadow comparison.
37–40 min Wrap-up and likely follow-ups
Close with: "Because vectors aren't comparable across models, I'd build v2 in parallel: turn on versioned dual-writes, backfill in checkpointed, rate-limited ranges starting with the most-retrieved chunks, reconcile counts, then validate with a segmented golden set, shadow traffic and a canary before ramping, keeping v1 warm for instant rollback."
Likely follow-ups:
- Can you avoid re-embedding? A learned linear mapping between spaces is possible but lossy; use it only as a short stopgap.
- What about Matryoshka embeddings? Some models let you truncate dimensions with modest quality loss, which can cut storage in v2; evaluate the truncated size.
- How would you do this for a billion chunks? The same pattern, with GPU self-hosting for throughput, IVF-PQ or disk-based indexes, and a longer plan with partition-level cutover.
- How do you know the backfill finished correctly? Partition-level counts, ID and version sampling across the document store, v1 and v2, and an evaluation run on the full index.
What interviewers listen for
- Knowing vectors aren't comparable across models.
- A parallel-index plan with dual-writes, versioning and reconciliation.
- Throughput and cost numbers for the backfill.
- Validation segmented by query type, and an instant rollback path.
Red flags
- "Re-embed new documents with the new model and leave the rest."
- Switching all traffic at once without evaluation.
- No plan for changes that happen during the backfill.
Discussion
Help us improve our content — give feedback. Spotted an error, have a better explanation, or got asked a follow-up in a real interview? Share it here.