mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 19:08:30 +08:00
Fix similarity correlation (#12511)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>
This commit is contained in:
parent
b08e28abc1
commit
1db1cf2104
@ -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
|
||||
|
@ -68,8 +68,7 @@ Search(CSegmentInterface c_segment,
|
||||
auto plan = (milvus::query::Plan*)c_plan;
|
||||
auto phg_ptr = reinterpret_cast<const milvus::query::PlaceholderGroup*>(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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ func TestPositivelyRelated(t *testing.T) {
|
||||
},
|
||||
{
|
||||
JACCARD,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
TANIMOTO,
|
||||
true,
|
||||
false,
|
||||
},
|
||||
{
|
||||
L2,
|
||||
|
Loading…
Reference in New Issue
Block a user