You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/commands/ft.aggregate.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -331,6 +331,8 @@ if set, overrides the timeout parameter of the module.
331
331
defines one or more value parameters. Each parameter has a name and a value.
332
332
333
333
You can reference parameters in the `query` by a `$`, followed by the parameter name, for example, `$user`. Each such reference in the search query to a parameter name is substituted by the corresponding parameter value. For example, with parameter definition `PARAMS 4 lon 29.69465 lat 34.95126`, the expression `@loc:[$lon $lat 10 km]` is evaluated to `@loc:[29.69465 34.95126 10 km]`. You cannot reference parameters in the query string where concrete values are not allowed, such as in field names, for example, `@loc`. To use `PARAMS`, set `DIALECT` to `2` or greater than `2`.
334
+
335
+
**Query attributes**: You can also use `PARAMS` to pass values to [query attributes]({{< relref "/develop/ai/search-and-query/advanced-concepts/query_syntax#query-attributes" >}}) in vector search queries. For example, `$SHARD_K_RATIO` controls cluster optimization for vector KNN queries by setting the ratio of results each shard retrieves relative to the requested `top_k`. See [cluster-specific query parameters]({{< relref "develop/ai/search-and-query/vectors#cluster-specific-query-parameters" >}}) for details.
Copy file name to clipboardExpand all lines: content/commands/ft.search.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -510,6 +510,8 @@ defines one or more value parameters. Each parameter has a name and a value.
510
510
You can reference parameters in the `query` by a `$`, followed by the parameter name, for example, `$user`. Each such reference in the search query to a parameter name is substituted by the corresponding parameter value. For example, with parameter definition `PARAMS 4 lon 29.69465 lat 34.95126`, the expression `@loc:[$lon $lat 10 km]` is evaluated to `@loc:[29.69465 34.95126 10 km]`. You cannot reference parameters in the query string where concrete values are not allowed, such as in field names, for example, `@loc`. To use `PARAMS`, set
to `2` or greater than `2` (this requires [RediSearch v2.4](https://github.com/RediSearch/RediSearch/releases/tag/v2.4.3) or above).
513
+
514
+
**Query attributes**: You can also use `PARAMS` to pass values to [query attributes]({{< relref "/develop/ai/search-and-query/advanced-concepts/query_syntax#query-attributes" >}}) in vector search queries. For example, `$SHARD_K_RATIO` controls cluster optimization for vector KNN queries by setting the ratio of results each shard retrieves relative to the requested `top_k`. See [cluster-specific query parameters]({{< relref "develop/ai/search-and-query/vectors#cluster-specific-query-parameters" >}}) for details.
513
515
</details>
514
516
515
517
<detailsopen>
@@ -679,6 +681,16 @@ Search for books with semantically similar title to _Planet Earth_. Return top 1
679
681
{{< / highlight >}}
680
682
</details>
681
683
684
+
<detailsopen>
685
+
<summary><b>Vector search with cluster optimization</b></summary>
686
+
687
+
Search for books with semantically similar title to _Planet Earth_ using cluster optimization. Each shard retrieves 60% of the requested results for improved performance in Redis cluster environments.
Copy file name to clipboardExpand all lines: content/develop/ai/search-and-query/advanced-concepts/query_syntax.md
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -389,7 +389,8 @@ The supported attributes are:
389
389
390
390
As of v2.6.1, the query attributes syntax supports these additional attributes:
391
391
392
-
***$yield_distance_as**: specifies the distance field name, used for later sorting and/or returning, for clauses that yield some distance metric. It is currently supported for vector queries only (both KNN and range).
392
+
***$yield_distance_as**: specifies the distance field name, used for later sorting and/or returning, for clauses that yield some distance metric. It is currently supported for vector queries only (both KNN and range).
393
+
***$shard_k_ratio**: controls how many results each shard retrieves relative to the requested top_k in cluster setups. Value range: 0.1 - 1.0 (default: 1.0). Only applicable to vector KNN queries in Redis cluster environments. See [cluster-specific query parameters]({{< relref "develop/ai/search-and-query/vectors#cluster-specific-query-parameters" >}}) for detailed information.
393
394
***vector query params**: pass optional parameters for [vector queries]({{< relref "develop/ai/search-and-query/vectors#querying-vector-fields" >}}) in key-value format.
394
395
395
396
## A few query examples
@@ -458,6 +459,10 @@ As of v2.6.1, the query attributes syntax supports these additional attributes:
458
459
459
460
@age:[(18 +inf]
460
461
462
+
* Vector search with cluster optimization - retrieve 100 nearest neighbors with each shard providing 50% of results:
Copy file name to clipboardExpand all lines: content/develop/ai/search-and-query/query/vector-search.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,4 +106,28 @@ query = (
106
106
.return_fields('vector_dist', 'description')
107
107
.dialect(2)
108
108
)
109
-
</!-->
109
+
</!-->
110
+
111
+
## Cluster optimization
112
+
113
+
In Redis cluster environments, you can optimize vector search performance using the `$SHARD_K_RATIO` query attribute. This parameter controls how many results each shard retrieves relative to the requested `top_k`, creating a tunable trade-off between accuracy and performance.
114
+
115
+
### Basic cluster optimization
116
+
117
+
Retrieve 100 nearest neighbors with each shard providing 60% of the requested results:
Copy file name to clipboardExpand all lines: content/develop/ai/search-and-query/vectors/_index.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -414,6 +414,24 @@ By default, Redis selects the best filter mode to optimize query execution. You
414
414
|`HYBRID_POLICY`| Specifies the filter mode to use during vector search with filters (hybrid). |`BATCHES` or `ADHOC_BF`|
415
415
|`BATCH_SIZE`| A fixed batch size to use in every iteration when the `BATCHES` policy is auto-selected or requested. | Positive integer. |
416
416
417
+
### Cluster-specific query parameters
418
+
419
+
**$SHARD_K_RATIO**
420
+
421
+
The `$SHARD_K_RATIO` parameter controls how many results each shard retrieves relative to the requested `top_k` in Redis cluster environments. This creates a tunable trade-off between accuracy and performance.
422
+
423
+
| Parameter | Description | Value Range | Default |
|`$SHARD_K_RATIO`| Ratio of `top_k` results to fetch per shard in cluster setups. Calculation: `shard_results = top_k × ratio`. | 0.1 - 1.0 (up to 2 decimal places) | 1.0 |
426
+
427
+
**Important considerations:**
428
+
429
+
- Only applicable to vector KNN queries in Redis cluster environments
430
+
- Each shard must retrieve at least `max(top_k / #shards, ceil(top_k × ratio))` results
431
+
- If the user-defined ratio is lower than `top_k / #shards`, the server ignores it and uses the minimum required ratio
432
+
- Unbalanced shards returning fewer results than required may lead to fewer total results than requested in `top_k`
@@ -523,6 +541,63 @@ FT.SEARCH movies "(@category:{action})=>[KNN 10 @doc_embedding $BLOB]=>{$HYBRID_
523
541
524
542
To explore additional Python vector search examples, review recipes for the [`Redis Python`](https://github.com/redis-developer/redis-ai-resources/blob/main/python-recipes/vector-search/00_redispy.ipynb) client library and the [`Redis Vector Library`](https://github.com/redis-developer/redis-ai-resources/blob/main/python-recipes/vector-search/01_redisvl.ipynb).
525
543
544
+
### Cluster optimization examples
545
+
546
+
The following examples demonstrate using `$SHARD_K_RATIO` to optimize vector search performance in Redis cluster environments.
547
+
548
+
Return the top 100 nearest neighbors with each shard providing 50% of the requested results (50 results per shard):
Combine cluster optimization with filtering and other query attributes. Among movies with `action` category, return top 50 nearest neighbors with 30% shard ratio and custom EF_RUNTIME:
When using `$SHARD_K_RATIO` in Redis cluster environments, consider the following behavioral characteristics and best practices:
569
+
570
+
#### Minimum results guarantee
571
+
572
+
Each shard must retrieve at least `max(top_k / #shards, ceil(top_k × ratio))` results to ensure the cluster can return the requested `top_k` results. If your specified ratio would result in fewer results per shard than this minimum, Redis automatically adjusts to the minimum required ratio.
573
+
574
+
**Example scenarios:**
575
+
-`top_k=100`, 4 shards, `ratio=0.5` → 50 results per shard (valid)
576
+
-`top_k=100`, 4 shards, `ratio=0.2` → 25 results per shard (minimum: 25, so valid)
577
+
-`top_k=100`, 8 shards, `ratio=0.1` → 10 results per shard (minimum: 13, so Redis uses 13)
578
+
579
+
#### Handling unbalanced shards
580
+
581
+
In cases where some shards contain fewer documents than required to fulfill the `top_k` results, using a lower ratio may lead to fewer total results than requested. To mitigate this:
582
+
583
+
1.**Monitor shard distribution**: Ensure your data is relatively balanced across shards
584
+
2.**Adjust ratio dynamically**: If you consistently get fewer results than expected, increase the ratio
585
+
3.**Use higher ratios for critical queries**: When result completeness is more important than performance
586
+
587
+
#### Performance vs accuracy trade-offs
588
+
589
+
| Ratio Range | Use Case | Performance | Accuracy |
The feature introduces a shard window ratio - suggested $shard_k_ratio - parameter that controls how many results each shard retrieves relative to the requested top_k. This creates a tunable trade-off between accuracy and performance.
3
+
4
+
Calculation: shard_results = top_k × window_ratio
5
+
6
+
3.2 API Integration
7
+
Following Redis vector search patterns, the new parameter will be implemented as a Query Attribute using the existing =>{...} syntax.
Range: Must be between higher than 0 and 1.0 (inclusive)
65
+
66
+
Precision: Support up to 2 decimal places (0.01 minimum)
67
+
68
+
Minimum results: Each shard must retrieve at least max(top_k/#shards, ceil(top_k × ratio)) results, not allowing to return less results than the requested K (NEED DOCUMENTATION)
top_k=7, ratio=0.2 → 2 results per shard (ceiling applied)
78
+
79
+
Documentation required for the following limitations:
80
+
Minimum K results from the shards will always be top_k/shardsif the user-defined ratio is lower than that, the server will ignore it
81
+
82
+
In case some unbalanced shard returns less than the amount required for fulfilling the top_k results, when using ratio, it could lead to fewer results than requested in the top_k. If that’s the case, it requires adjusting the ratio to a higher value
0 commit comments