From 37152d58bbfbc294ce23b4651c10029c64e56346 Mon Sep 17 00:00:00 2001 From: NicoYuan1986 <109071306+NicoYuan1986@users.noreply.github.com> Date: Wed, 14 Dec 2022 19:27:35 +0800 Subject: [PATCH] Add test cases of index annoy (#21220) Signed-off-by: nico Signed-off-by: nico --- tests/python_client/common/common_func.py | 2 ++ tests/python_client/testcases/test_index.py | 21 +++++++++++++++-- tests/python_client/testcases/test_search.py | 24 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/tests/python_client/common/common_func.py b/tests/python_client/common/common_func.py index 950dc6175e..4c3415bfd6 100644 --- a/tests/python_client/common/common_func.py +++ b/tests/python_client/common/common_func.py @@ -536,6 +536,7 @@ def gen_normal_expressions(): ] return expressions + def gen_field_compare_expressions(): expressions = [ "int64_1 | int64_2 == 1", @@ -551,6 +552,7 @@ def gen_field_compare_expressions(): ] return expressions + def gen_normal_string_expressions(field): expressions = [ f"\"0\"< {field} < \"3\"", diff --git a/tests/python_client/testcases/test_index.py b/tests/python_client/testcases/test_index.py index 1e8925cb1a..3429fcf98e 100644 --- a/tests/python_client/testcases/test_index.py +++ b/tests/python_client/testcases/test_index.py @@ -1264,6 +1264,22 @@ class TestIndexInvalid(TestcaseBase): "err_msg": "index cannot be dropped, collection is " "loaded, please release it first"}) + @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.parametrize("n_trees", [-1, 1025, 'a', {34}]) + def test_annoy_index_with_invalid_params(self, n_trees): + """ + target: test create index with invalid params + method: 1. set annoy index param n_trees out of range [1, 1024] + 2. set annoy index param n_trees type invalid(not int) + expected: raise exception + """ + collection_w = self.init_collection_general(prefix, True, is_index=True)[0] + index_annoy = {"index_type": "ANNOY", "params": {"n_trees": n_trees}, "metric_type": "L2"} + collection_w.create_index("float_vector", index_annoy, + check_task=CheckTasks.err_res, + check_items={"err_code": 1, + "err_msg": "invalid index params"}) + class TestNewIndexAsync(TestcaseBase): @pytest.fixture(scope="function", params=[False, True]) @@ -1553,7 +1569,8 @@ class TestIndexString(TestcaseBase): assert collection_w.has_index(index_name=index_name2)[0] == True collection_w.drop_index(index_name=index_name2) assert len(collection_w.indexes) == 0 - + + class TestIndexDiskann(TestcaseBase): """ ****************************************************************** @@ -1835,4 +1852,4 @@ class TestIndexDiskann(TestcaseBase): collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index, check_task=CheckTasks.err_res, check_items={ct.err_code: 1, - ct.err_msg: "invalid index params"}) \ No newline at end of file + ct.err_msg: "invalid index params"}) diff --git a/tests/python_client/testcases/test_search.py b/tests/python_client/testcases/test_search.py index d2dd5ddf55..608f87f960 100644 --- a/tests/python_client/testcases/test_search.py +++ b/tests/python_client/testcases/test_search.py @@ -330,6 +330,30 @@ class TestCollectionSearchInvalid(TestcaseBase): check_items={"err_code": 1, "err_msg": message}) + @pytest.mark.skip("not fixed yet") + @pytest.mark.tags(CaseLabel.L1) + @pytest.mark.parametrize("search_k", [-10, -1, 0, 10, 125]) + def test_search_param_invalid_annoy_index(self, search_k): + """ + target: test search with invalid search params matched with annoy index + method: search with invalid param search_k out of [top_k, ∞) + expected: raise exception and report the error + """ + # 1. initialize with data + collection_w = self.init_collection_general(prefix, True, 3000, is_index=True)[0] + # 2. create annoy index and load + index_annoy = {"index_type": "ANNOY", "params": {"n_trees": 512}, "metric_type": "L2"} + collection_w.create_index("float_vector", index_annoy) + collection_w.load() + # 3. search + annoy_search_param = {"index_type": "ANNOY", "search_params": {"search_k": search_k}} + collection_w.search(vectors[:default_nq], default_search_field, + annoy_search_param, default_limit, + default_search_exp, + check_task=CheckTasks.err_res, + check_items={"err_code": 1, + "err_msg": "Search params check failed"}) + @pytest.mark.tags(CaseLabel.L2) def test_search_param_invalid_limit_type(self, get_invalid_limit): """