Sort Before You Prune: Improved Worst-Case Guarantees of the DiskANN Family of Graphs

Siddharth Gollapudi, Ravishankar Krishnaswamy, Kirankumar Shiragur, Harsh WardhanICML 2025

Graph-based Approximate Nearest Neighbor Search (ANNS) is the engine room of modern AI. Whether you are performing a semantic search through millions of documents or retrieving context for a Retrieval-Augmented Generation (RAG) pipeline, you are likely using a graph-based index like HNSW or DiskANN. While these tools are incredibly fast in practice, their theoretical "worst-case" guarantees have historically been loose.

A new paper from researchers at UC Berkeley and Microsoft Research India, titled "Sort Before You Prune: Improved Worst-Case Guarantees of the DiskANN Family of Graphs," bridges this gap. By looking closely at a seemingly minor implementation detail—sorting candidates before pruning them—the authors have significantly tightened the mathematical bounds for DiskANN and provided the first formal proof for why beam search works so well.

What Problem Does This Paper Address?

In ANNS, the goal is to find the $k$ points in a dataset $P$ closest to a query $q$. Graph-based methods achieve this by "walking" a navigation graph. Until recently, there were no strong "worst-case" guarantees for these walks. In other words, in the absolute worst possible arrangement of points, how far off could the algorithm be?

A 2023 breakthrough by Indyk & Xu introduced $\alpha$-reachable graphs, proving that DiskANN-style graphs could guarantee a specific approximation ratio. However, their analysis had three notable gaps:

  1. It treated all metrics the same, failing to exploit the specific geometric properties of Euclidean ($\ell_2$) distance, which is the most common metric in practice.
  2. It ignored a key step in the actual DiskANN code: sorting the candidate edges before pruning them.
  3. It only analyzed a simple greedy walk ($k=1$), whereas practitioners use beam search to find multiple neighbors ($k > 1$).

The Innovation: Sorted $\alpha$-Reachable Graphs

The authors' primary innovation is the formalization of the Sorted $\alpha$-reachable graph.

In the standard DiskANN pruning algorithm, a node $p$ evaluates a set of candidate neighbors and keeps an edge to $p'$ only if $p'$ is "closer enough" to $p$ than any existing neighbor. The authors realized that by explicitly sorting these candidates by distance to $p$ before pruning, the resulting graph gains a powerful "sorting property."

To prove tighter bounds, they utilized Semidefinite Programming (SDP) duality. By framing the search for the "worst-case arrangement of points" as an optimization problem, they demonstrated that the geometric constraints of Euclidean space prevent the worst-case scenario from being as severe as it is in general metric spaces.

Key Insights

  • Sorting is a Theoretical Superpower: Sorting is not just a heuristic for better organization; it structurally changes the graph. It ensures that a vertex always connects to closer points before farther ones, preventing the search algorithm from getting "stuck" too far from the true nearest neighbor.
  • Euclidean Geometry Matters: In a general metric space, the best provable approximation factor was $\frac{\alpha+1}{\alpha-1}$. For a typical $\alpha=2$, that’s a factor of 3. In Euclidean space, the authors improved this to $\frac{\alpha}{\alpha-1}$, which is a factor of 2—a massive 33% tighter bound.
  • Beam Search is Now Provable: Beam search (maintaining a "beam" of $L$ candidates) is the industry standard. This paper provides the first proof that beam search makes multiplicative progress toward the true $k$-nearest neighbors in every step, eventually converging to a high-quality solution in poly-logarithmic time.

Empirical Validation and Key Results

The researchers validated their theory using four diverse, high-dimensional datasets: OpenAI (2.3M vectors), SIFT1M (1M vectors), Wikipedia (35M passages), and SPACEV (100M points). The empirical results strongly aligned with the theoretical claims:

  • Better Graphs & Faster Builds: "Sorted" graphs were consistently 6% to 25% less dense than unsorted ones. Because the pruning is more effective, the algorithm spends less time processing redundant edges, making the index build 13% to 22% faster.
  • Higher Performance: The sorted indices achieved significantly higher Queries Per Second (QPS) at high recall levels compared to unsorted versions.
Recall vs QPS on Wikipedia dataset
  • Fewer Comparisons: The "Sorted" version used substantially fewer distance comparisons to reach the same recall targets, directly confirming that the sorting property leads to more efficient routing paths.
Recall vs Average Comparisons on Wikipedia dataset

Limitations and Future Work

While the paper significantly advances the theory of DiskANN, a few areas remain open for exploration:

  • The OpenAI Anomaly: On the OpenAI dataset, the "sorted" graph showed a slightly worse maximum approximation ratio in one specific test, even though its overall QPS and recall were better. The authors suggest this peculiar behavior warrants further study.
  • Other Metrics: The tighter bounds rely on Euclidean properties. Extending these "sorted" guarantees to other popular metrics like Cosine Similarity or Jaccard Similarity is a logical next step.
  • Intrinsic Dimension: The complexity bounds still depend on the "doubling dimension" of the dataset. If a dataset is truly "flat" and high-dimensional without any local structure, these guarantees become less effective.

Summary updated

BibTeX
@inproceedings{gollapudi2025sort,
  author = {Siddharth Gollapudi and Ravishankar Krishnaswamy and Kirankumar Shiragur and Harsh Wardhan},
  title = {{Sort Before You Prune: Improved Worst-Case Guarantees of the DiskANN Family of Graphs}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=JnXbUKtLzz},
}
Figure