From 3349ed1a256c122077537b0e98bc40e217a55491 Mon Sep 17 00:00:00 2001 From: tomjohnhall Date: Wed, 18 Feb 2026 23:17:51 +0000 Subject: [PATCH 1/2] update test with multi vector default case --- tests/unit/test_aggregation_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_aggregation_types.py b/tests/unit/test_aggregation_types.py index 503674f9..ea271dcb 100644 --- a/tests/unit/test_aggregation_types.py +++ b/tests/unit/test_aggregation_types.py @@ -367,7 +367,7 @@ def test_multi_vector_query_string(): assert ( str(multi_vector_query) - == f"@{field_1}:[VECTOR_RANGE 2.0 $vector_0]=>{{$YIELD_DISTANCE_AS: distance_0}} | @{field_2}:[VECTOR_RANGE 2.0 $vector_1]=>{{$YIELD_DISTANCE_AS: distance_1}} SCORER TFIDF DIALECT 2 APPLY (2 - @distance_0)/2 AS score_0 APPLY (2 - @distance_1)/2 AS score_1 APPLY @score_0 * {weight_1} + @score_1 * {weight_2} AS combined_score SORTBY 2 @combined_score DESC MAX 10" + == f"@{field_1}:[VECTOR_RANGE 2.0 $vector_0]=>{{$YIELD_DISTANCE_AS: distance_0}} | @{field_2}:[VECTOR_RANGE 2.0 $vector_1]=>{{$YIELD_DISTANCE_AS: distance_1}} SCORER TFIDF DIALECT 2 APPLY case(exists(@distance_0), (2 - @distance_0)/2, 0) AS score_0 APPLY case(exists(@distance_1), (2 - @distance_1)/2, 0) AS score_1 APPLY @score_0 * {weight_1} + @score_1 * {weight_2} AS combined_score SORTBY 2 @combined_score DESC MAX 10" ) From dd1e8032fab632015364a6ba5f890ac2a9dcbd27 Mon Sep 17 00:00:00 2001 From: tomjohnhall Date: Wed, 18 Feb 2026 22:57:41 +0000 Subject: [PATCH 2/2] use case() to default to 0 when vector is out of range --- redisvl/query/aggregate.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/redisvl/query/aggregate.py b/redisvl/query/aggregate.py index 1f1da2ac..01ecedd2 100644 --- a/redisvl/query/aggregate.py +++ b/redisvl/query/aggregate.py @@ -329,7 +329,11 @@ def __init__( # calculate the respective vector similarities for i in range(len(self._vectors)): - self.apply(**{f"score_{i}": f"(2 - @distance_{i})/2"}) + self.apply( + **{ + f"score_{i}": f"case(exists(@distance_{i}), (2 - @distance_{i})/2, 0)" + } + ) # construct the scoring string based on the vector similarity scores and weights combined_scores = []