advanced24 min studyLesson 657 in Engineering

Keep logical documents correct while index bytes change

Separate stable document identity, logical deletion, physical removal, delta overlays, and rebuild cutovers.

On this page

What you’ll understand

  • Trace replacement and deletion across a base-plus-delta design.
  • Distinguish logical visibility from reclaimed memory and graph repair.
  • Define a watermark that makes rebuild replay complete.

Retrieval indexes rarely contain a permanently frozen corpus. Documents are corrected, removed, re-embedded, and replaced while queries continue. The central correctness question is which logical document version a query is allowed to return. Physical index entries are only one representation of that decision: a tombstoned vector can remain in memory, and two entries can represent different versions of one document. Design the visibility and version rules before choosing an update API, because a fast insertion path alone does not ensure that a query stops seeing the superseded embedding.

Stable IDs are different from array positions

A document ID should survive physical compaction and index rebuilding. Some flat index removal operations shift implicit positions, whereas IVF variants can store explicit IDs; Faiss documents these differences and the direct-map restrictions for supported removals. Applications that treat a shifting ordinal as a stable business key can accidentally attach one vector’s score to another document’s text. Keep the document-to-vector mapping explicit and verify it after mutation, not only after the initial build.

Deletion support also differs across graph implementations. The Faiss HNSW family documented in its index guide does not support removing vectors in the same way as its removable flat or IVF indexes. hnswlib 0.8.0 supports mark_deleted, omitting that label from results, and optional replacement of deleted slots under its initialization contract. Marking an item invisible is not equivalent to reclaiming all adjacency storage, rebuilding navigation, or erasing every copy in a surrounding service.

v∗(i,w)=max⁡{v:(i,v) is committed at watermark w}v^*(i,w)=\max\{v:(i,v)\text{ is committed at watermark }w\}
i is a stable logical document ID, v is an application-ordered version, and w identifies a consistent ingestion boundary. The maximum is defined only for a nonempty committed-version history; an empty history means absent or not yet created at w. This expression requires an application-defined comparable version order; it is not an ANN-library timestamp or an arbitrary wall-clock maximum. A winning tombstone means the logical document is absent.↔ Scroll wide equations horizontally.

Merge a base and a delta with a visibility rule

One design keeps an immutable base snapshot and a smaller mutable delta. A version map says which physical entry is current, and tombstones suppress deleted IDs. Query both structures, discard entries inconsistent with the chosen visibility boundary, deduplicate logical IDs, then rank the remaining candidates using comparable scores. Merely taking k entries from each physical structure can leave fewer than k valid logical documents after stale versions are removed, so the candidate and fallback policy must address that loss.

Correct visibility still does not imply exact nearest-neighbor completeness. A stale entry can consume a local candidate slot before being discarded, hiding a valid farther entry. Overfetching reduces this risk but does not generally certify an exact answer. For an exact proof, obtain sufficient valid local results or use an exhaustive eligible fallback under the same snapshot. In an ANN service, measure recall after all version suppression and deduplication rather than reporting the earlier physical-entry recall.

Nlive=Nbase IDs+Nnew IDs−Ndeleted base IDsN_{\rm live}=N_{\rm base\ IDs}+N_{\rm new\ IDs}-N_{\rm deleted\ base\ IDs}
This count assumes the delta’s updates to existing base IDs replace rather than add logical documents, new IDs are distinct and live, and the stated deletion set contains only base IDs. Physical entry count and memory usage can be larger than Nlive.↔ Scroll wide equations horizontally.

Rebuild from a complete boundary

A rebuild can compact deleted entries, retrain coarse or PQ codebooks, or repair graph quality under the current distribution. Choose a source snapshot and record its ingestion watermark. If writes continue during the build, replay every later change in a defined order or use a coordinated snapshot-and-log mechanism, then verify the final coverage boundary before promotion. A snapshot copied without its log boundary cannot prove whether a concurrent update was included, omitted, or applied twice.

Test updates adversarially: replace the nearest document, delete it, reinsert its stable ID with a newer version, and query while the base and delta overlap. Check both returned text versions and scores. Preserve the old snapshot and its compatible delta state long enough for the declared rollback policy. A pointer back to old vector bytes alone may resurrect deleted documents if current visibility or replay state is not carried into the rollback design.

Three physical changes produce two live documents

The base contains A version 1 at vector 0 and B version 1 at vector 10. A delta contains A version 2 at vector 3, a tombstone for B version 2, and new C version 1 at vector 5. All changes are committed at watermark w. Query q=4 in one dimension.

  1. Resolve versions by stable ID: A version 2 suppresses base A version 1, B’s version 2 tombstone suppresses base B, and C is a new live ID. The live population is {A v2,C v1}, not every physical record across the two structures.

  2. Score only current live vectors: A has squared distance (4−3)²=1 and C has squared distance (4−5)²=1. Use the declared ascending-ID tie rule to return A before C; B is absent regardless of its physical entry.

  3. Count logical documents with the scoped formula: 2 base IDs +1 new ID −1 deleted base ID=2. Updating A adds a physical delta entry but contributes zero additional logical IDs. A rebuild storing only the two live vectors preserves the same answer.

The result

The answer has two unique live documents and no stale versions. Physical compaction can change storage layout while the stable-ID and watermark contract preserves this logical result.

Explore the model

Interactive lab

Interactive lab · queue

Rebuild catch-up needs service capacity

Reset, set Arrival rate λ to 2 and Service rate μ to 3. Predict initial backlog 4 and backlog 3.5 after one Step of 0.5 seconds. Reset, set λ to 4 and μ to 3, predict backlog 4.5 after Step. The deterministic fluid model clips backlog at zero and is only an ingestion catch-up analogy; it does not implement replay, versions, or index mutation.

Rebuild catch-up needs service capacityFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA replay path that permanently ingests faster than it applies cannot catch up under this simple constant-rate model.

Check your understanding

What does a graph API’s logical delete necessarily establish?

Try it yourself

A base has 100 unique live IDs. A delta replaces 12 of those IDs, deletes 8 different base IDs, and adds 5 new live IDs. Under the lesson’s assumptions, find the final logical live count and explain why 125 is wrong.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Replacements do not create additional logical IDs, and tombstones remove IDs from visibility.

Compare with the solution

The final logical count is 100+5−8=97. The 12 replacements change versions without increasing the population. Adding every physical operation gives 100+12+8+5=125, but that treats replacement entries and tombstones as additional live documents; it counts storage records instead of the logical eligible corpus.

Take it with you

  • Stable IDs and version visibility define update correctness.
  • Logical deletion does not automatically reclaim or repair an index.
  • A rebuild needs a snapshot boundary and complete change replay.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.