Deletes leave tombstoned nodes in the graph (still traversed, filtered from results). Heavy churn bloats memory, slows queries, and degrades recall.
Imagine a phone book where every entry is connected by little arrows to a few similar entries. When someone moves out, you do not actually rip the page out (that would shred all the arrows pointing to that page and you'd have to redraw them). Instead, you put a sticker on their entry that says 'gone'. People searching the phone book still wander past their entry, follow their arrows for a few hops, then realize the entry is marked and move on. The book gets thicker with stickered entries over time, paths get muddled, and eventually a librarian has to sit down and rebuild the whole book to make searches fast again.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
HNSW is a beautifully simple data structure when the corpus is static. The complications come from how it handles change. The standard HNSW build algorithm assumes you have all the vectors in hand and constructs the graph in one pass. Real production indexes never have that luxury: documents arrive, get updated, get deleted, embedding models change. How HNSW handles those changes determines whether the index degrades silently or stays healthy.
This question is about a specific failure mode that does not appear in academic ANN benchmarks (which are static) but bites every production HNSW deployment eventually.
Why deletes are tombstones
An HNSW graph stores, for each node, a list of M neighbors per layer. Deleting a node means removing it from every neighbor list that mentions it. With M = 32 neighbors per layer and 2-3 layers per node on average, that is 64 to 96 incoming-edge references to find and repair for each deletion. Worst case, repairing requires a scan; with a reverse-index it is bounded, but the repaired neighbors then need new neighbors to replace the deleted one, which triggers more partial rebuilds.
Doing this synchronously on every delete kills write throughput. So every production HNSW implementation uses tombstones: a 1-bit-per-node flag that says 'logically deleted, do not return in results'. The node, its vector, and its edges remain in memory and remain part of the graph. Searches still traverse through tombstoned nodes; they are filtered only at the top-K collection step before returning to the caller.
This trades O(1) per-delete cost for deferred maintenance. Every tombstone is a small lien against future compaction. Without compaction, the liens accumulate until the graph degrades.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Operation | What HNSW does internally | Visible cost |
|---|---|---|
| Delete | Sets tombstone bit; node stays in graph | RAM and traversal cost until compaction |
| Update | Tombstones old, inserts new with fresh edges | Doubles per-vector storage until compaction |
| Insert (no churn) | Standard HNSW build: pick M neighbors via greedy descent | Comparable to ground-up build cost per vector |
| Insert (heavy churn) | Picks neighbors from a graph polluted with stale nodes | Recall degradation over time |
| Compaction / rebuild | Drop tombstones, repair edges, or build fresh graph | Expensive but restores all properties |
Real products, models, and research that use this idea.
- Pinecone runs continuous background optimization on managed indexes; users observe the effect on recall and memory without configuring the compaction directly.
- Qdrant exposes `optimizers_config.deleted_threshold` and related knobs; compaction triggers automatically when tombstone ratios cross those thresholds.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does graph quality degrade even with no deletes, just heavy inserts?
New inserts pick neighbors greedily from the existing graph; the greedy algorithm tends to over connect to high degree nodes (hub formation). Periodic rebuild rebalances the degree distribution.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Assuming HNSW deletes are free because they don't change the graph structure. Tombstones are cheap to write but expensive to live with, they cost RAM and traversal hops on every query forever, until you rebuild.
60 second bullets to scan on the way to the call.
Tombstone mechanism: logical delete, physical node persists
Update = tombstone-old + insert-new (no in place update)
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.