milvus/pkg/util/indexparamcheck/hnsw_checker.go
Gao a789c60380
enhance: autoindex for multi data type (#33868)
issue: #22837 

contain https://github.com/milvus-io/milvus/pull/33625
https://github.com/milvus-io/milvus/pull/33867
https://github.com/milvus-io/milvus/pull/33911 which already merged to
2.4 branch

Signed-off-by: chasingegg <chao.gao@zilliz.com>
Co-authored-by: foxspy <xianliang.li@zilliz.com>
2024-06-18 21:34:01 +08:00

55 lines
1.7 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 hnswChecker struct {
baseChecker
}
func (c hnswChecker) StaticCheck(params map[string]string) error {
if !CheckIntByRange(params, EFConstruction, HNSWMinEfConstruction, HNSWMaxEfConstruction) {
return errOutOfRange(EFConstruction, HNSWMinEfConstruction, HNSWMaxEfConstruction)
}
if !CheckIntByRange(params, HNSWM, HNSWMinM, HNSWMaxM) {
return errOutOfRange(HNSWM, HNSWMinM, HNSWMaxM)
}
if !CheckStrByValues(params, Metric, HnswMetrics) {
return fmt.Errorf("metric type %s not found or not supported, supported: %v", params[Metric], HnswMetrics)
}
return nil
}
func (c hnswChecker) CheckTrain(params map[string]string) error {
if err := c.StaticCheck(params); err != nil {
return err
}
return c.baseChecker.CheckTrain(params)
}
func (c hnswChecker) CheckValidDataType(dType schemapb.DataType) error {
if !typeutil.IsVectorType(dType) {
return fmt.Errorf("can't build hnsw in not vector type.")
}
return nil
}
func (c hnswChecker) SetDefaultMetricTypeIfNotExist(params map[string]string, dType schemapb.DataType) {
if typeutil.IsDenseFloatVectorType(dType) {
setDefaultIfNotExist(params, common.MetricTypeKey, FloatVectorDefaultMetricType)
} else if typeutil.IsSparseFloatVectorType(dType) {
setDefaultIfNotExist(params, common.MetricTypeKey, SparseFloatVectorDefaultMetricType)
} else if typeutil.IsBinaryVectorType(dType) {
setDefaultIfNotExist(params, common.MetricTypeKey, BinaryVectorDefaultMetricType)
}
}
func newHnswChecker() IndexChecker {
return &hnswChecker{}
}