fix(mcp_server): clamp similarity to [0,1] to avoid negative values

This commit is contained in:
bobo-xxx
2026-04-18 12:40:58 +08:00
committed by Igor Lins e Silva
parent 46d9eb5df0
commit eef053d750
+1 -1
View File
@@ -740,7 +740,7 @@ def tool_check_duplicate(content: str, threshold: float = 0.9):
if results["ids"] and results["ids"][0]: if results["ids"] and results["ids"][0]:
for i, drawer_id in enumerate(results["ids"][0]): for i, drawer_id in enumerate(results["ids"][0]):
dist = results["distances"][0][i] dist = results["distances"][0][i]
similarity = round(1 - dist, 3) similarity = round(max(0.0, 1 - dist), 3)
if similarity >= threshold: if similarity >= threshold:
# Chroma 1.5.x can return None for partially-flushed rows; # Chroma 1.5.x can return None for partially-flushed rows;
# coerce to empty sentinels so downstream .get() is safe. # coerce to empty sentinels so downstream .get() is safe.