Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update check for sparse hnsw index #33713

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/proxy/task_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (

AutoIndexName = "AUTOINDEX"
DimKey = common.DimKey
IsSparseKey = common.IsSparseKey
)

type createIndexTask struct {
Expand Down Expand Up @@ -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 {
Expand All @@ -399,6 +405,10 @@ func checkTrain(field *schemapb.FieldSchema, indexParams map[string]string) erro
return err
}

if isSparse {
delete(indexParams, IsSparseKey)
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const (
DropRatioBuildKey = "drop_ratio_build"

BitmapCardinalityLimitKey = "bitmap_cardinality_limit"
IsSparseKey = "is_sparse"
)

// Collection properties key
Expand Down
23 changes: 21 additions & 2 deletions pkg/util/indexparamcheck/base_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/indexparamcheck/base_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()
Expand Down
Loading