Skip to content

Commit 5cebdea

Browse files
committed
fix(knowledge): clamp single-result distance instead of forcing zero
1 parent ff08fb0 commit 5cebdea

File tree

1 file changed

+4
-1
lines changed
  • apps/sim/app/api/knowledge/search

1 file changed

+4
-1
lines changed

apps/sim/app/api/knowledge/search/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ export async function POST(request: NextRequest) {
420420
// scores to 0-1 range before merging.
421421
const normalizeScores = (items: SearchResult[]): SearchResult[] => {
422422
if (items.length === 0) return items
423-
if (items.length === 1) return [{ ...items[0], distance: 0 }]
423+
// Single result: clamp raw distance to [0,1] to preserve quality signal.
424+
// Forcing distance=0 would give a poor single result the best possible rank.
425+
if (items.length === 1)
426+
return [{ ...items[0], distance: Math.min(1, Math.max(0, items[0].distance)) }]
424427
const min = Math.min(...items.map((r) => r.distance))
425428
const max = Math.max(...items.map((r) => r.distance))
426429
const range = max - min || 1

0 commit comments

Comments
 (0)