Efficient K-Nearest Neighbor Graph Construction Using MapReduce for Large-Scale Data Sets

Tomohiro Warashina, Kazuo Aoyama, Hiroshi Sawada, Takashi HattoriIEICE Trans. Information and Systems 2014 · DOI

Abstract

Constructing K-Nearest Neighbor Graphs (K-NNG) for large-scale datasets is a computationally intensive task, traditionally scaling at $O(n^2)$. While the NN-Descent algorithm provides an efficient heuristic for building approximate graphs, its direct porting to distributed frameworks like MapReduce often results in severe performance bottlenecks due to memory exhaustion at "hub" nodes and excessive network congestion from shuffling high-dimensional feature vectors. This paper presents a highly optimized distributed approach that redesigns the NN-Descent pipeline to minimize data transmission. By utilizing a four-stage MapReduce process and a compact vertex representation, the proposed method achieves a 5x speedup over naive implementations while maintaining over 90% recall on datasets containing tens of millions of points.

Introduction

A K-Nearest Neighbor Graph (K-NNG), where each vertex is connected to its $K$ most similar peers, serves as the backbone for recommendation engines, similarity searches, and clustering algorithms. As datasets grow to the scale of tens of millions of points, building these graphs becomes a significant challenge. The NN-Descent algorithm is a popular approximate solution designed for single machines with shared memory. However, in a distributed MapReduce environment, the "simple extension" of this algorithm fails to scale because it constantly shuffles bulky feature vectors (e.g., image descriptors) across the network during the neighbor-of-neighbor search phase.

Methodology: The Four-Stage Pipeline

To address the limitations of distributed NN-Descent, the authors propose a sophisticated four-stage MapReduce pipeline. This architecture replaces the monolithic shuffling of data with a more surgical approach to data movement, ensuring that only necessary information is transmitted between nodes.

The four-stage MapReduce pipeline designed to optimize data flow and minimize redundant calculations.

The pipeline consists of the following stages:

  1. CreateRevVertices: Generates reverse neighbor sets to identify which nodes consider a specific vertex a neighbor.
  2. CreateKVertices: Attaches essential metadata and specific "attribute tags" to vertices.
  3. CreateAdjVertices: Prepares candidate lists for the "neighbor-of-neighbor" search using only IDs and tags.
  4. UpdateKVertices: Performs the actual distance calculations and updates the graph structure.

Key Innovations in Data Efficiency

The primary innovation lies in the design of low-cost key-value pairs. In a naive setup, full feature vectors are passed through every stage of the MapReduce process. The authors instead designed a compact data format that uses unique IDs, pre-calculated distances, and three specific attribute tags ($a1, a2, a3$).

The optimized vertex data structure reduces the size of transmitted data by using IDs and attributes instead of full feature vectors.

By using this "small size" representation, feature vectors are only loaded from storage when a distance calculation is strictly required. This strategy effectively "de-bulks" the data sent to reducers, preventing the memory exhaustion typically caused by "hub" nodes (vertices that appear in many neighbor lists) and reducing overall network load by a factor of five.

Experimental Results

The researchers evaluated the system using a subset of the "80 million tiny images" dataset (up to 36.5 million images with 384-dimensional Gist vectors) and a controlled dataset of 10 million random vectors.

Key findings include:

  • Performance: The proposed method was approximately 5x faster than the simple extension of NN-Descent on 10 million vertices.
  • Accuracy: The system consistently achieved over 90% recall, finding the vast majority of true nearest neighbors even at massive scales.
  • Scalability: The framework demonstrated near-linear speedup as the cluster size increased to 127 nodes. Furthermore, the method scales with the number of neighbors ($K$) at roughly $O(K^{0.55})$, a significant improvement over the $O(K^{1.5 \sim 1.8})$ complexity of the original serial algorithm.

Conclusion

This research demonstrates that for large-scale distributed graph construction, the cost of data shuffling often outweighs the cost of computation. By implementing a more complex, multi-stage pipeline that prioritizes data efficiency and compact vertex representation, it is possible to build high-accuracy K-NNGs at a scale previously unattainable with standard distributed heuristics. Future work will focus on extending these optimizations to non-metric dissimilarity measures and exploring implementations in modern in-memory frameworks like Apache Spark.

Summary updated

BibTeX
@article{warashina2014efficient,
  author = {Tomohiro Warashina and Kazuo Aoyama and Hiroshi Sawada and Takashi Hattori},
  title = {{Efficient K-Nearest Neighbor Graph Construction Using MapReduce for Large-Scale Data Sets}},
  journal = {IEICE Trans. Information and Systems},
  year = {2014},
  doi = {10.1587/transinf.2014edp7108},
}
Figure