Skip to content

Commit

Permalink
fix: dbsf zero div error (#872)
Browse files Browse the repository at this point in the history
* fix: dbsf zero division error

closes #871

* review suggestion

Co-authored-by: Andrey Vasnetsov <[email protected]>

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
  • Loading branch information
pavelm10 and generall authored Jan 2, 2025
1 parent a960b1a commit 67b7eb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions qdrant_client/hybrid/fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def distribution_based_score_fusion(
responses: list[list[models.ScoredPoint]], limit: int
) -> list[models.ScoredPoint]:
def normalize(response: list[models.ScoredPoint]) -> list[models.ScoredPoint]:
if len(response) <= 1:
return response

total = sum([point.score for point in response])
mean = total / len(response)
variance = sum([(point.score - mean) ** 2 for point in response]) / (len(response) - 1)
Expand Down
3 changes: 3 additions & 0 deletions qdrant_client/hybrid/test_reranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def test_distribution_based_score_fusion() -> None:
assert fused[1].id == 0
assert fused[2].id == 4

fused = distribution_based_score_fusion([[responses[0][0]]], limit=3)
assert fused[0].id == 1


def test_reciprocal_rank_fusion_empty_responses() -> None:
responses: list[list[models.ScoredPoint]] = [[]]
Expand Down

0 comments on commit 67b7eb8

Please sign in to comment.