diff --git a/internal/proxy/task_index.go b/internal/proxy/task_index.go index 9a510f3845..bec40f6239 100644 --- a/internal/proxy/task_index.go +++ b/internal/proxy/task_index.go @@ -63,6 +63,7 @@ type createIndexTask struct { isAutoIndex bool newIndexParams []*commonpb.KeyValuePair + newTypeParams []*commonpb.KeyValuePair collectionID UniqueID fieldSchema *schemapb.FieldSchema @@ -167,20 +168,27 @@ func (cit *createIndexTask) parseIndexParams() error { } } typeParams := cit.fieldSchema.GetTypeParams() - typeParamsMap := make(map[string]interface{}) + typeParamsMap := make(map[string]string) for _, pair := range typeParams { - typeParamsMap[pair.Key] = struct{}{} + typeParamsMap[pair.Key] = pair.Value } for k, v := range indexParamsMap { //Currently, it is required that type_params and index_params do not have same keys. - _, ok := typeParamsMap[k] - if ok { + if k == DimKey || k == maxVarCharLengthKey { + delete(indexParamsMap, k) continue } cit.newIndexParams = append(cit.newIndexParams, &commonpb.KeyValuePair{Key: k, Value: v}) } + for k, v := range typeParamsMap { + if _, ok := indexParamsMap[k]; ok { + continue + } + cit.newTypeParams = append(cit.newTypeParams, &commonpb.KeyValuePair{Key: k, Value: v}) + } + return nil } diff --git a/internal/proxy/task_index_test.go b/internal/proxy/task_index_test.go index 677130b0b6..491013ca3e 100644 --- a/internal/proxy/task_index_test.go +++ b/internal/proxy/task_index_test.go @@ -274,3 +274,90 @@ func TestCreateIndexTask_PreExecute(t *testing.T) { assert.NoError(t, err) }) } + +func Test_parseIndexParams(t *testing.T) { + cit := &createIndexTask{ + Condition: nil, + req: &milvuspb.CreateIndexRequest{ + Base: nil, + DbName: "", + CollectionName: "", + FieldName: "", + ExtraParams: []*commonpb.KeyValuePair{ + { + Key: "index_type", + Value: "HNSW", + }, + { + Key: MetricTypeKey, + Value: "IP", + }, + { + Key: "params", + Value: "{\"M\": 48, \"efConstruction\": 64}", + }, + { + Key: DimKey, + Value: "128", + }, + }, + IndexName: "", + }, + ctx: nil, + rootCoord: nil, + queryCoord: nil, + result: nil, + isAutoIndex: false, + newIndexParams: nil, + newTypeParams: nil, + collectionID: 0, + fieldSchema: &schemapb.FieldSchema{ + FieldID: 101, + Name: "FieldID", + IsPrimaryKey: false, + Description: "field no.1", + DataType: schemapb.DataType_FloatVector, + TypeParams: []*commonpb.KeyValuePair{ + { + Key: DimKey, + Value: "128", + }, + { + Key: MetricTypeKey, + Value: "L2", + }, + }}, + } + + t.Run("parse index params", func(t *testing.T) { + err := cit.parseIndexParams() + assert.NoError(t, err) + + assert.ElementsMatch(t, + []*commonpb.KeyValuePair{ + { + Key: "index_type", + Value: "HNSW", + }, + { + Key: MetricTypeKey, + Value: "IP", + }, + { + Key: "M", + Value: "48", + }, + { + Key: "efConstruction", + Value: "64", + }, + }, cit.newIndexParams) + assert.ElementsMatch(t, + []*commonpb.KeyValuePair{ + { + Key: DimKey, + Value: "128", + }, + }, cit.newTypeParams) + }) +}