milvus/pkg/util/indexparamcheck/float_vector_base_checker.go
Cai Yudong 00438f408f
enhance: Unify data type check APIs for go (#31887)
Issue: #22837

Signed-off-by: Cai Yudong <yudong.cai@zilliz.com>
2024-04-07 14:27:22 +08:00

45 lines
1.1 KiB
Go

package indexparamcheck
import (
"fmt"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)
type floatVectorBaseChecker struct {
baseChecker
}
func (c floatVectorBaseChecker) staticCheck(params map[string]string) error {
if !CheckStrByValues(params, Metric, METRICS) {
return fmt.Errorf("metric type %s not found or not supported, supported: %v", params[Metric], METRICS)
}
return nil
}
func (c floatVectorBaseChecker) CheckTrain(params map[string]string) error {
if err := c.baseChecker.CheckTrain(params); err != nil {
return err
}
return c.staticCheck(params)
}
func (c floatVectorBaseChecker) CheckValidDataType(dType schemapb.DataType) error {
if !typeutil.IsDenseFloatVectorType(dType) {
return fmt.Errorf("data type should be FloatVector, Float16Vector or BFloat16Vector")
}
return nil
}
func (c floatVectorBaseChecker) SetDefaultMetricTypeIfNotExist(params map[string]string) {
setDefaultIfNotExist(params, common.MetricTypeKey, FloatVectorDefaultMetricType)
}
func newFloatVectorBaseChecker() IndexChecker {
return &floatVectorBaseChecker{}
}