fix(vector-stores/baidu): convert L2 distance to similarity score in search() (#6435)

This commit is contained in:
Abhinav Singh
2026-07-20 12:44:26 +05:30
committed by GitHub
parent 9383e9a255
commit 726bcc80b2
2 changed files with 29 additions and 1 deletions
+8 -1
View File
@@ -224,8 +224,15 @@ class BaiduDB(VectorStoreBase):
output = []
for row in res.rows:
row_data = row.get("row", {})
# Mochow returns the raw L2 distance (lower = closer). Convert it to a
# similarity score (higher = better) to satisfy the VectorStoreBase
# contract, mirroring the milvus provider. Non-L2 metrics already
# return a higher-is-better score.
raw_score = row.get("score", 0.0)
if self.metric_type in (MetricType.L2, "L2"):
raw_score = 1.0 / (1.0 + raw_score)
output_data = OutputData(
id=row_data.get("id"), score=row.get("score", 0.0), payload=row_data.get("metadata", {})
id=row_data.get("id"), score=raw_score, payload=row_data.get("metadata", {})
)
output.append(output_data)