From ba86c1663d9282031a676d6c55bda6ac40bee8d9 Mon Sep 17 00:00:00 2001 From: ZeFeng Yin Date: Tue, 10 Mar 2026 16:09:37 +0800 Subject: [PATCH] fix: add validator for cosine metric with int8 (#209) --- src/db/index/common/schema.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/db/index/common/schema.cc b/src/db/index/common/schema.cc index 02789c6..1f74353 100644 --- a/src/db/index/common/schema.cc +++ b/src/db/index/common/schema.cc @@ -160,6 +160,16 @@ Status FieldSchema::validate() const { "types according to the IP metric"); } } + if (vector_index_params->metric_type() == MetricType::COSINE) { + if (data_type_ != DataType::VECTOR_FP16 && + data_type_ != DataType::VECTOR_FP32) { + return Status::InvalidArgument( + "schema validate failed: cosine metric only supports FP32/FP16 " + "data types, but field[", + name_, "]'s data type is ", + DataTypeCodeBook::AsString(data_type_)); + } + } } } else { if (index_params_) {