From 889543559130cefb43d38b79dd87a941e8af31fe Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Fri, 16 Sep 2022 16:48:59 +0530 Subject: [PATCH] Ensure that vec distance is always positive for cosine. --- src/index.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.cpp b/src/index.cpp index a10f1840..c7acb92a 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -2572,8 +2572,11 @@ void Index::search(std::vector& field_query_tokens, const std::v groups_processed.emplace(distinct_id); } + auto vec_dist_score = (field_vector_index->distance_type == cosine) ? std::abs(dist_label.first) : + dist_label.first; + int64_t scores[3] = {0}; - scores[0] = -float_to_int64_t(dist_label.first); + scores[0] = -float_to_int64_t(vec_dist_score); int64_t match_score_index = -1; //LOG(INFO) << "SEQ_ID: " << seq_id << ", score: " << dist_label.first;