Skip to content
Open
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
11 changes: 6 additions & 5 deletions libs/core/langchain_core/vectorstores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,13 @@ def _cosine_relevance_score_fn(distance: float) -> float:
return 1.0 - distance

@staticmethod
def _max_inner_product_relevance_score_fn(distance: float) -> float:
"""Normalize the distance to a score on a scale [0, 1]."""
if distance > 0:
return 1.0 - distance
def _max_inner_product_relevance_score_fn(similarity: float) -> float:
"""Convert raw MAX_INNER_PRODUCT scores into a normalized relevance score.
return -1.0 * distance
For similarity-based metrics, higher scores are already better,
so we simply return the similarity (optionally clamp to 0-1 if needed).
"""
return max(0.0, min(1.0, similarity))

def _select_relevance_score_fn(self) -> Callable[[float], float]:
"""The 'correct' relevance function.
Expand Down