TL;DR
Hierarchical Navigable Small World (HNSW) graphs are the industry standard for fast vector search, but they struggle with data deletions, often forcing developers to choose between slow queries or poor accuracy. This paper introduces SPatch, a novel deletion algorithm that treats graph search as a random walk to mathematically preserve the graph's "navigability" after a point is removed. The result is a method that maintains high recall and fast query speeds while being significantly faster and more memory-efficient than existing state-of-the-art alternatives.
The Challenge of Dynamic Data in HNSW
Approximate Nearest Neighbor (ANN) search is the engine behind Retrieval-Augmented Generation (RAG) and large-scale recommendation systems. HNSW is the most popular algorithm for this task because it builds a multi-layer graph that allows for lightning-fast "greedy" navigation to the nearest data points.
However, HNSW was designed primarily for static or insertion-only datasets. In the real world, data is dynamic: ads expire, seasonal inventory changes, and old document versions are deleted. Current ways to handle deletions in HNSW are fundamentally flawed:
- Tombstones: Marking a point as "deleted" but leaving it in the graph. This preserves accuracy but makes searches slower over time and wastes memory.
- No Patching: Simply removing the point. This often breaks the "paths" in the graph, causing search accuracy (recall) to plummet.
- Global Rebuilds: Periodically starting from scratch. This is prohibitively expensive for large datasets.
The authors sought a middle ground: a way to "patch" the hole left by a deleted point that is fast, keeps the graph navigable, and actually frees up memory.
Methods: Reframing Search as a Random Walk
The authors bridge the gap between practical heuristics and graph theory by reframing HNSW search as a Random Walk.
- The Softmax Walk: Instead of a "hard" greedy search (always moving to the absolute closest neighbor), they propose a "softmax walk" where the searcher moves to neighbors with a probability based on their distance. They empirically prove that this probabilistic walk behaves almost identically to standard HNSW search.
- The Star-Mesh Transform: Drawing from electrical network theory, the authors use the "star-mesh transform." This theorem states that if you remove a central node (the "star"), you can perfectly preserve the "hitting time" (the expected steps to reach a destination) by connecting all its former neighbors in a weighted clique (the "mesh").
- SPatch (Sparsified Patching): A full clique is too dense and would severely slow down the graph. SPatch calculates the theoretically ideal weights for these new connections and then performs deterministic sparsification—it only keeps the "top-$t$" heaviest edges. This keeps the graph sparse and fast while maintaining the essential pathways for search.
Experimental Setup & Key Insights
The authors evaluated SPatch on four standard 1-million-point benchmarks: classic computer vision datasets (SIFT & GIST) and modern text embeddings derived from MS MARCO (MPNet & MiniLM), representing typical RAG workloads.
A profound theoretical insight from this work is using hitting time as a proxy for recall. Preserving the "hitting time" of a random walk is an excellent proxy for maintaining search recall in a greedy graph. If the expected number of steps to get near a target remains the same, the search remains efficient. Furthermore, while some methods try to re-insert points globally to fix the graph, SPatch demonstrates that a mathematically grounded local update is sufficient if the right edge weights are applied. Finally, although the underlying theory relies on randomized sampling, a deterministic approach (picking the strongest edges) proved more stable and performant in practice.
Key Results
The authors tested a rigorous "mass deletion" scenario where 80% of the points were gradually removed from the datasets.
- Query Speed: SPatch was 2.5x to 3x faster than the "Tombstone" method because it physically removes nodes, reducing the number of traversals required during a search.
- Deletion Efficiency: SPatch is significantly faster to execute than alternatives like "FreshDiskANN" or "Global Reconnect." In some tests, competing global methods were up to 35x slower than SPatch.
- Memory Usage: Unlike tombstones, SPatch successfully frees memory as points are deleted, scaling down with the actual size of the dataset.
- Recall: SPatch maintained high recall across all datasets, significantly outperforming "No Patch" and "Local Reconnect" strategies.
Limitations and Future Work
- Hyperparameter Tuning: SPatch introduces a parameter ($\alpha$) that controls how many edges to keep in the patch. While the authors recommend a default value (usually 1.2), the optimal setting can vary slightly depending on the dataset's dimensionality and distribution.
- Greedy vs. Softmax Gap: While empirical results are strong, a small theoretical gap remains between the "Softmax Walk" (covered by the proofs) and the "Greedy Search" (used in industry).
- Connectivity Risks: In extreme cases involving very sparse graphs, local patching could theoretically lead to disconnected components. The authors argue HNSW's multi-layer structure makes this unlikely in practice, but future work could involve formal proofs regarding graph connectivity during mass deletions.
Summary updated