File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
apps/sim/app/api/knowledge/search Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments