Overview
TheHnswQueryParam class controls query-time parameters for HNSW (Hierarchical Navigable Small World) index searches. It allows you to trade off between search speed and accuracy.
Constructor
Parameters
Size of the dynamic candidate list during search. Larger values improve recall (accuracy) but slow down search. This is the primary tuning parameter for HNSW query performance.Typical range: 100-500 for most use cases. Higher values (500+) for maximum accuracy.
Search radius for range queries. When set to a value greater than 0, only results within this distance threshold will be returned. Default is 0.0 (disabled).
Force linear (brute-force) search instead of using the HNSW index. Useful for debugging or verifying index accuracy.
Whether to use refiner for the query. Refiners can improve accuracy by re-scoring candidates with higher-precision distance calculations.
Properties
ef
Size of the dynamic candidate list during HNSW search. Type:int
Examples
Basic HNSW query
High accuracy search
Fast search with lower accuracy
Range query
Force linear search
Performance Tuning
The
ef parameter should be at least as large as the number of results (k) you want to retrieve. Setting ef < k will limit your results.See Also
- HnswIndexParam - Index construction parameters for HNSW
- VectorQuery - Vector query class that uses these parameters