Merge pull request #988 from bobo-xxx/clawoss/fix/978-negative-similarity

fix: clamp similarity scores to [0,1] to prevent negative values
This commit is contained in:
Igor Lins e Silva
2026-05-06 03:34:56 -03:00
committed by GitHub
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -287,7 +287,7 @@ class Layer3:
for i, (doc, meta, dist) in enumerate(zip(docs, metas, dists), 1):
meta = meta or {}
doc = doc or ""
similarity = round(1 - dist, 3)
similarity = round(max(0.0, 1 - dist), 3)
wing_name = meta.get("wing", "?")
room_name = meta.get("room", "?")
source = Path(meta.get("source_file", "")).name if meta.get("source_file") else ""
+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]:
for i, drawer_id in enumerate(results["ids"][0]):
dist = results["distances"][0][i]
similarity = round(1 - dist, 3)
similarity = round(max(0.0, 1 - dist), 3)
if similarity >= threshold:
# Chroma 1.5.x can return None for partially-flushed rows;
# coerce to empty sentinels so downstream .get() is safe.