fix: update check for sparse hnsw index (#33713)

issue: #29419

Signed-off-by: Buqian Zheng <zhengbuqian@gmail.com>
This commit is contained in:
Buqian Zheng 2024-07-02 21:56:09 +08:00 committed by GitHub
parent ec5db7a57d
commit fa8d641ce6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 3 deletions

View File

@ -51,6 +51,7 @@ const (
AutoIndexName = "AUTOINDEX"
DimKey = common.DimKey
IsSparseKey = common.IsSparseKey
)
type createIndexTask struct {
@ -383,10 +384,15 @@ func checkTrain(field *schemapb.FieldSchema, indexParams map[string]string) erro
}
}
if !typeutil.IsSparseFloatVectorType(field.DataType) {
isSparse := typeutil.IsSparseFloatVectorType(field.DataType)
if !isSparse {
if err := fillDimension(field, indexParams); err != nil {
return err
}
} else {
// used only for checker, should be deleted after checking
indexParams[IsSparseKey] = "true"
}
if err := checker.CheckValidDataType(field.GetDataType()); err != nil {
@ -399,6 +405,10 @@ func checkTrain(field *schemapb.FieldSchema, indexParams map[string]string) erro
return err
}
if isSparse {
delete(indexParams, IsSparseKey)
}
return nil
}

View File

@ -120,6 +120,7 @@ const (
DropRatioBuildKey = "drop_ratio_build"
BitmapCardinalityLimitKey = "bitmap_cardinality_limit"
IsSparseKey = "is_sparse"
)
// Collection properties key

View File

@ -19,18 +19,37 @@ package indexparamcheck
import (
"fmt"
"math"
"strings"
"github.com/cockroachdb/errors"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
)
type baseChecker struct{}
func (c baseChecker) CheckTrain(params map[string]string) error {
// vector dimension should be checked on collection creation. this is just some basic check
if !CheckIntByRange(params, DIM, 1, math.MaxInt) {
return fmt.Errorf("failed to check vector dimension, should be larger than 0 and smaller than math.MaxInt")
isSparse := false
if val, exist := params[common.IsSparseKey]; exist {
val = strings.ToLower(val)
if val != "true" && val != "false" {
return fmt.Errorf("invalid is_sparse value: %s, must be true or false", val)
}
if val == "true" {
isSparse = true
}
}
if isSparse {
if !CheckStrByValues(params, Metric, SparseMetrics) {
return fmt.Errorf("metric type not found or not supported for sparse float vectors, supported: %v", SparseMetrics)
}
} else {
// we do not check dim for sparse
if !CheckIntByRange(params, DIM, 1, math.MaxInt) {
return fmt.Errorf("failed to check vector dimension, should be larger than 0 and smaller than math.MaxInt")
}
}
return nil
}

View File

@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
"github.com/milvus-io/milvus/pkg/common"
"github.com/milvus-io/milvus/pkg/util/metric"
)
@ -18,12 +19,27 @@ func Test_baseChecker_CheckTrain(t *testing.T) {
paramsWithoutDim := map[string]string{
Metric: metric.L2,
}
sparseParamsWithoutDim := map[string]string{
Metric: metric.IP,
common.IsSparseKey: "tRue",
}
sparseParamsWrongMetric := map[string]string{
Metric: metric.L2,
common.IsSparseKey: "True",
}
badSparseParams := map[string]string{
Metric: metric.IP,
common.IsSparseKey: "ds",
}
cases := []struct {
params map[string]string
errIsNil bool
}{
{validParams, true},
{paramsWithoutDim, false},
{sparseParamsWithoutDim, true},
{sparseParamsWrongMetric, false},
{badSparseParams, false},
}
c := newBaseChecker()