A re-embedding backfill dies at 60% — what must its progress record hold so a restart neither re-bills finished chunks nor mixes model versions?
answer
- progress per chunk, not per batch
- key carries the model revision
- write first, then count it done
- remaining work as a set difference
basics
~20 sOne record per chunk keyed by chunk ID and the exact pinned model revision, written only once the vector is durable, so a restart re-embeds just the chunks with no record at the new version.
solid answer
~40 sThe unit of progress is the chunk, not a batch number or a row offset. Each record is keyed by `chunk_id` plus the exact model revision pinned at the start, never a moving alias, and carries the hash of the text that was embedded and a status. Order matters: write the vector under `(chunk_id, model_version)` as an idempotent upsert, then count it done. A crash in between re-embeds at most the in-flight batch, harmlessly; marking done first leaves silent gaps. Best of all, the store is the ledger: remaining work is every current chunk ID with no record at the new version, so a restart is a set difference, not a resumed cursor. Rejected chunks get a record too, and workers partition by chunk ID so two of them never bill the same chunk.
code
pseudocode · 24 lines# Resumable re-embed worker (illustrative names)
PINNED = "embed-model-rev-2026-09" # resolved once, stored with the run
DIM = 1024
loop:
todo = current_chunks
where hash(chunk_id) mod WORKERS == ME
and no record exists for (chunk_id, PINNED) # vector or rejection
limit 500
if todo is empty: stop # this partition is done
resp = embed([c.text for c in todo], model = PINNED) # transient errors retried by the client
if resp.request_failed: # one bad input can fail the whole request
resend each half of todo separately, recursing into a failing half
until the failing chunk is alone; record it as rejected; continue
for item in resp.results: # each result carries its input index
c = todo[item.input_index]
if item.error:
put record (c.id, PINNED) {status: "rejected", reason: item.error}
else if length(item.vector) != DIM:
abort run "dimension drift" # wrong model behind the pin
else:
upsert vector (c.id, PINNED) {vector: item.vector, content_hash: c.hash, status: "embedded"}
# no separate 'done' mark: the record's existence is the progressgo deeper
Recall that progress must be tracked per chunk and tied to the model version, so finished chunks are skipped and old and new vectors are never mixed.
Explain the write order: vector written as an idempotent upsert first, done second, and what each order costs on a crash, a small re-bill versus a silent gap.
Show the set-difference resume, the record for rejected chunks that lets the loop end, partitioning across workers, and pinning a revision rather than an alias.
Argue for making the store the ledger instead of a separate checkpoint, and for keeping old vectors until cutover as the rollback, against the cost of the second copy.
## The failure this record exists for A whole-corpus **re-embedding backfill** runs for hours or days. Somewhere in that time a worker is redeployed, a node dies or a run of errors trips an alarm, and the job stops at, say, sixty percent. The restart has to do two things at once: **skip the chunks that already have a new-model vector**, so finished work is not billed again, and **never let two models' vectors sit together as if they were one**, because vectors from different models live in different spaces and cannot be compared. Whether a progress record achieves both depends on what it is keyed by and when it is written. (General checkpointing of long-running jobs, such as saving a training step's state, is covered with restartable job graphs; this is the per-chunk version for a re-embed.) ## Why a batch number or row offset is not enough - **Offsets drift.** The chunk table keeps changing while the job runs; a delete before position 12,000,000 shifts every later row, so "resume at row 12,000,000" skips some chunks and repeats others. - **Batches are not atomic.** A batch can be half-written when the worker dies; "batch 4,812 done" says nothing about which of its chunks landed. - **A job checkpoint forgets the model.** If the restart picks up a different model revision, a cursor resumes happily and mixes versions. ## What one entry holds | Field | Why it is there | |---|---| | `chunk_id` | the stable identity of the chunk, derived from its source document and position | | `model_version` | the exact, pinned model revision the vector came from, never a moving alias | | `content_hash` | a hash of the exact text sent, so a later check can tell whether the text changed since | | `status` | embedded, truncated or rejected, so a rejected chunk is a decision rather than a hole | | `written_at` | when the vector became durable, for auditing the run | The key is the pair `(chunk_id, model_version)`. Writing new vectors under that pair means an old-model vector and a new-model vector for the same chunk are two different records, and a query for one version can never see the other. ## Write order decides what a crash costs 1. Send the batch and receive its vectors. 2. Match each vector to its input by the index the response carries, not by assuming the order held. 3. **Write the vectors**, tagged with the model version, as an idempotent upsert on `(chunk_id, model_version)`. 4. Only then treat those chunks as done. A crash between steps 3 and 4 re-embeds at most the in-flight batch, and the upsert makes the duplicate harmless; that is the bounded re-bill. The opposite order, **marking done first**, turns a crash into chunks recorded as finished that have no vector, a silent gap that only a completeness check will find. ## Let the store be the ledger The cleanest design keeps no separate cursor at all. The remaining work is a **set difference**: every current chunk ID minus the chunk IDs that already have a record at the new version. A restart recomputes that set and carries on, whatever killed the previous run. Two details keep it honest: - **Rejected and truncated chunks get a record too**, or they reappear in the work list on every restart and the job never finishes. - **Workers partition the work**, for example by a hash of the chunk ID modulo the worker count, or two workers that both ask for "the next 500 missing chunks" embed and bill the same ones. ## Keeping versions apart - **Pin the revision.** Where a provider offers a moving "latest" alias, resolve it once, record the exact revision, and configure every worker with it. An alias repointed mid-run would write a second model's vectors under the first one's tag. - **Check the shape on restart.** A vector whose dimension differs from the run's expected dimension means a configuration drift; stop rather than write it. - **Keep the old vectors.** They keep serving queries until the cutover, and they are the rollback. Edits that land in the source while the backfill runs are a separate catch-up problem, covered with shadow reindexing; this record only guarantees that the chunks the job set out to embed are each embedded once, under one model.
- Why is resuming a re-embed from the last processed row offset unsafe over a live chunk table?Inserts and deletes before the offset shift every later row, so the restart skips some chunks and re-embeds others. Resume from something stable instead: an ordering on the chunk ID itself, or better, the set of current chunk IDs that still have no record at the new model version, which stays correct whatever the table did in between.
- What goes wrong if every re-embed worker is configured with a provider's moving 'latest' model alias?If the alias is repointed during the run, later vectors come from a different model but carry the same version tag, so one index silently holds two incomparable vector spaces. Resolve the alias once, record the exact revision, configure every worker with it, and treat a dimension or sample mismatch on restart as a reason to stop.
- What should the progress record do with a chunk the new model rejects?Record it at the new version with a rejected or truncated status and the reason. Without that record the set difference keeps returning the chunk, the job never finishes, and each restart pays for the same failing call. The record also turns the rejection into something a completeness check can count and someone can decide on.
Relabelling a warehouse for a new catalogue system: you tick a box off the list only after its new label is stuck on, and the label says which catalogue it belongs to. Tick first, and a box dropped on the way is marked done but never labelled.
- Checkpoint the batch number; per-chunk records are overkill.
- Mark a batch done as soon as its request is sent, so a crash never re-bills it.
- Recording the model's name is enough; the exact revision does not matter.
- Overwrite old vectors in place so there is only one copy to track.
- A restart that finishes without errors proves nothing was skipped.