Graph-based Nearest Neighbor Search: From Practice to Theory

Liudmila Prokhorenkova, Aleksandr Shekhovtsov

Introduction

Graph-based approaches have empirically proven to be highly successful for Nearest Neighbor Search (NNS), consistently outperforming traditional methods in real-world applications. However, there has been a significant gap in our understanding of why they work so well. While Locality Sensitive Hashing (LSH) has long been the darling of theorists due to its provable guarantees, graph-based methods like Hierarchical Navigable Small World (HNSW) have lacked rigorous theoretical backing.

This paper provides the first rigorous theoretical analysis of graph-based NNS in the "dense" regime ($d \ll \log n$), where these algorithms are most effective in practice. The authors bridge the gap between empirical success and mathematical guarantees by proving how common heuristics—such as adding long-range "shortcut" edges and utilizing beam search—drastically improve search complexity.

The Problem: Bridging Theory and Practice

Nearest Neighbor Search is a cornerstone of modern machine learning, utilized in recommendation systems, pattern recognition, and more. Most existing theoretical work focuses on the "sparse" regime (high-dimensional data). However, real-world datasets often exhibit a low intrinsic dimension.

This paper tackles the "dense" regime, where the number of points $n$ is significantly larger than the complexity of the dimensionality $d$. The authors aim to quantify the time and space complexity of these algorithms and provide a theoretical explanation for the benefits of the practical "tricks" used to accelerate them.

Methods and Modeling

To analyze these algorithms, the authors model the problem by assuming data points are uniformly distributed on a $d$-dimensional unit sphere. They break down the NNS process into three main analytical components:

1. Greedy Search on Plain NN Graphs

They establish a baseline complexity for a simple greedy walk, where the algorithm iteratively moves to the neighbor closest to the query point.

Greedy search path on a nearest neighbor graph

Inspired by Kleinberg’s "small-world" model, the authors analyze the impact of adding edges between distant nodes. They propose a dimension-independent method to sample these edges based on the rank of neighbors rather than their physical distance. This crucial adaptation makes the approach applicable to general, real-world datasets.

Instead of tracking only a single "best" candidate during the search, beam search maintains a dynamic list of $L$ candidates. The authors rigorously analyze how this strategy prevents the search from getting trapped in local optima and allows the underlying graph to function effectively with lower degrees.

Key Insights and Results

The authors validate their theoretical findings using both synthetic datasets ($10^6$ points uniformly distributed on spheres with dimensions $d \in \{2, 4, 8, 16\}$) and well-known real-world benchmarks (SIFT, GIST, GloVe, and DEEP).

The Regime Shift

In the "sparse" regime ($d \gg \log n$), the search converges in very few steps, meaning the computational cost is dominated by the number of neighbors checked per step. Conversely, in the "dense" regime ($d \ll \log n$), the number of steps becomes the primary bottleneck. For this dense regime, the authors prove a baseline time complexity of $\Theta(d^{1/2} \cdot n^{1/d} \cdot M^d)$.

The Power of Shortcuts

Adding edges uniformly at random does not yield asymptotic improvements. However, if long-range edges are added following a specific power-law distribution (based on distance or rank), the number of search steps drops dramatically from $n^{1/d}$ to $O(\log^2 n)$. They prove that adding just one properly distributed long-range edge per node is sufficient to achieve this $O(\log^2 n)$ step bound.

Beam Search as a Degree Reducer

Theoretically, beam search is not merely about finding a better neighbor; it allows the graph to maintain much lower degrees (fewer edges per node) while still guaranteeing that the search finds the exact nearest neighbor. The authors show that beam search can reduce the main term of time complexity from $2^{d/2}$ to $(27/16)^{d/2}$, representing a significant exponential improvement in higher-dimensional contexts.

Performance comparison of kNN search variants across different dimensions

Uniformization Matters

The authors demonstrate that real-world datasets, which are often non-uniform, can be pre-processed using a technique called DIM-RED. This makes the data behave more like the "dense uniform" model, significantly boosting the performance of simple graph-based algorithms. Impressively, on the GIST dataset, a simple k-NN graph combined with DIM-RED pre-processing and long-range links outperformed the state-of-the-art HNSW algorithm.

Limitations and Future Work

The primary limitation of this theoretical framework is its reliance on the uniform distribution assumption. While the authors provide a "uniformization" trick to adapt real data to the model, a rigorous mathematical analysis of non-uniform distributions—where density varies across the space—remains an open challenge.

Additionally, the paper does not fully explore "diversification," a heuristic heavily used in HNSW to select neighbors that are not only close but also spatially spread out. The authors suggest that analyzing the effect of diversification on search pruning is a highly promising direction for future research.

Summary updated

BibTeX
@inproceedings{prokhorenkova2020graph,
  author = {Liudmila Prokhorenkova and Aleksandr Shekhovtsov},
  title = {{Graph-based Nearest Neighbor Search: From Practice to Theory}},
  booktitle = {International Conference on Machine Learning},
  year = {2020},
  url = {https://openreview.net/forum?id=XpmpLVyhkpO},
}
Figure