HQANN: Efficient and Robust Similarity Search for Hybrid Queries with Structured and Unstructured Constraints

Wei Wu, Junlin He, Yu Qiao, Guoheng Fu, Li Liu, Jin Yu

Abstract

Modern retrieval systems increasingly require hybrid query capabilities, combining unstructured vector similarity search with structured attribute filtering. Traditional approaches, such as search-then-filter or filter-then-search, often suffer from low recall or high latency. This paper introduces HQANN, a novel framework that integrates structured constraints directly into the distance metric of proximity graph-based search. By employing a Fusion Distance Metric where attributes act as the dominant component, HQANN achieves up to 10x faster performance than state-of-the-art solutions while maintaining near-perfect recall on billion-scale datasets.

1. Introduction

In production environments like e-commerce and social media, search queries are rarely purely visual or textual. Instead, they are hybrid: "Find images similar to this product where the category is 'shoes' and the merchant is 'Store A'."

Standard Approximate Nearest Neighbor Search (ANNS) algorithms excel at finding similar vectors but struggle with these hard filters. Current systems typically adopt one of two sub-optimal strategies:

  1. Search-then-filter: The system retrieves the top-$k$ vector matches and then applies filters. If the filters are restrictive, the top matches may all be discarded, leading to poor recall.
  2. Filter-then-search: The system filters the dataset first and then performs a vector search on the remainder. This is computationally expensive, particularly for broad filters or massive datasets requiring extensive bitmap scans.

HQANN addresses these bottlenecks by treating structured and unstructured search as a unified task rather than disjoint steps.

2. The HQANN Framework

2.1 Fusion Distance Metric

The core innovation of HQANN is the Fusion Distance Metric. Rather than a two-step process, the framework incorporates attributes into the distance calculation used to construct and traverse proximity graphs (such as HNSW or NSG). The distance between two points is defined as:

$$Dist = w \cdot VectorDist + AttributeDist$$

2.2 Attribute Dominance and Navigation

A critical aspect of HQANN is Attribute Dominance. The authors intentionally set the AttributeDist to be significantly larger than the VectorDist. This weighting ensures that within the proximity graph, nodes sharing identical attributes are linked together first.

To preserve "navigation sense," the framework utilizes Manhattan distance for attributes. This allows the graph traversal to effectively "walk" toward nodes with more similar attributes before refining the search based on vector similarity. The resulting composite proximity graph naturally clusters nodes by attributes, allowing the search algorithm to perform filtering and vector search simultaneously in a single traversal.

3. Experimental Evaluation

3.1 Datasets and Setup

The authors evaluated HQANN across several high-profile benchmarks:

  • Public Datasets: GLOVE-1.2M, SIFT-1M, GIST-1M, and DEEP-1B. Random attribute constraints were generated to simulate real-world hybrid queries.
  • Production Dataset: A billion-scale merchandise dataset from Kuaishou, featuring millions of unique merchant IDs as attribute constraints.

3.2 Performance and Scalability

  • Speedup: HQANN demonstrated a 10x speedup over state-of-the-art hybrid solutions, including Milvus, Vearch, and Alibaba’s AnalyticDB-V, at equivalent recall levels.
  • Latency: On the GLOVE-1.2M dataset with thousands of constraints, HQANN achieved 99% recall@10 in just 50 microseconds.
  • Robustness: Unlike competing methods (such as NHQ), which often see performance degradation as attribute complexity increases, HQANN remains efficient. In fact, as constraints become narrower, HQANN becomes more efficient because the attribute-first navigation quickly prunes irrelevant branches of the graph.
  • Billion-Scale Success: On the Kuaishou merchandise dataset, HQANN reached 99.9% recall with a scale factor ($w$) of 0.25, proving its readiness for massive production environments.

4. Discussion and Future Work

HQANN is not a standalone graph algorithm but a flexible framework. It can be integrated into existing graph-based ANNS structures simply by swapping the distance function.

However, some considerations remain for deployment:

  • Hyperparameter Tuning: While $w=0.25$ proved effective in most tests, extremely high-dimensional attribute spaces may require specific tuning of the scale and bias terms.
  • Pre-processing: The framework assumes attributes are pre-processed into vectors or integers; the overhead for highly dynamic metadata was not the primary focus of this study.
  • Memory Constraints: As a graph-based approach, HQANN inherits the significant memory requirements typical of such indices at the billion-scale.

5. Conclusion

HQANN represents a significant shift in hybrid search methodology. By embedding structured constraints into the fundamental distance metric of proximity graphs, it eliminates the trade-offs between speed and recall that plague traditional filtering methods. Its ability to scale to billion-point datasets while providing a 10x performance boost makes it a compelling solution for modern, high-concurrency retrieval systems.

Summary updated

BibTeX
@inproceedings{wu2022hqann,
  author = {Wei Wu and Junlin He and Yu Qiao and Guoheng Fu and Li Liu and Jin Yu},
  title = {{HQANN: Efficient and Robust Similarity Search for Hybrid Queries with Structured and Unstructured Constraints}},
  booktitle = {ACM International Conference on Information and Knowledge Management},
  year = {2022},
}
Figure