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
6 changes: 5 additions & 1 deletion redisvl/query/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
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 @@ -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"
)


Expand Down