Add COSINE metric type (#23350)

Signed-off-by: Yudong Cai <yudong.cai@zilliz.com>
This commit is contained in:
Cai Yudong 2023-04-20 10:20:31 +08:00 committed by GitHub
parent 4336ed8609
commit 2725d38b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 7 deletions

View File

@ -132,9 +132,17 @@ IsMetricType(const std::string_view str,
return !strcasecmp(str.data(), metric_type.c_str());
}
inline bool
IsFloatMetricType(const knowhere::MetricType& metric_type) {
return IsMetricType(metric_type, knowhere::metric::L2) ||
IsMetricType(metric_type, knowhere::metric::IP) ||
IsMetricType(metric_type, knowhere::metric::COSINE);
}
inline bool
PositivelyRelated(const knowhere::MetricType& metric_type) {
return IsMetricType(metric_type, knowhere::metric::IP);
return IsMetricType(metric_type, knowhere::metric::IP) ||
IsMetricType(metric_type, knowhere::metric::COSINE);
}
inline std::string

View File

@ -30,9 +30,7 @@ CheckBruteForceSearchParam(const FieldMeta& field,
AssertInfo(datatype_is_vector(data_type),
"[BruteForceSearch] Data type isn't vector type");
bool is_float_data_type = (data_type == DataType::VECTOR_FLOAT);
bool is_float_metric_type =
IsMetricType(metric_type, knowhere::metric::IP) ||
IsMetricType(metric_type, knowhere::metric::L2);
bool is_float_metric_type = IsFloatMetricType(metric_type);
AssertInfo(is_float_data_type == is_float_metric_type,
"[BruteForceSearch] Data type and metric type miss-match");
}

View File

@ -11,7 +11,7 @@
# or implied. See the License for the specific language governing permissions and limitations under the License.
#-------------------------------------------------------------------------------
set( KNOWHERE_VERSION 4a7b77b )
set( KNOWHERE_VERSION 2fa9067d )
message(STATUS "Building knowhere-${KNOWHERE_SOURCE_VER} from source")
message(STATUS ${CMAKE_BUILD_TYPE})

View File

@ -28,6 +28,8 @@ const (
L2 = "L2"
// IP represents the inner product distance
IP = "IP"
// COSINE represents the cosine distance
COSINE = "COSINE"
// HAMMING represents the hamming distance
HAMMING = "HAMMING"
// TANIMOTO represents the tanimoto distance

View File

@ -21,5 +21,5 @@ import "strings"
// PositivelyRelated return if metricType are "ip" or "IP"
func PositivelyRelated(metricType string) bool {
mUpper := strings.ToUpper(metricType)
return mUpper == strings.ToUpper(IP)
return mUpper == strings.ToUpper(IP) || mUpper == strings.ToUpper(COSINE)
}

View File

@ -31,6 +31,9 @@ const (
// IP represents inner product distance
IP = "IP"
// COSINE represents cosine distance
COSINE = "COSINE"
// HAMMING represents hamming distance
HAMMING = "HAMMING"
@ -84,7 +87,7 @@ const (
)
// METRICS is a set of all metrics types supported for float vector.
var METRICS = []string{L2, IP} // const
var METRICS = []string{L2, IP, COSINE} // const
// BinIDMapMetrics is a set of all metric types supported for binary vector.
var BinIDMapMetrics = []string{HAMMING, JACCARD, TANIMOTO, SUBSTRUCTURE, SUPERSTRUCTURE} // const