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.search.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -679,6 +679,16 @@ Search for books with semantically similar title to _Planet Earth_. Return top 1
679
679
{{< / highlight >}}
680
680
</details>
681
681
682
+
<detailsopen>
683
+
<summary><b>Vector search with cluster optimization</b></summary>
684
+
685
+
Search for books with titles that are semantically similar to _Planet Earth_ using cluster optimization. Each shard retrieves 60% of the requested results for improved performance in Redis cluster environments. See the [query attributes]({{< relref "/develop/ai/search-and-query/advanced-concepts/query_syntax#query-attributes" >}}) reference page for more information.
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 for clauses that yield some distance metric. This is used for later sorting and/or returning. 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**: Do this when result completeness is more important than performance
586
+
587
+
#### Performance vs accuracy trade-offs
588
+
589
+
| Ratio Range | Use Case | Performance | Accuracy |
0 commit comments