Fast k-NN search

Ville Hyvönen, Teemu Pitkänen, Sotiris K. Tasoulis, Liang Wang, Teemu Roos, Jukka Corander · DOI

Abstract

Efficient index structures for fast approximate nearest neighbor queries are required in many applications such as recommendation systems. In high-dimensional spaces, many conventional methods suffer from excessive usage of memory and slow response times. We propose a method where multiple random projection trees are combined by a novel voting scheme. The key idea is to exploit the redundancy in a large number of candidate sets obtained by independently generated random projections in order to reduce the number of expensive exact distance evaluations. The method is straightforward to implement using sparse projections which leads to a reduced memory footprint and fast index construction. Furthermore, it enables grouping of the required computations into big matrix multiplications, which leads to additional savings due to cache effects and low-level parallelization. We demonstrate by extensive experiments on a wide variety of data sets that the method is faster than existing partitioning tree or hashing based approaches, making it the fastest available technique on high accuracy levels.

Introduction

Finding the "nearest neighbor" to a query point is a foundational task in machine learning, powering everything from recommendation engines to image retrieval. However, as data dimensionality grows, the "curse of dimensionality" makes exact search computationally prohibitive. Approximate Nearest Neighbor (ANN) algorithms trade a bit of accuracy for massive gains in speed.

Existing ANN methods generally fall into three categories: hashing-based (e.g., LSH), graph-based, and space-partitioning trees (e.g., k-d trees). While robust, these methods often struggle to reach high accuracy levels efficiently in high dimensions. Researchers have proposed a new approach called Multiple Random Projection Trees (MRPT) that significantly speeds up this process without sacrificing accuracy, particularly at high recall levels.

The MRPT Algorithm

The MRPT algorithm improves upon classic random projection (RP) trees through three key innovations:

  • Sparse Random Projections: Instead of using dense Gaussian vectors to project data, MRPT uses sparse vectors (mostly zeros). This provides a $\sqrt{d}$-fold speedup in projection math and reduces the memory footprint of the index.
  • Shared Projection Vectors: In a standard RP tree, every node has its own random vector. MRPT uses a single projection vector for all nodes at the same level of the tree. This allows the algorithm to use highly optimized "big matrix" multiplications during index construction and query time, taking advantage of modern CPU cache effects and vectorization.
  • Voting Search: This is the "secret sauce." Instead of just looking at all points in the leaves where a query point lands, MRPT tracks how many different trees a candidate point appears in. A point is only added to the final candidate set if it appears in at least $v$ trees. This "voting" effectively prunes the search space, focusing on points that are most likely to be true neighbors.

Experimental Evaluation

The authors evaluated MRPT against seven diverse datasets to ensure robustness across different domains, including GIST, SIFT, MNIST, Trevi, STL-10, and News.

Performance comparison on the GIST dataset (k=10), showing query time vs. recall.

As shown in the performance plots, MRPT consistently outperforms state-of-the-art tree and hashing-based methods. At 90% recall, MRPT is roughly 25–100 times faster than brute-force search across all real-world datasets. The method is particularly dominant at high recall levels (95%–99%). While graph-based methods might be faster at low recall, their performance often degrades more sharply than MRPT as the accuracy requirement increases.

Performance comparison on News and Trevi datasets (k=10).

Key Insights and Results

  • Voting Effectiveness: While sparse projections help, the voting scheme was the most significant contributor to query speed improvements. It allows the algorithm to reach high recall levels while performing far fewer exact distance evaluations.
  • Hardware Optimization: By sharing projection vectors across tree levels, the authors turned a tree traversal problem into a linear algebra problem. This allows the code to leverage optimized BLAS libraries, making it much faster than pointer-heavy tree implementations.
  • Scalability: MRPT was the fastest method in 14 out of 21 tested instances for recall $\ge 90\%$. It significantly outperformed established libraries like FLANN (randomized k-d trees) and FALCONN (LSH) on almost all high-dimensional datasets. The performance gap between MRPT and other methods widened as the dimensionality of the data increased.

Conclusion

MRPT represents a significant advancement in approximate k-NN search for high-dimensional data. By combining sparse projections with a novel voting scheme and hardware-conscious implementation, it provides a highly efficient solution for applications requiring high accuracy. Future work may address parameter tuning for specific data distributions and adapting the index for dynamic datasets.

Summary updated

BibTeX
@inproceedings{hyvonen2016fast,
  author = {Ville Hyvönen and Teemu Pitkänen and Sotiris K. Tasoulis and Liang Wang and Teemu Roos and Jukka Corander},
  title = {{Fast k-NN search}},
  booktitle = {IEEE BigData},
  year = {2016},
  doi = {10.1109/bigdata.2016.7840682},
}
Figure