diff --git a/internal/core/src/segcore/SimilarityCorelation.h b/internal/core/src/segcore/SimilarityCorelation.h index 4c99ebb7ca..2c9bccd76d 100644 --- a/internal/core/src/segcore/SimilarityCorelation.h +++ b/internal/core/src/segcore/SimilarityCorelation.h @@ -13,12 +13,9 @@ #include "index/thirdparty/faiss/MetricType.h" -namespace milvus { -namespace segcore { +namespace milvus::segcore { static inline bool PositivelyRelated(faiss::MetricType metric_type) { - return metric_type == faiss::MetricType::METRIC_INNER_PRODUCT || metric_type == faiss::MetricType::METRIC_Jaccard || - metric_type == faiss::MetricType::METRIC_Tanimoto; + return metric_type == faiss::MetricType::METRIC_INNER_PRODUCT; } -} // namespace segcore -} // namespace milvus +} // namespace milvus::segcore diff --git a/internal/core/src/segcore/segment_c.cpp b/internal/core/src/segcore/segment_c.cpp index c4196f1cec..d142c2d490 100644 --- a/internal/core/src/segcore/segment_c.cpp +++ b/internal/core/src/segcore/segment_c.cpp @@ -68,8 +68,7 @@ Search(CSegmentInterface c_segment, auto plan = (milvus::query::Plan*)c_plan; auto phg_ptr = reinterpret_cast(c_placeholder_group); *search_result = segment->Search(plan, *phg_ptr, timestamp); - if (plan->plan_node_->search_info_.metric_type_ != milvus::MetricType::METRIC_INNER_PRODUCT) { - // if (!milvus::segcore::PositivelyRelated(plan->plan_node_->search_info_.metric_type_)) { + if (!milvus::segcore::PositivelyRelated(plan->plan_node_->search_info_.metric_type_)) { for (auto& dis : search_result->distances_) { dis *= -1; } diff --git a/internal/core/unittest/test_similarity_corelation.cpp b/internal/core/unittest/test_similarity_corelation.cpp index e48df15f50..7ec8991efb 100644 --- a/internal/core/unittest/test_similarity_corelation.cpp +++ b/internal/core/unittest/test_similarity_corelation.cpp @@ -15,9 +15,9 @@ TEST(SimilarityCorelation, Naive) { ASSERT_TRUE(milvus::segcore::PositivelyRelated(faiss::METRIC_INNER_PRODUCT)); - ASSERT_TRUE(milvus::segcore::PositivelyRelated(faiss::METRIC_Jaccard)); - ASSERT_TRUE(milvus::segcore::PositivelyRelated(faiss::METRIC_Tanimoto)); + ASSERT_FALSE(milvus::segcore::PositivelyRelated(faiss::METRIC_Jaccard)); + ASSERT_FALSE(milvus::segcore::PositivelyRelated(faiss::METRIC_Tanimoto)); ASSERT_FALSE(milvus::segcore::PositivelyRelated(faiss::METRIC_L2)); ASSERT_FALSE(milvus::segcore::PositivelyRelated(faiss::METRIC_Hamming)); ASSERT_FALSE(milvus::segcore::PositivelyRelated(faiss::METRIC_Substructure)); diff --git a/internal/proxy/task.go b/internal/proxy/task.go index b91c679f1e..2d9022fb85 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -46,6 +46,7 @@ import ( "github.com/milvus-io/milvus/internal/proto/querypb" "github.com/milvus-io/milvus/internal/proto/schemapb" "github.com/milvus-io/milvus/internal/types" + "github.com/milvus-io/milvus/internal/util/distance" "github.com/milvus-io/milvus/internal/util/funcutil" "github.com/milvus-io/milvus/internal/util/indexparamcheck" "github.com/milvus-io/milvus/internal/util/timerecord" @@ -1831,8 +1832,7 @@ func reduceSearchResultData(searchResultData []*schemapb.SearchResultData, nq in log.Debug("skip duplicated search result", zap.Int64("count", skipDupCnt)) ret.Results.TopK = realTopK - if metricType != "IP" { - // if !distance.PositivelyRelated(metricType) { + if !distance.PositivelyRelated(metricType) { for k := range ret.Results.Scores { ret.Results.Scores[k] *= -1 } diff --git a/internal/util/distance/similarity_corelation.go b/internal/util/distance/similarity_corelation.go index 7a0fb57e35..04b2a52912 100644 --- a/internal/util/distance/similarity_corelation.go +++ b/internal/util/distance/similarity_corelation.go @@ -15,7 +15,5 @@ import "strings" func PositivelyRelated(metricType string) bool { mUpper := strings.ToUpper(metricType) - return mUpper == strings.ToUpper(IP) || - mUpper == strings.ToUpper(JACCARD) || - mUpper == strings.ToUpper(TANIMOTO) + return mUpper == strings.ToUpper(IP) } diff --git a/internal/util/distance/similarity_corelation_test.go b/internal/util/distance/similarity_corelation_test.go index ebbda06cce..4d984ef90f 100644 --- a/internal/util/distance/similarity_corelation_test.go +++ b/internal/util/distance/similarity_corelation_test.go @@ -24,11 +24,11 @@ func TestPositivelyRelated(t *testing.T) { }, { JACCARD, - true, + false, }, { TANIMOTO, - true, + false, }, { L2,