Skip to content

Commit 2605a1f

Browse files
fix: normalize Milvus similarity scores for threshold filtering (#4880)
* fix: normalize Milvus similarity scores for threshold filtering * refactor: refact Milvus similarity score normalization #4879 --------- Co-authored-by: 강나훈 <nahoon.kang@mnc.ai>
1 parent 2e1999e commit 2605a1f

File tree

1 file changed

+12
-1
lines changed
  • packages/components/nodes/vectorstores/Milvus

1 file changed

+12
-1
lines changed

packages/components/nodes/vectorstores/Milvus/Milvus.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,18 @@ const similaritySearchVectorWithScore = async (query: number[], k: number, vecto
395395
}
396396
}
397397
})
398-
results.push([new Document(fields), result.score])
398+
let normalizedScore = result.score
399+
switch (vectorStore.indexCreateParams.metric_type) {
400+
case MetricType.L2:
401+
normalizedScore = 1 / (1 + result.score)
402+
break
403+
case MetricType.IP:
404+
case MetricType.COSINE:
405+
normalizedScore = (result.score + 1) / 2
406+
break
407+
}
408+
409+
results.push([new Document(fields), normalizedScore])
399410
})
400411
return results
401412
}

0 commit comments

Comments
 (0)