diff --git a/internal/proxy/task_index.go b/internal/proxy/task_index.go index 2b03517659..7b215dff55 100644 --- a/internal/proxy/task_index.go +++ b/internal/proxy/task_index.go @@ -131,14 +131,10 @@ func (cit *createIndexTask) parseIndexParams() error { if isVecIndex { specifyIndexType, exist := indexParamsMap[common.IndexTypeKey] if Params.AutoIndexConfig.Enable { - if exist { - if specifyIndexType != AutoIndexName { - return fmt.Errorf("IndexType should be %s", AutoIndexName) - } - } log.Info("create index trigger AutoIndex", - zap.String("type", Params.AutoIndexConfig.AutoIndexTypeName)) - // override params + zap.String("original type", specifyIndexType), + zap.String("final type", Params.AutoIndexConfig.AutoIndexTypeName)) + // override params by autoindex for k, v := range Params.AutoIndexConfig.IndexParams { indexParamsMap[k] = v } diff --git a/internal/proxy/task_index_test.go b/internal/proxy/task_index_test.go index 9f0bc2c75a..ba301423dc 100644 --- a/internal/proxy/task_index_test.go +++ b/internal/proxy/task_index_test.go @@ -375,4 +375,99 @@ func Test_parseIndexParams(t *testing.T) { }, }, cit.newTypeParams) }) + + cit2 := &createIndexTask{ + Condition: nil, + req: &milvuspb.CreateIndexRequest{ + Base: nil, + DbName: "", + CollectionName: "", + FieldName: "", + ExtraParams: []*commonpb.KeyValuePair{ + { + Key: "index_type", + Value: "IVF_FLAT", + }, + { + Key: MetricTypeKey, + Value: "L2", + }, + { + Key: "params", + Value: "{\"nlist\": 100}", + }, + { + Key: DimKey, + Value: "128", + }, + }, + IndexName: "", + }, + ctx: nil, + rootCoord: nil, + indexCoord: 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 2", func(t *testing.T) { + Params.AutoIndexConfig.Enable = true + Params.AutoIndexConfig.IndexParams = map[string]string{ + "index_type": "HNSW", + "M": "10", + "efConstruction": "100", + } + err := cit2.parseIndexParams() + assert.NoError(t, err) + + assert.ElementsMatch(t, + []*commonpb.KeyValuePair{ + { + Key: "index_type", + Value: "HNSW", + }, + { + Key: MetricTypeKey, + Value: "L2", + }, + { + Key: "M", + Value: "10", + }, + { + Key: "efConstruction", + Value: "100", + }, + { + Key: "nlist", + Value: "100", + }, + }, cit2.newIndexParams) + assert.ElementsMatch(t, + []*commonpb.KeyValuePair{ + { + Key: DimKey, + Value: "128", + }, + }, cit2.newTypeParams) + }) } diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index f264a65353..cd2fc698f4 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -1482,6 +1482,39 @@ class TestCollectionSearch(TestcaseBase): "limit": default_limit, "_async": _async}) + @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.parametrize("M", [4, 64]) + @pytest.mark.parametrize("efConstruction", [8, 512]) + @pytest.mark.parametrize("limit", [1, 10, 3000]) + def test_search_HNSW_index_with_redundant_param(self, M, efConstruction, limit, auto_id, _async): + """ + target: test search HNSW index with redundant param + method: connect milvus, create collection , insert, create index, load and search + expected: search successfully + """ + dim = M * 4 + ef = limit + self._connect() + collection_w, _, _, insert_ids, time_stamp = self.init_collection_general(prefix, True, + partition_num=1, + auto_id=auto_id, + dim=dim, is_index=True)[0:5] + HNSW_index_params = {"M": M, "efConstruction": efConstruction, "nlist": 100} # nlist is of no use + HNSW_index = {"index_type": "HNSW", "params": HNSW_index_params, "metric_type": "L2"} + collection_w.create_index("float_vector", HNSW_index) + collection_w.load() + search_param = {"metric_type": "L2", "params": {"ef": ef, "nprobe": 10}} # nprobe is of no use + vectors = [[random.random() for _ in range(dim)] for _ in range(default_nq)] + collection_w.search(vectors[:default_nq], default_search_field, + search_param, limit, + default_search_exp, _async=_async, + travel_timestamp=0, + check_task=CheckTasks.check_search_results, + check_items={"nq": default_nq, + "ids": insert_ids, + "limit": limit, + "_async": _async}) + @pytest.mark.tags(CaseLabel.L1) @pytest.mark.parametrize("M", [4, 64]) @pytest.mark.parametrize("efConstruction", [8, 512])