Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion redisvl/query/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,13 @@ def __init__(
super().__init__(query_string)

# calculate the respective vector similarities
# use exists() guard so documents where Redis did not yield a distance
# (e.g. when the index contains >10 000 entries) get score 0 instead
# of raising "Could not find the value for a parameter name".
for i in range(len(self._vectors)):
self.apply(**{f"score_{i}": f"(2 - @distance_{i})/2"})
self.apply(
**{f"score_{i}": f"if(exists(@distance_{i}), (2 - @distance_{i})/2, 0)"}
)

# construct the scoring string based on the vector similarity scores and weights
combined_scores = []
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_aggregation_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def test_multi_vector_query_string():

assert (
str(multi_vector_query)
== f"@{field_1}:[VECTOR_RANGE {max_distance_1} $vector_0]=>{{$YIELD_DISTANCE_AS: distance_0}} AND @{field_2}:[VECTOR_RANGE {max_distance_2} $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 {max_distance_1} $vector_0]=>{{$YIELD_DISTANCE_AS: distance_0}} AND @{field_2}:[VECTOR_RANGE {max_distance_2} $vector_1]=>{{$YIELD_DISTANCE_AS: distance_1}} SCORER TFIDF DIALECT 2 APPLY if(exists(@distance_0), (2 - @distance_0)/2, 0) AS score_0 APPLY if(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"
)


Expand Down
Loading