Skip to content

Commit 51f3064

Browse files
Update for redisvl 0.12.1 (#2461)
Co-authored-by: redisdocsapp[bot] <177626021+redisdocsapp[bot]@users.noreply.github.com>
1 parent f2ec180 commit 51f3064

File tree

7 files changed

+510
-22
lines changed

7 files changed

+510
-22
lines changed

content/develop/ai/redisvl/api/query.md

Lines changed: 272 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ queries for different use cases. Each query class wraps the `redis-py` Query mod
1212

1313
## VectorQuery
1414

15-
### `class VectorQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, ef_runtime=None, normalize_vector_distance=False)`
15+
### `class VectorQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, ef_runtime=None, epsilon=None, search_window_size=None, use_search_history=None, search_buffer_capacity=None, normalize_vector_distance=False)`
1616

1717
Bases: `BaseVectorQuery`, `BaseQuery`
1818

@@ -57,6 +57,22 @@ expression.
5757
* **ef_runtime** (*Optional* *[* *int* *]*) – Controls the size of the dynamic candidate list for HNSW
5858
algorithm at query time. Higher values improve recall at the expense of
5959
slower search performance. Defaults to None, which uses the index-defined value.
60+
* **epsilon** (*Optional* *[* *float* *]*) – The range search approximation factor for HNSW and SVS-VAMANA
61+
indexes. Sets boundaries for candidates within radius \* (1 + epsilon). Higher values
62+
allow more extensive search and more accurate results at the expense of run time.
63+
Defaults to None, which uses the index-defined value (typically 0.01).
64+
* **search_window_size** (*Optional* *[* *int* *]*) – The size of the search window for SVS-VAMANA KNN searches.
65+
Increasing this value generally yields more accurate but slower search results.
66+
Defaults to None, which uses the index-defined value (typically 10).
67+
* **use_search_history** (*Optional* *[* *str* *]*) – For SVS-VAMANA indexes, controls whether to use the
68+
search buffer or entire search history. Options are "OFF", "ON", or "AUTO".
69+
"AUTO" is always evaluated internally as "ON". Using the entire history may yield
70+
a slightly better graph at the cost of more search time.
71+
Defaults to None, which uses the index-defined value (typically "AUTO").
72+
* **search_buffer_capacity** (*Optional* *[* *int* *]*) – Tuning parameter for SVS-VAMANA indexes using
73+
two-level compression (LVQ<X>x<Y> or LeanVec types). Determines the number of vector
74+
candidates to collect in the first level of search before the re-ranking level.
75+
Defaults to None, which uses the index-defined value (typically SEARCH_WINDOW_SIZE).
6076
* **normalize_vector_distance** (*bool*) – Redis supports 3 distance metrics: L2 (euclidean),
6177
IP (inner product), and COSINE. By default, L2 distance returns an unbounded value.
6278
COSINE distance returns a value between 0 and 2. IP returns a value determined by
@@ -215,6 +231,19 @@ Set the EF_RUNTIME parameter for the query.
215231
* **TypeError** – If ef_runtime is not an integer
216232
* **ValueError** – If ef_runtime is not positive
217233

234+
#### `set_epsilon(epsilon)`
235+
236+
Set the epsilon parameter for the query.
237+
238+
* **Parameters:**
239+
**epsilon** (*float*) – The range search approximation factor for HNSW and SVS-VAMANA
240+
indexes. Sets boundaries for candidates within radius \* (1 + epsilon).
241+
Higher values allow more extensive search and more accurate results at the
242+
expense of run time.
243+
* **Raises:**
244+
* **TypeError** – If epsilon is not a float or int
245+
* **ValueError** – If epsilon is negative
246+
218247
#### `set_filter(filter_expression=None)`
219248

220249
Set the filter expression for the query.
@@ -235,6 +264,40 @@ Set the hybrid policy for the query.
235264
* **Raises:**
236265
**ValueError** – If hybrid_policy is not one of the valid options
237266

267+
#### `set_search_buffer_capacity(search_buffer_capacity)`
268+
269+
Set the SEARCH_BUFFER_CAPACITY parameter for the query.
270+
271+
* **Parameters:**
272+
**search_buffer_capacity** (*int*) – Tuning parameter for SVS-VAMANA indexes using
273+
two-level compression. Determines the number of vector candidates to collect
274+
in the first level of search before the re-ranking level.
275+
* **Raises:**
276+
* **TypeError** – If search_buffer_capacity is not an integer
277+
* **ValueError** – If search_buffer_capacity is not positive
278+
279+
#### `set_search_window_size(search_window_size)`
280+
281+
Set the SEARCH_WINDOW_SIZE parameter for the query.
282+
283+
* **Parameters:**
284+
**search_window_size** (*int*) – The size of the search window for SVS-VAMANA KNN searches.
285+
Increasing this value generally yields more accurate but slower search results.
286+
* **Raises:**
287+
* **TypeError** – If search_window_size is not an integer
288+
* **ValueError** – If search_window_size is not positive
289+
290+
#### `set_use_search_history(use_search_history)`
291+
292+
Set the USE_SEARCH_HISTORY parameter for the query.
293+
294+
* **Parameters:**
295+
**use_search_history** (*str*) – For SVS-VAMANA indexes, controls whether to use the
296+
search buffer or entire search history. Options are "OFF", "ON", or "AUTO".
297+
* **Raises:**
298+
* **TypeError** – If use_search_history is not a string
299+
* **ValueError** – If use_search_history is not one of "OFF", "ON", or "AUTO"
300+
238301
#### `slop(slop)`
239302

240303
Allow a maximum of N intervening non matched terms between
@@ -331,6 +394,15 @@ Return the EF_RUNTIME parameter for the query.
331394
* **Return type:**
332395
Optional[int]
333396

397+
#### `property epsilon: float | None`
398+
399+
Return the epsilon parameter for the query.
400+
401+
* **Returns:**
402+
The epsilon value for the query.
403+
* **Return type:**
404+
Optional[float]
405+
334406
#### `property filter: str | `[`FilterExpression`]({{< relref "filter/#filterexpression" >}})` `
335407

336408
The filter expression for the query.
@@ -357,9 +429,77 @@ Return the parameters for the query.
357429

358430
Return self as the query object.
359431

432+
#### `property search_buffer_capacity: int | None`
433+
434+
Return the SEARCH_BUFFER_CAPACITY parameter for the query.
435+
436+
* **Returns:**
437+
The SEARCH_BUFFER_CAPACITY value for the query.
438+
* **Return type:**
439+
Optional[int]
440+
441+
#### `property search_window_size: int | None`
442+
443+
Return the SEARCH_WINDOW_SIZE parameter for the query.
444+
445+
* **Returns:**
446+
The SEARCH_WINDOW_SIZE value for the query.
447+
* **Return type:**
448+
Optional[int]
449+
450+
#### `property use_search_history: str | None`
451+
452+
Return the USE_SEARCH_HISTORY parameter for the query.
453+
454+
* **Returns:**
455+
The USE_SEARCH_HISTORY value for the query.
456+
* **Return type:**
457+
Optional[str]
458+
459+
#### `NOTE`
460+
**Runtime Parameters for Performance Tuning**
461+
462+
VectorQuery supports runtime parameters for HNSW and SVS-VAMANA indexes that can be adjusted at query time without rebuilding the index:
463+
464+
**HNSW Parameters:**
465+
466+
- `ef_runtime`: Controls search accuracy (higher = better recall, slower search)
467+
468+
**SVS-VAMANA Parameters:**
469+
470+
- `search_window_size`: Size of search window for KNN searches
471+
- `use_search_history`: Whether to use search buffer (OFF/ON/AUTO)
472+
- `search_buffer_capacity`: Tuning parameter for 2-level compression
473+
474+
Example with HNSW runtime parameters:
475+
476+
```python
477+
from redisvl.query import VectorQuery
478+
479+
query = VectorQuery(
480+
vector=[0.1, 0.2, 0.3],
481+
vector_field_name="embedding",
482+
num_results=10,
483+
ef_runtime=150 # Higher for better recall
484+
)
485+
```
486+
487+
Example with SVS-VAMANA runtime parameters:
488+
489+
```python
490+
query = VectorQuery(
491+
vector=[0.1, 0.2, 0.3],
492+
vector_field_name="embedding",
493+
num_results=10,
494+
search_window_size=20,
495+
use_search_history='ON',
496+
search_buffer_capacity=30
497+
)
498+
```
499+
360500
## VectorRangeQuery
361501

362-
### `class VectorRangeQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', distance_threshold=0.2, epsilon=None, num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, normalize_vector_distance=False)`
502+
### `class VectorRangeQuery(vector, vector_field_name, return_fields=None, filter_expression=None, dtype='float32', distance_threshold=0.2, epsilon=None, search_window_size=None, use_search_history=None, search_buffer_capacity=None, num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, hybrid_policy=None, batch_size=None, normalize_vector_distance=False)`
363503

364504
Bases: `BaseVectorQuery`, `BaseQuery`
365505

@@ -384,6 +524,18 @@ distance threshold.
384524
This controls how extensive the search is beyond the specified radius.
385525
Higher values increase recall at the expense of performance.
386526
Defaults to None, which uses the index-defined epsilon (typically 0.01).
527+
* **search_window_size** (*Optional* *[* *int* *]*) – The size of the search window for SVS-VAMANA range searches.
528+
Increasing this value generally yields more accurate but slower search results.
529+
Defaults to None, which uses the index-defined value (typically 10).
530+
* **use_search_history** (*Optional* *[* *str* *]*) – For SVS-VAMANA indexes, controls whether to use the
531+
search buffer or entire search history. Options are "OFF", "ON", or "AUTO".
532+
"AUTO" is always evaluated internally as "ON". Using the entire history may yield
533+
a slightly better graph at the cost of more search time.
534+
Defaults to None, which uses the index-defined value (typically "AUTO").
535+
* **search_buffer_capacity** (*Optional* *[* *int* *]*) – Tuning parameter for SVS-VAMANA indexes using
536+
two-level compression (LVQ<X>x<Y> or LeanVec types). Determines the number of vector
537+
candidates to collect in the first level of search before the re-ranking level.
538+
Defaults to None, which uses the index-defined value (typically SEARCH_WINDOW_SIZE).
387539
* **num_results** (*int*) – The MAX number of results to return.
388540
Defaults to 10.
389541
* **return_score** (*bool* *,* *optional*) – Whether to return the vector
@@ -597,6 +749,38 @@ Set the hybrid policy for the query.
597749
* **Raises:**
598750
**ValueError** – If hybrid_policy is not one of the valid options
599751

752+
#### `set_search_buffer_capacity(search_buffer_capacity)`
753+
754+
Set the SEARCH_BUFFER_CAPACITY parameter for the range query.
755+
756+
* **Parameters:**
757+
**search_buffer_capacity** (*int*) – Tuning parameter for SVS-VAMANA indexes using
758+
two-level compression.
759+
* **Raises:**
760+
* **TypeError** – If search_buffer_capacity is not an integer
761+
* **ValueError** – If search_buffer_capacity is not positive
762+
763+
#### `set_search_window_size(search_window_size)`
764+
765+
Set the SEARCH_WINDOW_SIZE parameter for the range query.
766+
767+
* **Parameters:**
768+
**search_window_size** (*int*) – The size of the search window for SVS-VAMANA range searches.
769+
* **Raises:**
770+
* **TypeError** – If search_window_size is not an integer
771+
* **ValueError** – If search_window_size is not positive
772+
773+
#### `set_use_search_history(use_search_history)`
774+
775+
Set the USE_SEARCH_HISTORY parameter for the range query.
776+
777+
* **Parameters:**
778+
**use_search_history** (*str*) – Controls whether to use the search buffer or entire history.
779+
Must be one of "OFF", "ON", or "AUTO".
780+
* **Raises:**
781+
* **TypeError** – If use_search_history is not a string
782+
* **ValueError** – If use_search_history is not one of the valid options
783+
600784
#### `slop(slop)`
601785

602786
Allow a maximum of N intervening non matched terms between
@@ -728,6 +912,63 @@ Return the parameters for the query.
728912

729913
Return self as the query object.
730914

915+
#### `property search_buffer_capacity: int | None`
916+
917+
Return the SEARCH_BUFFER_CAPACITY parameter for the query.
918+
919+
* **Returns:**
920+
The SEARCH_BUFFER_CAPACITY value for the query.
921+
* **Return type:**
922+
Optional[int]
923+
924+
#### `property search_window_size: int | None`
925+
926+
Return the SEARCH_WINDOW_SIZE parameter for the query.
927+
928+
* **Returns:**
929+
The SEARCH_WINDOW_SIZE value for the query.
930+
* **Return type:**
931+
Optional[int]
932+
933+
#### `property use_search_history: str | None`
934+
935+
Return the USE_SEARCH_HISTORY parameter for the query.
936+
937+
* **Returns:**
938+
The USE_SEARCH_HISTORY value for the query.
939+
* **Return type:**
940+
Optional[str]
941+
942+
#### `NOTE`
943+
**Runtime Parameters for Range Queries**
944+
945+
VectorRangeQuery supports runtime parameters for controlling range search behavior:
946+
947+
**HNSW & SVS-VAMANA Parameters:**
948+
949+
- `epsilon`: Range search approximation factor (default: 0.01)
950+
951+
**SVS-VAMANA Parameters:**
952+
953+
- `search_window_size`: Size of search window
954+
- `use_search_history`: Whether to use search buffer (OFF/ON/AUTO)
955+
- `search_buffer_capacity`: Tuning parameter for 2-level compression
956+
957+
Example:
958+
959+
```python
960+
from redisvl.query import VectorRangeQuery
961+
962+
query = VectorRangeQuery(
963+
vector=[0.1, 0.2, 0.3],
964+
vector_field_name="embedding",
965+
distance_threshold=0.3,
966+
epsilon=0.05, # Approximation factor
967+
search_window_size=20, # SVS-VAMANA only
968+
use_search_history='AUTO' # SVS-VAMANA only
969+
)
970+
```
971+
731972
## HybridQuery
732973

733974
### `class HybridQuery(*args, **kwargs)`
@@ -773,6 +1014,12 @@ Instantiates a AggregateHybridQuery object.
7731014
* **text_weights** (*Optional* *[* *Dict* *[* *str* *,* *float* *]* *]*) – The importance weighting of individual words
7741015
within the query text. Defaults to None, as no modifications will be made to the
7751016
text_scorer score.
1017+
1018+
#### `NOTE`
1019+
AggregateHybridQuery uses FT.AGGREGATE commands which do NOT support runtime
1020+
parameters. For runtime parameter support (ef_runtime, search_window_size, etc.),
1021+
use VectorQuery or VectorRangeQuery which use FT.SEARCH commands.
1022+
7761023
* **Raises:**
7771024
* **ValueError** – If the text string is empty, or if the text string becomes empty after
7781025
stopwords are removed.
@@ -985,6 +1232,29 @@ The `stopwords` parameter in [HybridQuery](#hybridquery) (and `AggregateHybridQu
9851232
For index-level stopwords configuration (server-side), see `redisvl.schema.IndexInfo.stopwords`.
9861233
Using query-time stopwords with index-level `STOPWORDS 0` is counterproductive.
9871234

1235+
#### `NOTE`
1236+
**Runtime Parameters for Hybrid Queries**
1237+
1238+
**Important:** AggregateHybridQuery uses FT.AGGREGATE commands which do NOT support runtime parameters.
1239+
Runtime parameters (`ef_runtime`, `search_window_size`, `use_search_history`, `search_buffer_capacity`)
1240+
are only supported with FT.SEARCH commands.
1241+
1242+
For runtime parameter support, use [VectorQuery](#vectorquery) or [VectorRangeQuery](#vectorrangequery) instead of AggregateHybridQuery.
1243+
1244+
Example with VectorQuery (supports runtime parameters):
1245+
1246+
```python
1247+
from redisvl.query import VectorQuery
1248+
1249+
query = VectorQuery(
1250+
vector=[0.1, 0.2, 0.3],
1251+
vector_field_name="embedding",
1252+
return_fields=["description"],
1253+
num_results=10,
1254+
ef_runtime=150 # Runtime parameters work with VectorQuery
1255+
)
1256+
```
1257+
9881258
## TextQuery
9891259

9901260
### `class TextQuery(text, text_field_name, text_scorer='BM25STD', filter_expression=None, return_fields=None, num_results=10, return_score=True, dialect=2, sort_by=None, in_order=False, params=None, stopwords='english', text_weights=None)`

0 commit comments

Comments
 (0)