This commit is contained in:
S. M. Mohiuddin Khan Shiam 2025-07-28 18:35:56 -07:00 committed by GitHub
commit 6fd8fb96b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -834,6 +834,16 @@ class Chroma(VectorStore):
return _results_to_docs_and_vectors(results)
@staticmethod
def _euclidean_relevance_score_fn(distance: float) -> float:
"""Normalize Euclidean (L2) distance to a [0, 1] relevance score.
Uses the transformation ``1 / (1 + distance)`` so that:
* distance == 0 -> score == 1 (most relevant)
* distance -> -> score -> 0 (least relevant)
"""
return 1.0 / (1.0 + float(distance))
def _select_relevance_score_fn(self) -> Callable[[float], float]:
"""Select the relevance score function based on collections distance metric.