Skip to content

Commit 11c2141

Browse files
committed
feat: Add runtime parameter support for HNSW and SVS-VAMANA vector indexes
Add comprehensive runtime parameter support for HNSW and SVS-VAMANA vector indexes across VectorQuery, VectorRangeQuery, and AggregateHybridQuery classes. Runtime parameters allow users to tune search performance at query time without rebuilding indexes, enabling dynamic trade-offs between accuracy and speed. Changes: - Add HNSW runtime parameters: ef_runtime, epsilon - Add SVS-VAMANA runtime parameters: search_window_size, epsilon, use_search_history, search_buffer_capacity - Implement setter methods with validation for all parameters - Add runtime parameter constants to BaseVectorQuery and AggregateHybridQuery - Update query string generation to include runtime parameters - Fix type annotation for params dict in AggregateHybridQuery Documentation: - Update API reference docs (query.rst, schema.rst) - Add runtime parameters section to SVS-VAMANA tutorial (09_svs_vamana.ipynb) - Add runtime parameters section to advanced queries tutorial (11_advanced_queries.ipynb) - Add runtime parameters notes to getting started and hybrid queries tutorials - Update README.md with ef_runtime example Tests: - Add tests for runtime parameters across all query types - Test parameter validation and error handling - Test query string generation with runtime parameters - Test parameter combinations
1 parent d1f4e76 commit 11c2141

File tree

11 files changed

+1328
-86
lines changed

11 files changed

+1328
-86
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ Define queries and perform advanced searches over your indices, including the co
190190
query = VectorQuery(
191191
vector=[0.16, -0.34, 0.98, 0.23],
192192
vector_field_name="embedding",
193-
num_results=3
193+
num_results=3,
194+
# Optional: tune search performance with runtime parameters
195+
ef_runtime=100 # HNSW: higher for better recall
194196
)
195197
# run the vector search query against the embedding field
196198
results = index.query(query)

docs/api/query.rst

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,51 @@ VectorQuery
2020
:show-inheritance:
2121
:exclude-members: add_filter,get_args,highlight,return_field,summarize
2222

23+
.. note::
24+
**Runtime Parameters for Performance Tuning**
25+
26+
VectorQuery supports runtime parameters for HNSW and SVS-VAMANA indexes that can be adjusted at query time without rebuilding the index:
27+
28+
**HNSW Parameters:**
29+
30+
- ``ef_runtime``: Controls search accuracy (higher = better recall, slower search)
31+
- ``epsilon``: Range search approximation factor (for range queries)
32+
33+
**SVS-VAMANA Parameters:**
34+
35+
- ``epsilon``: Range search approximation factor
36+
- ``search_window_size``: Size of search window for KNN searches
37+
- ``use_search_history``: Whether to use search buffer (OFF/ON/AUTO)
38+
- ``search_buffer_capacity``: Tuning parameter for 2-level compression
39+
40+
Example with HNSW runtime parameters:
41+
42+
.. code-block:: python
43+
44+
from redisvl.query import VectorQuery
45+
46+
query = VectorQuery(
47+
vector=[0.1, 0.2, 0.3],
48+
vector_field_name="embedding",
49+
num_results=10,
50+
ef_runtime=150, # Higher for better recall
51+
epsilon=0.05 # For range search approximation
52+
)
53+
54+
Example with SVS-VAMANA runtime parameters:
55+
56+
.. code-block:: python
57+
58+
query = VectorQuery(
59+
vector=[0.1, 0.2, 0.3],
60+
vector_field_name="embedding",
61+
num_results=10,
62+
search_window_size=20,
63+
use_search_history='ON',
64+
search_buffer_capacity=30,
65+
epsilon=0.01
66+
)
67+
2368
2469
VectorRangeQuery
2570
================
@@ -34,6 +79,36 @@ VectorRangeQuery
3479
:show-inheritance:
3580
:exclude-members: add_filter,get_args,highlight,return_field,summarize
3681

82+
.. note::
83+
**Runtime Parameters for Range Queries**
84+
85+
VectorRangeQuery supports runtime parameters for controlling range search behavior:
86+
87+
**HNSW & SVS-VAMANA Parameters:**
88+
89+
- ``epsilon``: Range search approximation factor (default: 0.01)
90+
91+
**SVS-VAMANA Parameters:**
92+
93+
- ``search_window_size``: Size of search window
94+
- ``use_search_history``: Whether to use search buffer (OFF/ON/AUTO)
95+
- ``search_buffer_capacity``: Tuning parameter for 2-level compression
96+
97+
Example:
98+
99+
.. code-block:: python
100+
101+
from redisvl.query import VectorRangeQuery
102+
103+
query = VectorRangeQuery(
104+
vector=[0.1, 0.2, 0.3],
105+
vector_field_name="embedding",
106+
distance_threshold=0.3,
107+
epsilon=0.05, # Approximation factor
108+
search_window_size=20, # SVS-VAMANA only
109+
use_search_history='AUTO' # SVS-VAMANA only
110+
)
111+
37112
HybridQuery
38113
================
39114

@@ -52,6 +127,41 @@ HybridQuery
52127
For index-level stopwords configuration (server-side), see :class:`redisvl.schema.IndexInfo.stopwords`.
53128
Using query-time stopwords with index-level ``STOPWORDS 0`` is counterproductive.
54129

130+
.. note::
131+
**Runtime Parameters for Hybrid Queries**
132+
133+
AggregateHybridQuery (and the deprecated HybridQuery) support runtime parameters for the vector search component:
134+
135+
**HNSW Parameters:**
136+
137+
- ``ef_runtime``: Controls search accuracy for the vector component
138+
- ``epsilon``: Range search approximation factor
139+
140+
**SVS-VAMANA Parameters:**
141+
142+
- ``epsilon``: Range search approximation factor
143+
- ``search_window_size``: Size of search window for KNN searches
144+
- ``use_search_history``: Whether to use search buffer (OFF/ON/AUTO)
145+
- ``search_buffer_capacity``: Tuning parameter for 2-level compression
146+
147+
Example:
148+
149+
.. code-block:: python
150+
151+
from redisvl.query import AggregateHybridQuery
152+
153+
query = AggregateHybridQuery(
154+
text="search query",
155+
text_field_name="description",
156+
vector=[0.1, 0.2, 0.3],
157+
vector_field_name="embedding",
158+
alpha=0.7,
159+
ef_runtime=150, # HNSW parameter
160+
epsilon=0.05, # HNSW & SVS-VAMANA
161+
search_window_size=20, # SVS-VAMANA only
162+
use_search_history='ON' # SVS-VAMANA only
163+
)
164+
55165
56166
TextQuery
57167
================

docs/api/schema.rst

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,16 @@ HNSW (Hierarchical Navigable Small World) - Graph-based approximate search with
208208

209209
**Performance characteristics:**
210210

211-
- **Search speed**: Very fast approximate search with tunable accuracy
211+
- **Search speed**: Very fast approximate search with tunable accuracy (via ``ef_runtime`` at query time)
212212
- **Memory usage**: Higher than compressed SVS-VAMANA but reasonable for most applications
213-
- **Recall quality**: Excellent recall rates (95-99%), often better than other approximate methods
213+
- **Recall quality**: Excellent recall rates (95-99%), tunable via ``ef_runtime`` parameter
214214
- **Build time**: Moderate construction time, faster than SVS-VAMANA for smaller datasets
215215

216+
**Runtime parameters** (adjustable at query time without rebuilding index):
217+
218+
- ``ef_runtime``: Controls search accuracy (higher = better recall, slower search). Default: 10
219+
- ``epsilon``: Range search approximation factor for VectorRangeQuery. Default: 0.01
220+
216221
.. autoclass:: HNSWVectorField
217222
:members:
218223
:show-inheritance:
@@ -234,10 +239,10 @@ HNSW (Hierarchical Navigable Small World) - Graph-based approximate search with
234239
dims: 768
235240
distance_metric: cosine
236241
datatype: float32
237-
# Balanced settings for good recall and performance
238-
m: 16
239-
ef_construction: 200
240-
ef_runtime: 10
242+
# Index-time parameters (set during index creation)
243+
m: 16 # Graph connectivity
244+
ef_construction: 200 # Build-time accuracy
245+
# Note: ef_runtime can be set at query time via VectorQuery
241246
242247
**High-recall configuration:**
243248

@@ -250,10 +255,10 @@ HNSW (Hierarchical Navigable Small World) - Graph-based approximate search with
250255
dims: 768
251256
distance_metric: cosine
252257
datatype: float32
253-
# Tuned for maximum accuracy
258+
# Index-time parameters tuned for maximum accuracy
254259
m: 32
255260
ef_construction: 400
256-
ef_runtime: 50
261+
# Note: ef_runtime=50 can be set at query time for higher recall
257262
258263
SVS-VAMANA Vector Fields
259264
------------------------
@@ -278,6 +283,13 @@ SVS-VAMANA (Scalable Vector Search with VAMANA graph algorithm) provides fast ap
278283

279284
- **vs HNSW**: Better memory efficiency with compression, similar or better recall, Intel-optimized
280285

286+
**Runtime parameters** (adjustable at query time without rebuilding index):
287+
288+
- ``epsilon``: Range search approximation factor. Default: 0.01
289+
- ``search_window_size``: Size of search window for KNN searches. Higher = better recall, slower search
290+
- ``use_search_history``: Whether to use search buffer (OFF/ON/AUTO). Default: AUTO
291+
- ``search_buffer_capacity``: Tuning parameter for 2-level compression. Default: search_window_size
292+
281293
**Compression selection guide:**
282294

283295
- **No compression**: Best performance, standard memory usage
@@ -314,10 +326,10 @@ SVS-VAMANA (Scalable Vector Search with VAMANA graph algorithm) provides fast ap
314326
dims: 768
315327
distance_metric: cosine
316328
datatype: float32
317-
# Standard settings for balanced performance
329+
# Index-time parameters (set during index creation)
318330
graph_max_degree: 40
319331
construction_window_size: 250
320-
search_window_size: 20
332+
# Note: search_window_size and other runtime params can be set at query time
321333
322334
**High-performance configuration with compression:**
323335

@@ -330,22 +342,22 @@ SVS-VAMANA (Scalable Vector Search with VAMANA graph algorithm) provides fast ap
330342
dims: 768
331343
distance_metric: cosine
332344
datatype: float32
333-
# Tuned for better recall
345+
# Index-time parameters tuned for better recall
334346
graph_max_degree: 64
335347
construction_window_size: 500
336-
search_window_size: 40
337348
# Maximum compression with dimensionality reduction
338349
compression: LeanVec4x8
339350
reduce: 384 # 50% dimensionality reduction
340351
training_threshold: 1000
352+
# Note: search_window_size=40 can be set at query time for higher recall
341353
342354
**Important Notes:**
343355

344356
- **Requirements**: SVS-VAMANA requires Redis >= 8.2 with RediSearch >= 2.8.10.
345357
- **Datatype limitations**: SVS-VAMANA only supports `float16` and `float32` datatypes (not `bfloat16` or `float64`).
346358
- **Compression compatibility**: The `reduce` parameter is only valid with LeanVec compression types (`LeanVec4x8` or `LeanVec8x8`).
347359
- **Platform considerations**: Intel's proprietary LVQ and LeanVec optimizations are not available in Redis Open Source. On non-Intel platforms and Redis Open Source, SVS-VAMANA with compression falls back to basic 8-bit scalar quantization.
348-
- **Performance tip**: Start with default parameters and tune `search_window_size` first for your speed vs accuracy requirements.
360+
- **Performance tip**: Runtime parameters like ``search_window_size``, ``epsilon``, and ``use_search_history`` can be adjusted at query time without rebuilding the index. Start with defaults and tune ``search_window_size`` first for your speed vs accuracy requirements.
349361

350362
FLAT Vector Fields
351363
------------------
@@ -487,16 +499,16 @@ Performance Characteristics
487499

488500
**Recall Quality:**
489501
- FLAT: 100% (exact search)
490-
- HNSW: 95-99% (tunable via ef_runtime)
491-
- SVS-VAMANA: 90-95% (depends on compression)
502+
- HNSW: 95-99% (tunable via ``ef_runtime`` at query time)
503+
- SVS-VAMANA: 90-95% (tunable via ``search_window_size`` at query time, also depends on compression)
492504

493505
Migration Considerations
494506
------------------------
495507

496508
**From FLAT to HNSW:**
497509
- Straightforward migration
498510
- Expect slight recall reduction but major speed improvement
499-
- Tune ef_runtime to balance speed vs accuracy
511+
- Tune ``ef_runtime`` at query time to balance speed vs accuracy (no index rebuild needed)
500512

501513
**From HNSW to SVS-VAMANA:**
502514
- Requires Redis >= 8.2 with RediSearch >= 2.8.10

0 commit comments

Comments
 (0)