Fix normalizing the cosine distance in Qdrant (#12934)

Qdrant was incorrectly calculating the cosine similarity and returning
`0.0` for the best match, instead of `1.0`. Internally Qdrant returns a
cosine score from `-1.0` (worst match) to `1.0` (best match), and the
current formula reflects it.
pull/12869/head^2
Kacper Łukawski 11 months ago committed by GitHub
parent 8fe6bcc662
commit 621419f71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1837,6 +1837,11 @@ class Qdrant(VectorStore):
)
return qdrant
@staticmethod
def _cosine_relevance_score_fn(distance: float) -> float:
"""Normalize the distance to a score on a scale [0, 1]."""
return (distance + 1.0) / 2.0
def _select_relevance_score_fn(self) -> Callable[[float], float]:
"""
The 'correct' relevance function

Loading…
Cancel
Save