We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ff08fb0 commit 5cebdeaCopy full SHA for 5cebdea
1 file changed
apps/sim/app/api/knowledge/search/route.ts
@@ -420,7 +420,10 @@ export async function POST(request: NextRequest) {
420
// scores to 0-1 range before merging.
421
const normalizeScores = (items: SearchResult[]): SearchResult[] => {
422
if (items.length === 0) return items
423
- if (items.length === 1) return [{ ...items[0], distance: 0 }]
+ // 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)) }]
427
const min = Math.min(...items.map((r) => r.distance))
428
const max = Math.max(...items.map((r) => r.distance))
429
const range = max - min || 1
0 commit comments