Module 4 · Data and runtime infrastructure · Chapter 14 · Free
Embedding pipelines: ingestion, reindexing and versioning
- An embedding pipeline moves source documents through chunking, embedding calls and index writes, so search sees current content.
- Vectors from different embedding models do not mix in one index. A model change means a rebuild.
- The safe rebuild: a fresh index beside the old one, verified, then swapped in.
The picture: a conveyor to the index, queue depth as its pulse.
- The four pipeline stages, and chunking as an operational decision.
- Why a model change invalidates every old vector.
- Three reindex strategies and when each is safe.
- Idempotent ingestion, retries, dead letters, drift checks.
- A worked throughput calculation and a planning lab.
Copperline is a made up B2B SaaS company. Priya Nair, its staff platform engineer, upgraded the copilot's embedding model on a Friday, in place, one document at a time. All figures here are illustrative.
- By Monday the index held a mix: about 60 percent new vectors, 40 percent old ones.
- Ana, the support lead, watched answer quality slide. Good documents ranked below weak ones, with no error anywhere.
- Rollback took an illustrative 9 hours, because nobody could tell which vectors were which.
Nothing crashed. The index was quietly wrong, which is worse. This chapter is the rebuild that stops it happening again.
- The pipeline: sources, chunking, embedding, index writes.
- Model versioning: why old vectors become invalid.
- Reindex strategies: fresh build and swap, dual write, backfill.
- Safe ingestion: idempotency, retries, dead letters, drift checks.
- Throughput math and queue depth as the health signal.
- The picture, a worked example, and a reindex planning lab.
Next: the four stages every document passes through.
Step 1: The pipeline, from source document to searchable vector
Chapter 13 covered the vector database itself. This chapter covers the conveyor that feeds it. For retrieval basics, see RAG end to end in the AI engineering course.
- Source: help articles, product docs and release notes in the document store. The store is the truth; the index is derived.
- Chunk: each document is split into passages small enough to embed and return as evidence.
- Embed: each chunk goes to the embedding model, which returns a vector: numbers that place the chunk by meaning.
- Write: vectors plus chunk text and metadata go into the index, keyed by document and chunk ID.
Chunking is an operational step, not just a quality choice. Chunk size sets embedding call volume and re-embed cost when a paragraph changes. Priya's team re-chunks only the changed section.
Think of a warehouse conveyor: goods arrive, get boxed, labelled and shelved. Where the picture breaks down:
- Boxes stay put. Index entries must be replaced the moment the source changes.
- A mislabelled box is one bad item. A wrong model quietly misplaces everything.
Next: why the embedding model version is part of every vector's identity.
Step 2: Model versioning, why old vectors stop being valid
An embedding model defines a space: which texts land near each other, and how many numbers each vector has. A new model, even from the same provider, defines a different space.
- Different geometry: a chunk's neighbours under the old model are not its neighbours under the new one.
- Possibly different size: the new model may return a different dimension count, breaking the index schema.
- Queries change too: the query is embedded with the current model. A new model query against old vectors compares two different spaces.
So a mixed index is not half upgraded. It is two half indexes interleaved, and ranking across them is meaningless.
The fix is bookkeeping: stamp every vector, and the index, with the model version. The query path checks the stamp first. If stamps disagree, the request fails loudly instead of answering badly.
Next: three ways to rebuild, and the risk each one carries.
Step 3: Reindex strategies, fresh build, dual write, backfill
When the model changes, every chunk must be re-embedded. How do new vectors reach serving while the old index keeps answering?
- Fresh index and swap: build a complete new index beside the old one, verify it, then point traffic at it with an alias change. The old index stays as rollback. Cost: double storage during the build.
- Dual write: during migration, each change is embedded with both models and written to both indexes. Useful when the build takes days and sources keep changing. Cost: double embedding and write load throughout.
- Backfill in place: re-embed documents inside the live index, a batch at a time. Cheapest in storage, riskiest in practice: the index is mixed for the whole backfill, exactly the cold open failure.
Priya's default is fresh build and swap, with dual write added only when the build outlasts a source freeze. Backfill in place is reserved for tiny, low risk collections where a mixed window is acceptable.
Think of repainting a bridge: build a new span, paint both during a closure, or paint lane by lane under traffic. Where the picture breaks down:
- A half painted bridge still carries cars. A half migrated index returns wrong rankings.
- Switching an index is an alias change, seconds of work, not a road closure.
Next: making daily ingestion safe to retry, because pipelines fail mid flight.
Step 4: Idempotent ingestion, retries and dead letters
Between model changes, the pipeline runs daily. Workers crash, embedding calls time out, writes fail. The design question is what a retry does.
- Idempotent writes: each chunk write is keyed by document ID, chunk ID and content hash. Running the same job twice writes the same record twice, which is one record.
- Retries with backoff: a failed call retries a few times with growing waits. Most failures are brief: a rate limit, a blip.
- Dead letter queue: a chunk that still fails goes to a dead letter queue with its error attached, and an alert fires. The pipeline keeps moving. Nothing is silently dropped.
- Deletes travel too: a deleted source document sends a delete for all its chunks. A surviving stale chunk is a wrong answer waiting to happen.
Predict first:
A dropped chunk leaves no trace, so nobody knows which documents are missing until a user reports a bad answer. The dead letter queue is the record: what failed, why, and what to replay once the cause is fixed.
Next: how Priya proves the index still matches the source store.
Step 5: Drift checks, proving index and source still agree
Even a healthy pipeline drifts: a missed delete, a stuck consumer. Priya's team checks agreement at three depths.
- Counts: documents in the store versus documents in the index, chunks likewise. Cheap, runs hourly. A gap says something is wrong, not what.
- Checksums: hash each document's current content and compare with the hash stored at embed time. This finds edits that never re-entered the pipeline.
- Sampling: re-embed a random slice of documents and compare against the live index. This catches subtle faults counts and hashes miss, such as a wrong stamp.
Repair is simple: drifted documents go back through normal ingestion, with the same idempotent writes.
Next: the throughput math, and the one number that shows pipeline health.
Step 6: The picture, one document through the pipeline
Press Next to walk a changed article from store to index.
- An editor saves a help article. The store is the truth; everything downstream is a copy.
- Only changed sections are re-chunked. Each chunk gets an ID and a hash.
- Chunks queue for embedding. A growing queue is the first sign of falling behind.
- Each chunk is embedded by the current model, and the vector carries that stamp.
- Good chunks are written by key, so retries are safe. Repeat failures go to dead letters.
Next: the worked example, how fast the pipeline drains a backlog.
Step 7: Worked example, throughput through three stages
A help centre migration lands 12,000 documents in the queue at once. All figures are illustrative. The slowest stage sets the pace.
1. Chunk stage. The chunker handles an illustrative 2,000 documents per hour. Chunking alone: 12,000 / 2,000 = 6 hours.
2. Embed stage. Each document makes an illustrative 8 chunks, so 12,000 x 8 = 96,000 embedding calls, at an illustrative 12,000 calls per hour. Time: 96,000 / 12,000 = 8 hours.
3. Write stage. The index accepts an illustrative 20,000 chunk writes per hour. Time: 96,000 / 20,000 = 4.8 hours.
4. The pipeline rate. Stages run in parallel, so the backlog drains at the slowest stage: embedding, at 12,000 / 8 = 1,500 documents per hour end to end. Total time: about 8 hours.
5. The lesson. Adding chunker workers changes nothing. The queue before the embedding stage grows whenever arrivals beat 1,500 documents per hour.
Queue depth is the health signal: flat means keeping up, rising means a stage is saturated or down, a sudden jump means a bulk change landed. Chapter 16, "Caching and queues: semantic caches, backpressure and fair sharing", builds the discipline behind it.
Next: the lab, planning a real reindex on paper.
Step 8: Hands-on lab, plan a reindex
Why this exercise: a reindex is a planned migration, not an incident. Writing the plan first is what keeps an upgrade from becoming the cold open.
Lab: Priya is rehearsing the v2 to v3 reindex on a small event stream before the real build. This lab runs in your browser and needs JavaScript enabled.
- Every decision follows from a stated fact: dimensions, build time, live traffic, rollback.
- The plan spends storage and embedding calls to buy safety. Name that trade, do not hide it.
Next: a field note and the mix-ups.
In production practice, mature retrieval teams treat the embedding model like a schema version: recorded with the data, migrated by planned, verified builds, the old version kept until the new one has carried real traffic. Tooling varies by vector database, so confirm your alias features before promising a swap based rollback.
Mix-ups to avoid
- "A better model can replace the old one in place." New model, new space. Rebuild, then swap.
- "Chunking is a content team's problem." Chunk size sets embedding volume and re-embed cost. It is an operations knob.
- "Retries are safe if the job usually works." Retries are safe only when writes are idempotent. Check the keys.
- "Equal counts mean the index is correct." Counts miss stale content and wrong stamps. Add checksums and sampling.
- "A quiet pipeline is a healthy pipeline." Watch queue depth. Silence plus a rising queue is failure in progress.
Chapter quiz
Five questions, 70% to pass.
Review this chapter in 5 minutes
Watch the whole chapter recapped: source to index pipeline, model versioning, fresh build and swap reindexing, drift checks and throughput.
- Pipeline: source store, chunk, embed, write. The store is the truth; the index is a derived, rebuildable copy.
- A model change creates a new vector space. Mixed indexes rank meaninglessly.
- Default reindex: fresh index, verify, swap the alias, keep the old index as rollback. Dual write for long builds with live changes.
- Safe ingestion: idempotent writes keyed by document, chunk and hash; retries with backoff; dead letters with alerts; deletes propagate.
- Drift checks: counts, checksums, sampling. Throughput is set by the slowest stage; queue depth is the health signal.
Decision rule: treat the embedding model as a schema version: pin it, stamp it, rebuild beside the old index, not inside it.
Review
Glossary
- Embedding pipeline
- The conveyor from source documents to searchable vectors. Example: the nightly help centre sync.
- Chunking
- Splitting a document into passages for embedding. Example: one article, 8 chunks.
- Embedding model version
- The exact model that produced a vector, recorded with it. Example: vectors stamped v2.
- Vector space
- The geometry one model uses to place texts by meaning. Example: v2 neighbours differ from v3.
- Reindex
- Rebuilding an index from source, usually for a model change. Example: the weekend v3 build.
- Dual write
- Writing each change to old and new indexes during a migration.
- Idempotent write
- A write that can repeat without changing the result. Example: one chunk key, stored once.
- Dead letter queue
- Where repeatedly failing items wait, with their errors, for review.
- Drift
- Disagreement between the source store and the index. Example: an edited policy never re-embedded.
- Queue depth
- How many items wait at a pipeline stage. Example: a rising embed queue.
Next: "Agent runtimes in production: sandboxes, tool gateways and state".