From 2605a1f74e279a4970855e567d16bd8b12fbc9f5 Mon Sep 17 00:00:00 2001 From: Kang Nahoon <49896157+ejrtks1020@users.noreply.github.com> Date: Fri, 18 Jul 2025 20:35:19 +0900 Subject: [PATCH] fix: normalize Milvus similarity scores for threshold filtering (#4880) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: normalize Milvus similarity scores for threshold filtering * refactor: refact Milvus similarity score normalization #4879 --------- Co-authored-by: 강나훈 --- .../components/nodes/vectorstores/Milvus/Milvus.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/vectorstores/Milvus/Milvus.ts b/packages/components/nodes/vectorstores/Milvus/Milvus.ts index e10c2cfc..ac2e4bd2 100644 --- a/packages/components/nodes/vectorstores/Milvus/Milvus.ts +++ b/packages/components/nodes/vectorstores/Milvus/Milvus.ts @@ -395,7 +395,18 @@ const similaritySearchVectorWithScore = async (query: number[], k: number, vecto } } }) - results.push([new Document(fields), result.score]) + let normalizedScore = result.score + switch (vectorStore.indexCreateParams.metric_type) { + case MetricType.L2: + normalizedScore = 1 / (1 + result.score) + break + case MetricType.IP: + case MetricType.COSINE: + normalizedScore = (result.score + 1) / 2 + break + } + + results.push([new Document(fields), normalizedScore]) }) return results }