Fast Diverse Nearest Neighbor Search

Justin Y. Chen, Soham Nagawanshi, Shenghao Xie, Haike Xu, Alan Zhou, Samson ZhouNeurIPS 2026

TL;DR

When you search for shoes online, you don't want fifty nearly identical sneakers from the exact same seller—you want options from $k$ different sellers. Existing algorithms for this "diverse nearest neighbor search" hit a steep $\mathcal{O}(k^2)$ speed limit, grinding to a halt when $k$ gets into the hundreds. By borrowing a clever trick from World War II-era medical group testing, this paper shatters that quadratic barrier, making diverse search roughly $k$ times faster while letting engineers plug in whatever standard search engine they already use as a black box.

What Problem Does This Paper Address?

Nearest Neighbor Search (NNS) is the workhorse behind recommendation engines, image retrieval, and LLM vector databases: given a query point $q$, find the closest data points in a massive geometric space. Because exact search is agonizingly slow in high dimensions, we usually settle for $c$-Approximate Nearest Neighbor ($c$-ANN) search, which returns points within $c$ times the distance of the true closest match.

In the real world, however, closeness isn't enough—we need diversity. Imagine assigning every item in a database a "color" representing a category, like a seller ID or website domain. The $k$-diverse $c$-ANN problem asks for $k$ nearby points that all have distinct colors.

Historically, engineers had two flawed options:

  1. Fetch-and-filter: Retrieve $m \gg k$ standard nearest neighbors and filter out duplicates afterward. If one seller floods the local neighborhood around your query, you might have to scan nearly the entire dataset ($m = \Omega(n)$) just to find $k$ distinct colors.
  2. Diversity-aware graphs: Bake diversity rules directly into graph-based search indices (like DiskANN). While this avoids scanning everything, traversing dense, overlapping spatial neighborhoods to hunt for new colors incurs an $\mathcal{O}(k^2)$ multiplicative query time overhead. Recommending 500 diverse items? Prepare to wait.

Methods

Instead of modifying complex search indices from the inside out, the authors decouple spatial geometry from categorical diversity using a color bucketing framework that wraps around any standard $c$-ANN algorithm as a black box.

  • Randomized Color Sampling (via Group Testing): During WWII, Robert Dorfman realized you could find a few syphilitic soldiers among thousands by pooling blood samples rather than testing everyone individually. Here, the $k$ target colors closest to the query are the "positives," and closer, redundant points of the same color are "masks" hiding other colors. By creating $L = \mathcal{O}(k \log k)$ buckets, sampling each color into a bucket independently with probability $1/k$, and building a standard $c$-ANN index per bucket, each target color gets isolated from its closer competitors in at least one bucket with high probability!
Algorithm 1: Diversity search by color sampling
  • Dataset-Oblivious Expander Graphs: What if we need deterministic guarantees (zero chance of failure) without looking at the spatial layout of the data? If you relax the goal slightly—accepting $(1-\varepsilon)k$ distinct colors—the authors use unbalanced bipartite expander graphs to assign colors to buckets, preserving neighborhoods well enough to isolate most target colors.
  • Adaptive Segment Trees: For exact $k$-diverse deterministic search, static buckets hit a mathematical wall. To get around it, the authors build a segment tree over the $N$ total colors and dynamically route queries down the tree, interleaving spatial priority search with mutually disjoint color partitions conditioned on candidates found so far.

Datasets

The authors note that they evaluate their methods empirically on semi-synthetic and real-world datasets, though specific dataset names and configurations are not discussed in the provided pages of the paper.

Key Insights and Ideas

  • The Geometric "Masking" Connection to Coding Theory: Why did prior deterministic methods get stuck at $\mathcal{O}(k^2)$? The authors prove this isn't an algorithmic failure—it's an information-theoretic law! For any static, dataset-oblivious bucketing scheme to guarantee finding all $k$ colors, every color must appear in at least one bucket completely free of any $k-1$ competing colors that might sit closer to the query and "mask" it. In algebraic coding theory, this requires a $(k-1)$-disjunct matrix, which mathematically forces at least $\Omega\left(k^2 \frac{\log N}{\log k}\right)$ buckets.
  • Adaptivity Beats Static Bounds: Realizing that static deterministic designs are prisoner to extremal combinatorics is the "aha" moment that motivates their adaptive segment tree—by reacting to the dataset and query geometry on the fly, you dodge the coding-theoretic penalty completely.
  • Plug-and-Play Modularity: Because the framework treats $c$-ANN as an untouched oracle, any future breakthroughs in standard vector search (like faster HNSW or LSH variants) automatically translate to faster diverse search.

Key Results

Measured by multiplicative overhead on top of a single black-box $c$-ANN query (where $N$ is total colors and $c$ is the approximation factor):

Comparison of query time and space overheads against prior work
  • Sublinear Overhead in Euclidean Space: Their randomized algorithm achieves an $\mathcal{O}\left(k^{1 - 1/c^2 - o(1)} \log k\right)$ query time overhead with $\mathcal{O}(\log k)$ space overhead—beating prior $\tilde{\mathcal{O}}(k)$ LSH-based methods and actually scaling sublinearly in $k$.
  • Breaking the Quadratic Barrier in General Metrics: Randomized search drops query overhead from the state-of-the-art $\mathcal{O}(k^2)$ down to $\mathcal{O}(k \log k)$, while shrinking space overhead from $\mathcal{O}(k)$ to $\mathcal{O}(\log k)$.
  • Deterministic Speedups: Adaptive segment trees achieve exact deterministic recovery in $\mathcal{O}(k \log N)$ query overhead and $\mathcal{O}(\log N)$ space overhead. Relaxed $(k, \varepsilon)$-diverse deterministic search runs in $\mathcal{O}(k^{1+o(1)}\gamma)$ overhead.
  • Empirically, the authors report significantly faster search times and higher recall than state-of-the-art diversity search baselines, plus extensions to general diversity metrics (maximizing minimum pairwise distances).

Limitations and Future Work

While the provided pages focus on establishing theoretical bounds and algorithmic foundations rather than explicitly listing future directions, a clear trade-off emerges from their impossibility proof: if you want strict, zero-failure deterministic guarantees without adaptive routing, you cannot escape the $\Omega(k^2)$ bucket lower bound unless you compromise slightly on diversity via the $(1-\varepsilon)k$ relaxation. Additionally, the deterministic exact method trades dependence on $k^2$ for a logarithmic dependence on the total number of categories ($\log N$) in both time and space.

Summary updated

Abstract

In the $k$-diverse nearest neighbor search problem, the input is a dataset in which each point is assigned a color, and given a query $q$, the goal is to retrieve $k$ approximate nearest neighbors with distinct colors. This color diversity metric is highly essential for information retrieval tasks where results are required to have different categories, e.g., recommending products from different sellers. Previous state-of-the-art solution by Anand et al. [ICML 2025] constructs a diversity-aware graph to meet this requirement. However, they suffer from an $\mathcal{O}(k^2)$ multiplicative query time overhead, creating a computational bottleneck when $k$ is large. To break this barrier, we propose a novel color bucketing framework that selects a subset of colors in each bucket and instantiates an independent approximate nearest neighbor search algorithm on the corresponding points. Inspired by group testing, we provide a randomized color sampling scheme that achieves an $\mathcal{O}\left(k^{1-\frac{1}{c^2}-o(1)}\log k\right)$ overhead in Euclidean spaces and an $\mathcal{O}\left(k \log k\right)$ overhead in general metric spaces, where $c$ is the approximation factor, reducing a factor of $k$. In addition, the space usage to store the data structure matches or improves upon prior methods. Empirical results on semi-synthetic and real-world datasets demonstrate that our approach achieves significantly faster search times and higher recall compared to state-of-the-art diversity search baselines. Furthermore, we introduce a dataset-oblivious deterministic bucketing scheme using expander graphs for a relaxed diverse search problem that only requires $k(1-\varepsilon)$ colors. Here, dataset-oblivious means that the color bucket construction does not depend on the spatial configuration of the dataset. We then establish an $\Omega(k^2)$ lower bound on the number of buckets for any dataset-oblivious deterministic bucketing scheme that gives an \emph{exact} $k$-diverse solution. We subsequently circumvent this by a dataset-aware adaptive segment tree bucketing scheme with an overhead of only $\mathcal{O}(k \log N)$, where $N$ is the number of colors. As an extension of our results, we solve the problem with general diversity metric, where the goal is to maximize the minimum pair-wise distance of the $k$ solutions, and improve the query time.
BibTeX
@inproceedings{chen2026fast,
  author = {Justin Y. Chen and Soham Nagawanshi and Shenghao Xie and Haike Xu and Alan Zhou and Samson Zhou},
  title = {{Fast Diverse Nearest Neighbor Search}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=0NrAOwOmiN},
}
Figure