Table of Contents
Fetching ...

Dynamically Detect and Fix Hardness for Efficient Approximate Nearest Neighbor Search

Zhiyuan Hua, Qiji Mo, Zebin Yao, Lixiao Cui, Xiaoguang Liu, Gang Wang, Zijing Wei, Xinyu Liu, Tianxiao Tang, Shaozhi Liu, Lin Qu

TL;DR

This work tackles the challenge of hard queries in graph-based ANNS, particularly under cross-modal OOD conditions, by introducing Escape Hardness (EH) to quantify local graph difficulty around a query and by proposing two dynamic graph-refinement modules: NGFix for vicinity connectivity and RFix for navigability from the entry point. The methods leverage historical queries to selectively fix defective regions of the graph, yielding large gains in recall-sensitive performance and significantly faster index construction compared to RoarGraph and HNSW, especially for hard OOD queries. The approach is supported by theoretical insights linking EH to upper bounds on required search list sizes and by extensive experiments across four cross-modal and two single-modal datasets, demonstrating robustness to query similarity and workload drift. Practical benefits include improved query speed for hard queries, reduced dependence on large historical-query sets, and efficient maintenance under insertion and deletion workloads, with optional use of approximate kNN to accelerate preprocessing.

Abstract

Approximate Nearest Neighbor Search (ANNS) has become a fundamental component in many real-world applications. Among various ANNS algorithms, graph-based methods are state-of-the-art. However, ANNS often suffers from a significant drop in accuracy for certain queries, especially in Out-of-Distribution (OOD) scenarios. To address this issue, a recent approach named RoarGraph constructs a bipartite graph between the base data and historical queries to bridge the gap between two different distributions. However, it suffers from some limitations: (1) Building a bipartite graph between two distributions lacks theoretical support, resulting in the query distribution not being effectively utilized by the graph index. (2) Requires a sufficient number of historical queries before graph construction and suffers from high construction times. (3) When the query workload changes, it requires reconstruction to maintain high search accuracy. In this paper, we first propose Escape Hardness, a metric to evaluate the quality of the graph structure around the query. Then we divide the graph search into two stages and dynamically identify and fix defective graph regions in each stage based on Escape Hardness. (1) From the entry point to the vicinity of the query. We propose Reachability Fixing (RFix), which enhances the navigability of some key nodes. (2) Searching within the vicinity of the query. We propose Neighboring Graph Defects Fixing (NGFix) to improve graph connectivity in regions where queries are densely distributed. The results of extensive experiments show that our method outperforms other state-of-the-art methods on real-world datasets, achieving up to 2.25x faster search speed for OOD queries at 99% recall compared with RoarGraph and 6.88x faster speed compared with HNSW. It also accelerates index construction by 2.35-9.02x compared to RoarGraph.

Dynamically Detect and Fix Hardness for Efficient Approximate Nearest Neighbor Search

TL;DR

This work tackles the challenge of hard queries in graph-based ANNS, particularly under cross-modal OOD conditions, by introducing Escape Hardness (EH) to quantify local graph difficulty around a query and by proposing two dynamic graph-refinement modules: NGFix for vicinity connectivity and RFix for navigability from the entry point. The methods leverage historical queries to selectively fix defective regions of the graph, yielding large gains in recall-sensitive performance and significantly faster index construction compared to RoarGraph and HNSW, especially for hard OOD queries. The approach is supported by theoretical insights linking EH to upper bounds on required search list sizes and by extensive experiments across four cross-modal and two single-modal datasets, demonstrating robustness to query similarity and workload drift. Practical benefits include improved query speed for hard queries, reduced dependence on large historical-query sets, and efficient maintenance under insertion and deletion workloads, with optional use of approximate kNN to accelerate preprocessing.

Abstract

Approximate Nearest Neighbor Search (ANNS) has become a fundamental component in many real-world applications. Among various ANNS algorithms, graph-based methods are state-of-the-art. However, ANNS often suffers from a significant drop in accuracy for certain queries, especially in Out-of-Distribution (OOD) scenarios. To address this issue, a recent approach named RoarGraph constructs a bipartite graph between the base data and historical queries to bridge the gap between two different distributions. However, it suffers from some limitations: (1) Building a bipartite graph between two distributions lacks theoretical support, resulting in the query distribution not being effectively utilized by the graph index. (2) Requires a sufficient number of historical queries before graph construction and suffers from high construction times. (3) When the query workload changes, it requires reconstruction to maintain high search accuracy. In this paper, we first propose Escape Hardness, a metric to evaluate the quality of the graph structure around the query. Then we divide the graph search into two stages and dynamically identify and fix defective graph regions in each stage based on Escape Hardness. (1) From the entry point to the vicinity of the query. We propose Reachability Fixing (RFix), which enhances the navigability of some key nodes. (2) Searching within the vicinity of the query. We propose Neighboring Graph Defects Fixing (NGFix) to improve graph connectivity in regions where queries are densely distributed. The results of extensive experiments show that our method outperforms other state-of-the-art methods on real-world datasets, achieving up to 2.25x faster search speed for OOD queries at 99% recall compared with RoarGraph and 6.88x faster speed compared with HNSW. It also accelerates index construction by 2.35-9.02x compared to RoarGraph.
Paper Structure (22 sections, 6 theorems, 1 equation, 21 figures, 1 table, 4 algorithms)

This paper contains 22 sections, 6 theorems, 1 equation, 21 figures, 1 table, 4 algorithms.

Key Result

THEOREM 1

For a directed graph index $G = (V, E)$ and a query $q$. If $N_{i,q}$ can reach $N_{j,q}$ in $NG_{S,q}$ ($1 \le i,j \le S$). The Algorithm beamsearch will always visit $N_{j,q}$ when query $=q$, $ep = N_{i,q}$ and $L \ge S$.

Figures (21)

  • Figure 1: Comparison between RoarGraph and Our Methods. (a) Example of RoarGraph. (b) Example of NGFix. (c) Query accuracy under same average latency in LAION10Mlaion and WebVid2.5Mwebvid.
  • Figure 2: (a) The two phases of Greedy Search on the graph. (b) The proportion of queries with different recall levels.
  • Figure 3: (a) A toy example of $NG_{5,q}$. (b) $NG_{30,q}$ of HNSW's base layer with two different OOD queries in LAION10M.
  • Figure 4: Randomly sampled 1000 ID queries and 1000 OOD queries in LAION10M. The graph index is the base layer of HNSW. (a) The correlation between query's recall@100 with a search list size of 100 and its average number of reachable points in $NG_{100,q}$. (b) Counts of queries with different average numbers of reachable points in $NG_{100,q}$.
  • Figure 5: An overview of Neighboring Graph Defects Fixing with $N_q = 4, K_h = 4$.
  • ...and 16 more figures

Theorems & Definitions (9)

  • DEFINITION 1
  • THEOREM 1
  • THEOREM 2
  • DEFINITION 2
  • COROLLARY 1
  • THEOREM 3
  • DEFINITION 3
  • THEOREM 4
  • THEOREM 5