2022-10-31 17:27:35 +08:00
|
|
|
from time import sleep
|
2021-05-11 17:59:29 +08:00
|
|
|
import pytest
|
2023-06-08 09:12:35 +08:00
|
|
|
import copy
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
from base.client_base import TestcaseBase
|
2021-06-04 09:35:34 +08:00
|
|
|
from base.index_wrapper import ApiIndexWrapper
|
2021-05-13 12:17:15 +08:00
|
|
|
from utils.util_log import test_log as log
|
2021-05-25 19:09:31 +08:00
|
|
|
from common import common_func as cf
|
|
|
|
from common import common_type as ct
|
2021-06-09 14:23:48 +08:00
|
|
|
from common.common_type import CaseLabel, CheckTasks
|
2021-07-15 15:03:54 +08:00
|
|
|
from common.code_mapping import CollectionErrorMessage as clem
|
|
|
|
from common.code_mapping import IndexErrorMessage as iem
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-12-22 17:07:48 +08:00
|
|
|
from utils.util_pymilvus import *
|
2021-08-31 18:49:59 +08:00
|
|
|
from common.constants import *
|
2022-04-19 15:41:39 +08:00
|
|
|
from pymilvus.exceptions import MilvusException
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
prefix = "index"
|
|
|
|
default_schema = cf.gen_default_collection_schema()
|
|
|
|
default_field_name = ct.default_float_vec_field_name
|
2023-06-20 11:26:41 +08:00
|
|
|
default_index_params = {"index_type": "IVF_SQ8", "metric_type": "COSINE", "params": {"nlist": 64}}
|
2023-06-08 09:12:35 +08:00
|
|
|
default_autoindex_params = {"index_type": "AUTOINDEX", "metric_type": "IP"}
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
# copied from pymilvus
|
|
|
|
uid = "test_index"
|
2022-01-06 09:35:30 +08:00
|
|
|
# BUILD_TIMEOUT = 300
|
2021-08-31 18:49:59 +08:00
|
|
|
field_name = default_float_vec_field_name
|
|
|
|
binary_field_name = default_binary_vec_field_name
|
2022-06-01 18:56:03 +08:00
|
|
|
default_string_field_name = ct.default_string_field_name
|
|
|
|
index_name1 = cf.gen_unique_str("float")
|
|
|
|
index_name2 = cf.gen_unique_str("varhar")
|
|
|
|
index_name3 = cf.gen_unique_str("binary")
|
|
|
|
default_string_index_params = {}
|
2022-05-11 21:55:53 +08:00
|
|
|
default_binary_schema = cf.gen_default_binary_collection_schema()
|
|
|
|
default_binary_index_params = {"index_type": "BIN_IVF_FLAT", "metric_type": "JACCARD", "params": {"nlist": 64}}
|
2021-10-11 15:32:55 +08:00
|
|
|
# query = gen_search_vectors_params(field_name, default_entities, default_top_k, 1)
|
2021-08-31 18:49:59 +08:00
|
|
|
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
|
2022-05-12 16:15:54 +08:00
|
|
|
default_ip_index_params = {"index_type": "IVF_FLAT", "metric_type": "IP", "params": {"nlist": 64}}
|
|
|
|
default_nq = ct.default_nq
|
|
|
|
default_limit = ct.default_limit
|
|
|
|
default_search_exp = "int64 >= 0"
|
|
|
|
default_search_field = ct.default_float_vec_field_name
|
|
|
|
default_search_params = ct.default_search_params
|
2022-06-01 18:56:03 +08:00
|
|
|
default_search_ip_params = ct.default_search_ip_params
|
2022-05-15 20:43:55 +08:00
|
|
|
default_search_binary_params = ct.default_search_binary_params
|
2023-06-20 11:26:41 +08:00
|
|
|
default_nb = ct.default_nb
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestIndexParams(TestcaseBase):
|
2021-05-25 19:09:31 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.parametrize("collection", [None, "coll"])
|
|
|
|
def test_index_non_collection(self, collection):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
2021-05-27 16:58:11 +08:00
|
|
|
target: test index with None collection
|
|
|
|
method: input none collection object
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
self._connect()
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection, default_field_name, default_index_params, check_task=CheckTasks.err_res,
|
2021-07-15 15:03:54 +08:00
|
|
|
check_items={ct.err_code: 0, ct.err_msg: clem.CollectionType})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-07-15 15:03:54 +08:00
|
|
|
@pytest.mark.parametrize("field_name", ct.get_invalid_strs)
|
|
|
|
def test_index_field_name_invalid(self, field_name):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error field name
|
|
|
|
method: input field name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-07-15 15:03:54 +08:00
|
|
|
collection_name = cf.gen_unique_str(prefix)
|
|
|
|
|
|
|
|
collection_w = self.init_collection_wrap(name=collection_name)
|
|
|
|
|
2021-09-16 17:21:49 +08:00
|
|
|
log.error(iem.WrongFieldName % str(field_name))
|
2021-07-15 15:03:54 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, field_name, default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
2021-09-16 17:21:49 +08:00
|
|
|
ct.err_msg: iem.WrongFieldName % str(field_name)})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_field_name_not_existed(self):
|
|
|
|
"""
|
|
|
|
target: test index with error field name
|
|
|
|
method: input field name not created
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
f_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, f_name, default_index_params, check_task=CheckTasks.err_res,
|
2021-09-16 17:21:49 +08:00
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: f"cannot create index on non-existed field: {f_name}"})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-09-17 11:59:49 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.parametrize("index_type", ct.get_invalid_strs)
|
|
|
|
def test_index_type_invalid(self, index_type):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error index type
|
|
|
|
method: input invalid index type
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = copy.deepcopy(default_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
index_params["index_type"] = index_type
|
2021-06-23 16:50:07 +08:00
|
|
|
if not isinstance(index_params["index_type"], str):
|
|
|
|
msg = "must be str"
|
|
|
|
else:
|
|
|
|
msg = "Invalid index_type"
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: msg})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_type_not_supported(self):
|
|
|
|
"""
|
|
|
|
target: test index with error index type
|
|
|
|
method: input unsupported index type
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = copy.deepcopy(default_index_params)
|
|
|
|
index_params["index_type"] = "IVFFFFFFF"
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_params_invalid(self, get_invalid_index_params):
|
|
|
|
"""
|
|
|
|
target: test index with error index params
|
|
|
|
method: input invalid index params
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = get_invalid_index_params
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2022-09-28 14:32:55 +08:00
|
|
|
@pytest.mark.parametrize("index_name", ["_1ndeX", "In_t0"])
|
|
|
|
def test_index_naming_rules(self, index_name):
|
|
|
|
"""
|
|
|
|
target: test index naming rules
|
|
|
|
method: 1. connect milvus
|
|
|
|
2. Create a collection
|
|
|
|
3. Create an index with an index_name which uses all the supported elements in the naming rules
|
|
|
|
expected: Index create successfully
|
|
|
|
"""
|
|
|
|
self._connect()
|
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
collection_w.create_index(default_field_name, default_index_params, index_name=index_name)
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
assert collection_w.indexes[0].index_name == index_name
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
@pytest.mark.parametrize("index_name", ["_1ndeX", "In_0"])
|
|
|
|
def test_index_same_index_name_two_fields(self, index_name):
|
|
|
|
"""
|
|
|
|
target: test index naming rules
|
|
|
|
method: 1. connect milvus
|
|
|
|
2. Create a collection with more than 3 fields
|
|
|
|
3. Create two indexes on two fields with the same index name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
self._connect()
|
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params,
|
|
|
|
index_name=index_name)
|
|
|
|
self.index_wrap.init_index(collection_w.collection, ct.default_int64_field_name, default_index_params,
|
|
|
|
index_name=index_name,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "CreateIndex failed: index already exist, "
|
|
|
|
"but parameters are inconsistent"})
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2022-10-16 21:05:25 +08:00
|
|
|
# @pytest.mark.xfail(reason="issue 19181")
|
|
|
|
@pytest.mark.parametrize("get_invalid_index_name", ["1nDex", "$in4t", "12 s", "(中文)"])
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_index_name_invalid(self, get_invalid_index_name):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error index name
|
|
|
|
method: input invalid index name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
index_name = get_invalid_index_name
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params,
|
2022-10-16 21:05:25 +08:00
|
|
|
index_name=get_invalid_index_name,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "Invalid index name"})
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2021-08-31 18:49:59 +08:00
|
|
|
class TestIndexOperation(TestcaseBase):
|
2021-05-11 17:59:29 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
2021-11-10 15:07:37 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_create_with_different_indexes(self):
|
|
|
|
"""
|
|
|
|
target: test create index on one field, with two different type of index
|
|
|
|
method: create two different indexes
|
|
|
|
expected: only latest index can be created for a collection
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2022-06-30 15:54:18 +08:00
|
|
|
error = {ct.err_code: 1, ct.err_msg: f"CreateIndex failed: index already exists"}
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index,
|
|
|
|
check_task=CheckTasks.err_res, check_items=error)
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-11-10 15:07:37 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
2022-06-30 15:54:18 +08:00
|
|
|
assert collection_w.indexes[0].params["index_type"] == default_index_params["index_type"]
|
2021-11-10 15:07:37 +08:00
|
|
|
|
2022-10-21 17:09:32 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_create_indexes_for_different_fields(self):
|
|
|
|
"""
|
|
|
|
target: Test create indexes for different fields
|
2022-10-28 10:17:32 +08:00
|
|
|
method: create two different indexes with default index name
|
2022-10-21 17:09:32 +08:00
|
|
|
expected: create successfully
|
|
|
|
"""
|
2022-12-29 17:01:31 +08:00
|
|
|
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
2022-10-21 17:09:32 +08:00
|
|
|
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
|
|
|
|
collection_w.create_index(default_field_name, default_index)
|
|
|
|
collection_w.create_index(ct.default_int64_field_name, {})
|
|
|
|
|
2022-10-26 17:45:33 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_create_on_scalar_field(self):
|
|
|
|
"""
|
|
|
|
target: Test create index on scalar field
|
|
|
|
method: create index on scalar field and load
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2022-12-29 17:01:31 +08:00
|
|
|
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
2022-10-26 17:45:33 +08:00
|
|
|
collection_w.create_index(ct.default_int64_field_name, {})
|
|
|
|
collection_w.load(check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: "there is no vector index on collection, "
|
|
|
|
"please create index firstly"})
|
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_collection_empty(self):
|
|
|
|
"""
|
|
|
|
target: test index with empty collection
|
|
|
|
method: Index on empty collection
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-05-25 19:09:31 +08:00
|
|
|
# TODO: assert index
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-07-15 15:03:54 +08:00
|
|
|
@pytest.mark.parametrize("index_param", [default_index_params])
|
|
|
|
def test_index_params(self, index_param):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with all index type/params
|
|
|
|
method: input valid params
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-12-07 14:19:32 +08:00
|
|
|
data = cf.gen_default_list_data()
|
2021-06-23 16:50:07 +08:00
|
|
|
collection_w.insert(data=data)
|
2021-07-15 15:03:54 +08:00
|
|
|
index_params = index_param
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, index_params)
|
|
|
|
# TODO: assert index
|
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_params_flush(self):
|
|
|
|
"""
|
|
|
|
target: test index with all index type/params
|
|
|
|
method: input valid params
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-12-07 14:19:32 +08:00
|
|
|
data = cf.gen_default_list_data()
|
2021-06-23 16:50:07 +08:00
|
|
|
collection_w.insert(data=data)
|
2022-01-14 12:55:34 +08:00
|
|
|
# flush
|
|
|
|
collection_w.num_entities
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-05-25 19:09:31 +08:00
|
|
|
# TODO: assert index
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-06-23 16:50:07 +08:00
|
|
|
assert collection_w.num_entities == ct.default_nb
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
# TODO: not support
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_name_dup(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with duplicate index name
|
|
|
|
method: create index with existed index name create by `collection.create_index`
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
2021-06-09 14:23:48 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_name = ct.default_index_name
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
collection_w.collection.create_index(default_field_name, default_index_params, index_name=index_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with two indexes
|
|
|
|
method: create index with two different indexes
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_fields(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on two fields, with the same name
|
|
|
|
method: create the same index name with two different fields
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_fields_B(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on two fields, with the different name
|
|
|
|
method: create the different index with two different fields
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names_eq_maximum(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with the different names, num of the names equal to the maximum num supported
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create the different indexes
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names_more_maximum(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with the different names, num of the names more than the maximum num supported
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create the different indexes
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
pass
|
2022-10-31 17:27:35 +08:00
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_index_drop_index(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create index by `index`, and then drop it
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-06-04 09:35:34 +08:00
|
|
|
self.index_wrap.drop()
|
2022-10-31 17:27:35 +08:00
|
|
|
assert len(collection_w.indexes) == 0
|
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
# TODO #7372
|
|
|
|
def test_index_drop_repeatedly(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create index by `index`, and then drop it twice
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
_, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-06-09 14:23:48 +08:00
|
|
|
self.index_wrap.drop()
|
2022-10-31 17:27:35 +08:00
|
|
|
self.index_wrap.drop()
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestIndexAdvanced(TestcaseBase):
|
2021-05-25 19:09:31 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_index_drop_multi_collections(self):
|
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create indexes by `index`, and then drop it, assert there is one index left
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
c_name_2 = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
cw = self.init_collection_wrap(name=c_name)
|
|
|
|
cw2 = self.init_collection_wrap(name=c_name_2)
|
|
|
|
iw_2 = ApiIndexWrapper()
|
2021-06-23 16:50:07 +08:00
|
|
|
self.index_wrap.init_index(cw.collection, default_field_name, default_index_params)
|
|
|
|
index_2, _ = iw_2.init_index(cw2.collection, default_field_name, default_index_params)
|
2021-06-04 09:35:34 +08:00
|
|
|
self.index_wrap.drop()
|
2021-06-09 14:23:48 +08:00
|
|
|
assert cf.assert_equal_index(index_2, cw2.collection.indexes[0])
|
|
|
|
assert len(cw.collection.indexes) == 0
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_drop_during_inserting(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop during inserting
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create indexes by `index`, and then drop it during inserting entities, make sure async insert
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised, insert success
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_drop_during_searching(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop during searching
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create indexes by `index`, and then drop it during searching, make sure async search
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised, search success
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2021-07-02 15:24:17 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_recovery_after_restart(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index still existed after server restart
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create index by `index`, and then restart server, assert index existed
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: index in collection.indexes
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2021-07-02 15:24:17 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_building_after_restart(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: index can still build if not finished before server restart
|
|
|
|
method: create index by `index`, and then restart server, assert server is indexing
|
2021-09-09 17:18:00 +08:00
|
|
|
expected: index build finished after server restart
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
pass
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following classes are copied from pymilvus test
|
|
|
|
******************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-05-12 16:15:54 +08:00
|
|
|
class TestNewIndexBase(TestcaseBase):
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_simple_index()
|
|
|
|
)
|
2022-05-12 16:15:54 +08:00
|
|
|
def get_simple_index(self, request):
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(request.param)
|
2021-08-31 18:49:59 +08:00
|
|
|
return copy.deepcopy(request.param)
|
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_new(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name, shards_num=1)
|
|
|
|
data = cf.gen_default_list_data(nb=5000)
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
log.debug(collection_w.num_entities)
|
2021-08-31 18:49:59 +08:00
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
2022-06-01 18:56:03 +08:00
|
|
|
index_name=ct.default_index_name)
|
2022-05-12 16:15:54 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2022-09-17 08:50:52 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2023-01-19 11:27:44 +08:00
|
|
|
@pytest.mark.skip(reason="The scenario in this case is not existed for each RPC is limited to 64 MB")
|
2022-06-01 18:56:03 +08:00
|
|
|
def test_annoy_index(self):
|
|
|
|
# The strange thing is that the indexnode crash is only reproduced when nb is 50000 and dim is 512
|
|
|
|
nb = 50000
|
|
|
|
dim = 512
|
|
|
|
|
|
|
|
fields = [cf.gen_int64_field(), cf.gen_float_vec_field(dim=dim)]
|
|
|
|
schema = cf.gen_collection_schema(fields, primary_field=ct.default_int64_field_name)
|
|
|
|
collection_w = self.init_collection_wrap(name=cf.gen_unique_str(), schema=schema)
|
|
|
|
|
|
|
|
# use python random to generate the data as usual doesn't reproduce
|
|
|
|
data = [[i for i in range(nb)], np.random.random([nb, dim]).tolist()]
|
|
|
|
collection_w.insert(data)
|
|
|
|
log.debug(collection_w.num_entities)
|
|
|
|
|
|
|
|
index_params = {"index_type": "ANNOY", "metric_type": "IP", "params": {"n_trees": 10}}
|
|
|
|
index_wrapper = ApiIndexWrapper()
|
|
|
|
index, _ = index_wrapper.init_index(collection_w.collection, ct.default_float_vec_field_name, index_params)
|
|
|
|
assert index.params == index_params
|
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_non_existed_field(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index on other field
|
|
|
|
expected: error raised
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_int8_field_name, default_index_params,
|
|
|
|
index_name=ct.default_index_name,
|
|
|
|
check_task=CheckTasks.err_res,
|
2022-06-01 18:56:03 +08:00
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "cannot create index on non-existed field: int8"}
|
2022-05-12 16:15:54 +08:00
|
|
|
)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_no_vectors(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: return success
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
|
|
|
|
index_name=ct.default_index_name)
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_partition(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
ins_res, _ = partition_w.insert(data)
|
|
|
|
assert len(ins_res.primary_keys) == len(data[0])
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_partition_flush(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
partition_w.insert(data)
|
|
|
|
assert collection_w.num_entities == default_nb
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_without_connect(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index without connection
|
|
|
|
method: create collection and add entities in it, check if added successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
self._connect()
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
self.connection_wrap.remove_connection(ct.default_alias)
|
|
|
|
res_list, _ = self.connection_wrap.list_connections()
|
|
|
|
assert ct.default_alias not in res_list
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, ct.default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: "should create connect first"})
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_search_with_query_vectors(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
self._connect()
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
|
|
|
collection_w.load()
|
|
|
|
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.search(vectors[:default_nq], default_search_field,
|
2022-05-12 16:15:54 +08:00
|
|
|
default_search_params, default_limit,
|
|
|
|
default_search_exp)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_multithread(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface with multiprocess
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
def build(collection_w):
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
threads_num = 8
|
|
|
|
threads = []
|
|
|
|
for i in range(threads_num):
|
2022-05-12 16:15:54 +08:00
|
|
|
t = MyThread(target=build, args=(collection_w,))
|
2021-08-31 18:49:59 +08:00
|
|
|
threads.append(t)
|
|
|
|
t.start()
|
|
|
|
time.sleep(0.2)
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_insert_flush(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index
|
|
|
|
method: create collection and create index, add entities in it
|
|
|
|
expected: create index ok, and count correct
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_same_index_repeatedly(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: return code success, and search ok
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
|
|
|
assert len(collection_w.indexes) == 1
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_different_name(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: raise error
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params, index_name="a")
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params, index_name="b",
|
|
|
|
check_task=CheckTasks.err_res,
|
2022-06-01 18:56:03 +08:00
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "CreateIndex failed: creating multiple indexes on same field is not supported"})
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_repeatedly_new(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the different create_index params
|
|
|
|
method: create another index with different index_params after index have been built
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: drop index successfully
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
index_prams = [default_index, {"metric_type": "L2", "index_type": "IVF_SQ8", "params": {"nlist": 1024}}]
|
|
|
|
for index in index_prams:
|
|
|
|
index_name = cf.gen_unique_str("name")
|
|
|
|
collection_w.create_index(default_float_vec_field_name, index, index_name=index_name)
|
|
|
|
collection_w.load()
|
2022-10-19 23:17:44 +08:00
|
|
|
collection_w.release()
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w.drop_index(index_name=index_name)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert len(collection_w.collection.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_no_vectors_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: return success
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params,
|
|
|
|
index_name=ct.default_index_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_partition_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
ins_res, _ = partition_w.insert(data)
|
|
|
|
assert len(ins_res.primary_keys) == len(data[0])
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_partition_flush_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
target: test create index
|
|
|
|
method: create collection and create index, add entities in it
|
|
|
|
expected: create index ok, and count correct
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w = self.init_collection_wrap()
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
partition_w.insert(data)
|
|
|
|
assert collection_w.num_entities == default_nb
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_search_with_query_vectors_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
self._connect()
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
|
|
|
collection_w.load()
|
|
|
|
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
|
|
|
|
collection_w.search(vectors[:default_nq], default_search_field,
|
|
|
|
default_search_ip_params, default_limit,
|
|
|
|
default_search_exp)
|
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-12 16:15:54 +08:00
|
|
|
def test_create_index_multithread_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface with multiprocess
|
|
|
|
method: create collection and add entities in it, create index
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: return success
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
def build(collection_w):
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
threads_num = 8
|
|
|
|
threads = []
|
|
|
|
for i in range(threads_num):
|
2022-05-12 16:15:54 +08:00
|
|
|
t = MyThread(target=build, args=(collection_w,))
|
2021-08-31 18:49:59 +08:00
|
|
|
threads.append(t)
|
|
|
|
t.start()
|
|
|
|
time.sleep(0.2)
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
2022-05-12 16:15:54 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_no_vectors_insert_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2021-12-21 21:17:44 +08:00
|
|
|
target: test create index interface when there is no vectors in collection,
|
|
|
|
and does not affect the subsequent process
|
|
|
|
method: create collection and add no vectors in it, and then create index,
|
|
|
|
add entities in it
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: return insert suceess
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
assert collection_w.num_entities == default_nb
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-12 16:15:54 +08:00
|
|
|
def test_create_same_index_repeatedly_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: return code success, and search ok
|
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params)
|
|
|
|
assert len(collection_w.indexes) == 1
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-12 16:15:54 +08:00
|
|
|
def test_create_index_different_name_ip(self):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: raise error
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params, index_name="a")
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params, index_name="b",
|
2022-06-01 18:56:03 +08:00
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "CreateIndex failed: creating multiple indexes on same field is not supported"})
|
|
|
|
|
2022-10-31 17:27:35 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-05-12 16:15:54 +08:00
|
|
|
def test_create_different_index_repeatedly_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the different create_index params
|
|
|
|
method: create another index with different index_params after index have been built
|
2022-05-12 16:15:54 +08:00
|
|
|
expected: drop index successfully
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-12 16:15:54 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
index_prams = [default_ip_index_params,
|
|
|
|
{"metric_type": "IP", "index_type": "IVF_SQ8", "params": {"nlist": 1024}}]
|
2022-05-12 16:15:54 +08:00
|
|
|
for index in index_prams:
|
|
|
|
index_name = cf.gen_unique_str("name")
|
|
|
|
collection_w.create_index(default_float_vec_field_name, index, index_name=index_name)
|
2022-10-31 17:27:35 +08:00
|
|
|
collection_w.release()
|
2022-05-12 16:15:54 +08:00
|
|
|
collection_w.drop_index(index_name=index_name)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert len(collection_w.collection.indexes) == 0
|
2022-05-12 16:15:54 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-13 17:33:57 +08:00
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `drop_index` function
|
|
|
|
******************************************************************
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
2022-05-13 17:33:57 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
# TODO #7372
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index_repeatedly(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index repeatedly
|
|
|
|
method: create index, call drop index, and drop again
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
2022-05-13 17:33:57 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2022-11-02 10:17:34 +08:00
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index_without_connect(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index without connection
|
|
|
|
method: drop index, and check if drop successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
|
|
|
|
index_name=ct.default_index_name)
|
2022-05-13 17:33:57 +08:00
|
|
|
self.connection_wrap.remove_connection(ct.default_alias)
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name, check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 0, ct.err_msg: "should create connect first."})
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_create_drop_index_repeatedly(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create / drop index repeatedly, use the same index params
|
|
|
|
method: create index, drop index, four times
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
for i in range(4):
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index_ip(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index_repeatedly_ip(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index repeatedly
|
|
|
|
method: create index, call drop index, and drop again
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2022-11-02 10:17:34 +08:00
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_drop_index_without_connect_ip(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index without connection
|
|
|
|
method: drop index, and check if drop successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_ip_index_params,
|
|
|
|
index_name=ct.default_index_name)
|
2022-05-13 17:33:57 +08:00
|
|
|
self.connection_wrap.remove_connection(ct.default_alias)
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name, check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 0, ct.err_msg: "should create connect first."})
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_create_drop_index_repeatedly_ip(self, get_simple_index):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create / drop index repeatedly, use the same index params
|
|
|
|
method: create index, drop index, four times
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
for i in range(4):
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, get_simple_index,
|
|
|
|
index_name=ct.default_index_name)
|
2022-05-13 17:33:57 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-05-13 17:33:57 +08:00
|
|
|
def test_create_PQ_without_nbits(self):
|
2021-09-17 14:05:54 +08:00
|
|
|
"""
|
|
|
|
target: test create PQ index
|
|
|
|
method: create PQ index without nbits
|
|
|
|
expected: create successfully
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
PQ_index = {"index_type": "IVF_PQ", "params": {"nlist": 128, "m": 16}, "metric_type": "L2"}
|
2022-05-13 17:33:57 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, PQ_index, index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 1
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-15 20:43:55 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_collection_not_create_ip(self):
|
|
|
|
"""
|
|
|
|
target: test drop index interface when index not created
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return code not equals to 0, drop index failed
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-02 10:17:34 +08:00
|
|
|
collection_w.drop_index(index_name=default_field_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-07-11 19:24:26 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_collection_with_after_load(self):
|
|
|
|
"""
|
|
|
|
target: Test that index files are not lost after loading
|
|
|
|
method: create collection and add entities in it, create index, flush and load
|
|
|
|
expected: load and search successfully
|
|
|
|
"""
|
|
|
|
collection_w = self.init_collection_wrap(cf.gen_unique_str(prefix))
|
|
|
|
nums = 20
|
2022-09-06 09:03:14 +08:00
|
|
|
tmp_nb = 5000
|
|
|
|
for i in range(nums):
|
2022-07-11 19:24:26 +08:00
|
|
|
df = cf.gen_default_dataframe_data(nb=tmp_nb, start=i * tmp_nb)
|
2022-09-06 09:03:14 +08:00
|
|
|
insert_res, _ = collection_w.insert(df)
|
|
|
|
assert collection_w.num_entities == (i + 1) * tmp_nb
|
2022-07-11 19:24:26 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
|
|
|
|
collection_w.load()
|
|
|
|
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
|
|
|
|
search_res, _ = collection_w.search(vectors, default_search_field, default_search_params, default_limit)
|
|
|
|
assert len(search_res[0]) == ct.default_limit
|
2022-09-06 09:03:14 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-05-15 20:43:55 +08:00
|
|
|
class TestNewIndexBinary(TestcaseBase):
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-15 20:43:55 +08:00
|
|
|
def get_simple_index(self, request):
|
|
|
|
log.info(request.param)
|
|
|
|
return copy.deepcopy(request.param)
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
collection_w.insert(data=df)
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=binary_field_name)
|
|
|
|
assert collection_w.has_index(index_name=binary_field_name)[0] == True
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index_partition(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
ins_res, _ = partition_w.insert(df)
|
|
|
|
assert len(ins_res.primary_keys) == len(df)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(default_binary_vec_field_name, default_binary_index_params,
|
|
|
|
index_name=binary_field_name)
|
2022-05-15 20:43:55 +08:00
|
|
|
assert collection_w.has_index(index_name=binary_field_name)[0] == True
|
|
|
|
assert len(collection_w.indexes) == 1
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index_search_with_query_vectors(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
collection_w.insert(data=df)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(default_binary_vec_field_name, default_binary_index_params,
|
|
|
|
index_name=binary_field_name)
|
2022-05-15 20:43:55 +08:00
|
|
|
collection_w.load()
|
|
|
|
_, vectors = cf.gen_binary_vectors(default_nq, default_dim)
|
|
|
|
collection_w.search(vectors[:default_nq], binary_field_name,
|
|
|
|
default_search_binary_params, default_limit,
|
|
|
|
default_search_exp)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index_invalid_metric_type_binary(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface with invalid metric type
|
2021-09-22 16:35:59 +08:00
|
|
|
method: add entities into binary collection, flush, create index with L2 metric type.
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return create_index failure
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
binary_index_params = {'index_type': 'BIN_IVF_FLAT', 'metric_type': 'L2', 'params': {'nlist': 64}}
|
|
|
|
collection_w.create_index(default_binary_vec_field_name, binary_index_params,
|
|
|
|
index_name=binary_field_name, check_task=CheckTasks.err_res,
|
2023-05-10 19:43:20 +08:00
|
|
|
check_items={ct.err_code: 1,
|
2022-06-01 18:56:03 +08:00
|
|
|
ct.err_msg: "Invalid metric_type: L2, which does not match the index type: BIN_IVF_FLAT"})
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2023-07-21 18:38:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
@pytest.mark.parametrize("metric_type", ["L2", "IP", "COSINE", "JACCARD", "HAMMING", "TANIMOTO"])
|
|
|
|
def test_create_binary_index_HNSW(self, metric_type):
|
|
|
|
"""
|
|
|
|
target: test create binary index hnsw
|
|
|
|
method: create binary index hnsw
|
|
|
|
expected: succeed
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
binary_index_params = {'index_type': 'HNSW', "M": '18', "efConstruction": '240', 'metric_type': metric_type}
|
|
|
|
if metric_type == "TANIMOTO":
|
|
|
|
collection_w.create_index(default_binary_vec_field_name, binary_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "metric type not found or not supported"})
|
|
|
|
else:
|
|
|
|
collection_w.create_index(default_binary_vec_field_name, binary_index_params)
|
|
|
|
assert collection_w.index()[0].params == binary_index_params
|
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `drop_index` function
|
|
|
|
******************************************************************
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_drop_index(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
collection_w.insert(data=df)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(default_binary_vec_field_name, default_binary_index_params,
|
|
|
|
index_name=binary_field_name)
|
2022-05-15 20:43:55 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=binary_field_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_drop_index_partition(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface
|
2021-10-29 21:46:51 +08:00
|
|
|
method: create collection, create partition and add entities in it,
|
|
|
|
create index on collection, call drop collection index
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
ins_res, _ = partition_w.insert(df)
|
|
|
|
assert len(ins_res.primary_keys) == len(df)
|
|
|
|
collection_w.create_index(default_binary_vec_field_name, default_binary_index_params,
|
|
|
|
index_name=binary_field_name)
|
|
|
|
assert collection_w.has_index(index_name=binary_field_name)[0] == True
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.drop_index(index_name=binary_field_name)
|
|
|
|
assert collection_w.has_index(index_name=binary_field_name)[0] == False
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2023-04-01 09:44:27 +08:00
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-10-21 17:05:37 +08:00
|
|
|
class TestIndexInvalid(TestcaseBase):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
Test create / describe / drop index interfaces with invalid collection names
|
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_invalid_strs()
|
|
|
|
)
|
|
|
|
def get_collection_name(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_with_invalid_collection_name(self, connect, get_collection_name):
|
2021-09-16 17:37:49 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface for invalid scenario
|
|
|
|
method: create index with invalid collection name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
collection_name = get_collection_name
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection_name, field_name, default_index)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_with_invalid_collection_name(self, connect, get_collection_name):
|
2021-09-16 18:55:49 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface for invalid scenario
|
|
|
|
method: drop index with invalid collection name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
collection_name = get_collection_name
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.drop_index(collection_name)
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_invalid_index()
|
|
|
|
)
|
|
|
|
def get_index(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_with_invalid_index_params(self, connect, collection, get_index):
|
2021-09-18 11:01:50 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface for invalid scenario
|
|
|
|
method: create index with invalid index params
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(get_index)
|
2021-08-31 18:49:59 +08:00
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection, field_name, get_index)
|
|
|
|
|
2022-10-21 17:05:37 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_drop_index_without_release(self):
|
|
|
|
"""
|
|
|
|
target: test drop index after load without release
|
|
|
|
method: 1. create a collection and build an index then load
|
|
|
|
2. drop the index
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2022-12-29 17:01:31 +08:00
|
|
|
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
2022-10-21 17:05:37 +08:00
|
|
|
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
|
|
|
|
collection_w.create_index("float_vector", default_index)
|
|
|
|
collection_w.load()
|
|
|
|
collection_w.drop_index(check_task=CheckTasks.err_res,
|
|
|
|
check_items={"err_code": 1,
|
|
|
|
"err_msg": "index cannot be dropped, collection is "
|
|
|
|
"loaded, please release it first"})
|
|
|
|
|
2022-12-14 19:27:35 +08:00
|
|
|
@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
|
|
|
|
"""
|
2022-12-29 17:01:31 +08:00
|
|
|
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
2022-12-14 19:27:35 +08:00
|
|
|
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"})
|
|
|
|
|
2023-06-08 09:12:35 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_json(self):
|
|
|
|
"""
|
|
|
|
target: test create index on json fields
|
|
|
|
method: 1.create collection, and create index
|
|
|
|
expected: create index raise an error
|
|
|
|
"""
|
|
|
|
collection_w, _, _, insert_ids = self.init_collection_general(prefix, True,
|
|
|
|
dim=ct.default_dim, is_index=False)[0:4]
|
|
|
|
collection_w.create_index(ct.default_json_field_name, index_params=ct.default_flat_index,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "create index on json field is not supported"})
|
|
|
|
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-05-15 20:43:55 +08:00
|
|
|
class TestNewIndexAsync(TestcaseBase):
|
|
|
|
@pytest.fixture(scope="function", params=[False, True])
|
|
|
|
def _async(self, request):
|
|
|
|
yield request.param
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2022-05-15 20:43:55 +08:00
|
|
|
def call_back(self):
|
|
|
|
assert True
|
2022-06-01 18:56:03 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index(self, _async):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
res, _ = collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
|
2022-06-01 18:56:03 +08:00
|
|
|
index_name=ct.default_index_name, _async=_async)
|
2022-05-15 20:43:55 +08:00
|
|
|
if _async:
|
|
|
|
res.done()
|
|
|
|
assert len(collection_w.indexes) == 1
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index_drop(self, _async):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
res, _ = collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
|
|
|
|
index_name=ct.default_index_name, _async=_async)
|
2022-09-06 09:03:14 +08:00
|
|
|
|
|
|
|
# load and search
|
2022-11-11 16:43:04 +08:00
|
|
|
if _async:
|
|
|
|
res.done()
|
|
|
|
assert len(collection_w.indexes) == 1
|
2022-09-06 09:03:14 +08:00
|
|
|
collection_w.load()
|
|
|
|
vectors_s = [[random.random() for _ in range(ct.default_dim)] for _ in range(ct.default_nq)]
|
|
|
|
search_res, _ = collection_w.search(vectors_s[:ct.default_nq], ct.default_float_vec_field_name,
|
|
|
|
ct.default_search_params, ct.default_limit)
|
|
|
|
assert len(search_res) == ct.default_nq
|
|
|
|
assert len(search_res[0]) == ct.default_limit
|
|
|
|
|
2022-10-19 23:17:44 +08:00
|
|
|
collection_w.release()
|
2022-05-15 20:43:55 +08:00
|
|
|
if _async:
|
|
|
|
res.done()
|
2022-09-06 09:03:14 +08:00
|
|
|
assert collection_w.indexes[0].params == default_index_params
|
2022-05-15 20:43:55 +08:00
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2022-05-15 20:43:55 +08:00
|
|
|
def test_create_index_callback(self):
|
2021-08-31 18:49:59 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-05-15 20:43:55 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
res, _ = collection_w.create_index(ct.default_float_vec_field_name, default_index_params,
|
|
|
|
index_name=ct.default_index_name, _async=True,
|
|
|
|
_callback=self.call_back())
|
2022-05-11 21:55:53 +08:00
|
|
|
|
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-06-01 18:56:03 +08:00
|
|
|
class TestIndexString(TestcaseBase):
|
2022-05-11 21:55:53 +08:00
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test create index about string
|
|
|
|
******************************************************************
|
2022-06-01 18:56:03 +08:00
|
|
|
"""
|
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_with_string_field(self):
|
|
|
|
"""
|
|
|
|
target: test create index with string field is not primary
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.only create an index with string field is not primary
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_string_field_name,
|
|
|
|
default_string_index_params)
|
2022-05-11 21:55:53 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_with_string_before_load(self):
|
|
|
|
"""
|
|
|
|
target: test create index with string field before load
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create an index with string field before load
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(ct.default_nb)
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_string_field_name,
|
|
|
|
default_string_index_params)
|
2022-05-12 16:15:54 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
2022-10-17 18:01:25 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, index_params=ct.default_flat_index, index_name="vector_flat")
|
2022-05-11 21:55:53 +08:00
|
|
|
collection_w.load()
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-05-11 21:55:53 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_load_after_create_index_with_string(self):
|
|
|
|
"""
|
|
|
|
target: test load after create index with string field
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.collection load after create index with string field
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(ct.default_nb)
|
|
|
|
collection_w.insert(data=data)
|
2022-10-17 18:01:25 +08:00
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, index_params=ct.default_flat_index, index_name="vector_flat")
|
2022-06-01 18:56:03 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_string_field_name,
|
|
|
|
default_string_index_params)
|
2022-10-27 13:05:31 +08:00
|
|
|
collection_w.load()
|
2022-05-12 16:15:54 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_with_string_field_is_primary(self):
|
|
|
|
"""
|
|
|
|
target: test create index with string field is primary
|
|
|
|
method: 1.create collection
|
|
|
|
2.insert data
|
|
|
|
3.only create an index with string field is primary
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
schema = cf.gen_string_pk_default_collection_schema()
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=schema)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_string_field_name,
|
|
|
|
default_string_index_params)
|
2022-05-12 16:15:54 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
2022-05-11 21:55:53 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_or_not_with_string_field(self):
|
|
|
|
"""
|
|
|
|
target: test create index, half of the string fields are indexed and half are not
|
|
|
|
method: 1.create collection
|
|
|
|
2.insert data
|
|
|
|
3.half of the indexes are created and half are not in the string fields
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
string_fields = [cf.gen_string_field(name="test_string")]
|
|
|
|
schema = cf.gen_schema_multi_string_fields(string_fields)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=schema)
|
|
|
|
df = cf.gen_dataframe_multi_string_fields(string_fields=string_fields)
|
|
|
|
collection_w.insert(df)
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_string_field_name, default_string_index_params)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_index_with_same_index_name(self):
|
|
|
|
"""
|
|
|
|
target: test create index with different fields use same index name
|
|
|
|
method: 1.create collection
|
|
|
|
2.insert data
|
|
|
|
3.only create index with different fields use same index name
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2)
|
2022-06-01 18:56:03 +08:00
|
|
|
collection_w.create_index(default_float_vec_field_name, default_index_params,
|
2022-05-11 21:55:53 +08:00
|
|
|
index_name=index_name2,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: "CreateIndex failed"})
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_different_index_fields(self):
|
|
|
|
"""
|
|
|
|
target: test create index with different fields
|
|
|
|
method: 1.create collection
|
|
|
|
2.insert data
|
|
|
|
3.create different indexes with string and float vector field
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(default_float_vec_field_name, default_index_params, index_name=index_name1)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.has_index(index_name=index_name1)[0] == True
|
2022-05-11 21:55:53 +08:00
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.has_index(index_name=index_name2)[0] == True
|
|
|
|
assert len(collection_w.indexes) == 2
|
|
|
|
|
2022-05-11 21:55:53 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_create_different_index_binary_fields(self):
|
|
|
|
"""
|
|
|
|
target: testing the creation of indexes with string and binary fields
|
|
|
|
method: 1.create collection
|
|
|
|
2.insert data
|
|
|
|
3.create different indexes with string and binary vector field
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
collection_w.insert(data=df)
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.has_index(index_name=index_name2)[0] == True
|
2022-05-11 21:55:53 +08:00
|
|
|
collection_w.create_index(default_binary_vec_field_name, default_binary_index_params, index_name=index_name3)
|
2022-06-01 18:56:03 +08:00
|
|
|
assert collection_w.has_index(index_name=index_name3)[0] == True
|
|
|
|
assert len(collection_w.indexes) == 2
|
2022-05-11 21:55:53 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_drop_index_with_string_field(self):
|
|
|
|
"""
|
|
|
|
target: test drop index with string field
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create index and use index.drop() drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-06-01 18:56:03 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_string_field_name,
|
|
|
|
default_string_index_params)
|
2022-05-12 16:15:54 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
2022-05-11 21:55:53 +08:00
|
|
|
self.index_wrap.drop()
|
2022-05-12 16:15:54 +08:00
|
|
|
assert len(collection_w.indexes) == 0
|
2022-05-11 21:55:53 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_collection_drop_index_with_string(self):
|
|
|
|
"""
|
|
|
|
target: test drop index with string field
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create index and uses collection.drop_index () drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2)
|
|
|
|
collection_w.drop_index(index_name=index_name2)
|
2022-05-12 16:15:54 +08:00
|
|
|
assert len(collection_w.indexes) == 0
|
2022-09-21 10:14:51 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_with_string_field_empty(self):
|
|
|
|
"""
|
|
|
|
target: test drop index with string field
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create index and uses collection.drop_index () drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
|
|
|
|
nb = 3000
|
|
|
|
data = cf.gen_default_list_data(nb)
|
|
|
|
data[2] = [""for _ in range(nb)]
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name=index_name2)
|
|
|
|
assert collection_w.has_index(index_name=index_name2)[0] == True
|
|
|
|
collection_w.drop_index(index_name=index_name2)
|
2022-10-31 17:27:35 +08:00
|
|
|
assert len(collection_w.indexes) == 0
|
2022-12-14 19:27:35 +08:00
|
|
|
|
|
|
|
|
2023-03-20 17:29:57 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
2022-10-31 17:27:35 +08:00
|
|
|
class TestIndexDiskann(TestcaseBase):
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test create index about diskann
|
|
|
|
******************************************************************
|
|
|
|
"""
|
|
|
|
@pytest.fixture(scope="function", params=[False, True])
|
|
|
|
def _async(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
|
|
|
def call_back(self):
|
|
|
|
assert True
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_index_with_diskann_normal(self):
|
|
|
|
"""
|
|
|
|
target: test create index with diskann
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create diskann index , then load data
|
|
|
|
3.search successfully
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_float_vec_field_name, ct.default_diskann_index)
|
|
|
|
log.info(self.index_wrap.params)
|
|
|
|
cf.assert_equal_index(index, collection_w.indexes[0])
|
|
|
|
collection_w.load()
|
|
|
|
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
|
|
|
|
search_res, _ = collection_w.search(vectors[:default_nq], default_search_field,
|
|
|
|
ct.default_diskann_search_params, default_limit,
|
|
|
|
default_search_exp,
|
|
|
|
check_task=CheckTasks.check_search_results,
|
|
|
|
check_items={"nq": default_nq,
|
|
|
|
"limit": default_limit})
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2023-04-01 09:44:27 +08:00
|
|
|
def test_create_index_with_max_dim(self):
|
2022-10-31 17:27:35 +08:00
|
|
|
"""
|
|
|
|
target: test create index with diskann
|
2023-04-01 09:44:27 +08:00
|
|
|
method: 1.create collection, when the max dim of the vector is 32768
|
2022-10-31 17:27:35 +08:00
|
|
|
2.create diskann index
|
|
|
|
expected: create index raise an error
|
|
|
|
"""
|
2023-04-01 09:44:27 +08:00
|
|
|
dim = 32768
|
2022-10-31 17:27:35 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
fields = [cf.gen_int64_field(is_primary=True), cf.gen_float_field(), cf.gen_string_field(),
|
|
|
|
cf.gen_float_vec_field(dim=dim)]
|
|
|
|
schema = cf.gen_collection_schema(fields=fields)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=schema)
|
2023-04-01 09:44:27 +08:00
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index)
|
|
|
|
assert len(collection_w.indexes) == 1
|
2022-10-31 17:27:35 +08:00
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2023-04-01 09:44:27 +08:00
|
|
|
def test_create_index_with_diskann_callback(self, _async):
|
2022-10-31 17:27:35 +08:00
|
|
|
"""
|
|
|
|
target: test create index with diskann
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create diskann index ,then load
|
|
|
|
3.search
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
res, _ = collection_w.create_index(ct.default_float_vec_field_name, ct.default_diskann_index,
|
|
|
|
index_name=ct.default_index_name, _async=_async,
|
|
|
|
_callback=self.call_back())
|
|
|
|
|
|
|
|
if _async:
|
|
|
|
res.done()
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.load()
|
|
|
|
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
|
|
|
|
search_res, _ = collection_w.search(vectors[:default_nq], default_search_field,
|
|
|
|
ct.default_diskann_search_params, default_limit,
|
|
|
|
default_search_exp,
|
|
|
|
check_task=CheckTasks.check_search_results,
|
|
|
|
check_items={"nq": default_nq,
|
|
|
|
"limit": default_limit})
|
2022-11-24 16:53:12 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_diskann_index_drop_with_async(self, _async):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create diskann index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
res, _ = collection_w.create_index(ct.default_float_vec_field_name, ct.default_diskann_index,
|
|
|
|
index_name=ct.default_index_name, _async=_async)
|
|
|
|
if _async:
|
|
|
|
res.done()
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.release()
|
|
|
|
collection_w.drop_index(index_name=ct.default_index_name)
|
|
|
|
assert len(collection_w.indexes) == 0
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_diskann_index_with_partition(self):
|
|
|
|
"""
|
|
|
|
target: test create index with diskann
|
|
|
|
method: 1.create collection , partition and insert data to partition
|
|
|
|
2.create diskann index ,then load
|
|
|
|
expected: create index successfully
|
|
|
|
"""
|
|
|
|
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_schema)
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
df = cf.gen_default_list_data(ct.default_nb)
|
|
|
|
ins_res, _ = partition_w.insert(df)
|
|
|
|
assert len(ins_res.primary_keys) == ct.default_nb
|
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index,
|
|
|
|
index_name=field_name)
|
|
|
|
collection_w.load()
|
2023-04-01 09:44:27 +08:00
|
|
|
assert collection_w.has_index(index_name=field_name)[0] is True
|
2022-10-31 17:27:35 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.release()
|
|
|
|
collection_w.drop_index(index_name=field_name)
|
2023-04-01 09:44:27 +08:00
|
|
|
assert collection_w.has_index(index_name=field_name)[0] is False
|
2022-10-31 17:27:35 +08:00
|
|
|
assert len(collection_w.indexes) == 0
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2023-04-01 09:44:27 +08:00
|
|
|
def test_drop_diskann_index_with_normal(self):
|
2022-10-31 17:27:35 +08:00
|
|
|
"""
|
|
|
|
target: test drop diskann index normal
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create index and uses collection.drop_index () drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index, index_name=index_name1)
|
|
|
|
collection_w.load()
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.release()
|
|
|
|
collection_w.drop_index(index_name=index_name1)
|
|
|
|
assert collection_w.has_index(index_name=index_name1)[0] == False
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_drop_diskann_index_and_create_again(self):
|
|
|
|
"""
|
|
|
|
target: test drop diskann index normal
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create index and uses collection.drop_index () drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
|
|
|
collection_w.create_index(default_field_name, ct.default_diskann_index)
|
|
|
|
collection_w.load()
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.release()
|
|
|
|
collection_w.drop_index()
|
|
|
|
assert len(collection_w.indexes) == 0
|
|
|
|
collection_w.create_index(default_field_name, ct.default_diskann_index)
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_more_than_three_index(self):
|
|
|
|
"""
|
|
|
|
target: test create diskann index
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create different index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data()
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index, index_name="a")
|
|
|
|
assert collection_w.has_index(index_name="a")[0] == True
|
|
|
|
collection_w.create_index(default_string_field_name, default_string_index_params, index_name="b")
|
|
|
|
assert collection_w.has_index(index_name="b")[0] == True
|
|
|
|
default_params = {}
|
|
|
|
collection_w.create_index("float", default_params, index_name="c")
|
|
|
|
assert collection_w.has_index(index_name="c")[0] == True
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_drop_diskann_index_with_partition(self):
|
|
|
|
"""
|
|
|
|
target: test drop diskann index normal
|
|
|
|
method: 1.create collection and insert data
|
|
|
|
2.create diskann index and uses collection.drop_index () drop index
|
|
|
|
expected: drop index successfully
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_schema)
|
|
|
|
partition_name = cf.gen_unique_str(prefix)
|
|
|
|
partition_w = self.init_partition_wrap(collection_w, partition_name)
|
|
|
|
assert collection_w.has_partition(partition_name)[0]
|
|
|
|
df = cf.gen_default_list_data()
|
|
|
|
ins_res, _ = partition_w.insert(df)
|
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index)
|
|
|
|
collection_w.load()
|
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
collection_w.release()
|
|
|
|
collection_w.drop_index()
|
|
|
|
assert len(collection_w.indexes) == 0
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_diskann_index_with_binary(self):
|
|
|
|
"""
|
|
|
|
target: test create diskann index with binary
|
|
|
|
method: 1.create collection and insert binary data
|
|
|
|
2.create diskann index
|
|
|
|
expected: report an error
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=default_binary_schema)
|
|
|
|
df, _ = cf.gen_default_binary_dataframe_data()
|
|
|
|
collection_w.insert(data=df)
|
|
|
|
collection_w.create_index(default_binary_vec_field_name, ct.default_diskann_index, index_name=binary_field_name,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: "field data type BinaryVector don't support the index build type DISKANN"})
|
|
|
|
|
2022-11-24 16:53:12 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-10-31 17:27:35 +08:00
|
|
|
def test_create_diskann_index_multithread(self):
|
|
|
|
"""
|
|
|
|
target: test create index interface with multiprocess
|
|
|
|
method: create collection and add entities in it, create diskann index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
data = cf.gen_default_list_data(default_nb)
|
|
|
|
collection_w.insert(data=data)
|
2022-11-23 09:55:12 +08:00
|
|
|
assert collection_w.num_entities == default_nb
|
2022-10-31 17:27:35 +08:00
|
|
|
|
|
|
|
def build(collection_w):
|
|
|
|
|
|
|
|
collection_w.create_index(ct.default_float_vec_field_name, ct.default_diskann_index)
|
|
|
|
|
|
|
|
threads_num = 10
|
|
|
|
threads = []
|
|
|
|
for i in range(threads_num):
|
|
|
|
t = MyThread(target=build, args=(collection_w,))
|
|
|
|
threads.append(t)
|
|
|
|
t.start()
|
|
|
|
time.sleep(0.2)
|
|
|
|
for t in threads:
|
2022-12-01 20:13:19 +08:00
|
|
|
t.join()
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2023-04-01 09:44:27 +08:00
|
|
|
@pytest.mark.parametrize("dim", [1, 2, 8, 16, 24, 31])
|
2022-12-01 20:13:19 +08:00
|
|
|
def test_create_index_with_small_dim(self, dim):
|
|
|
|
"""
|
|
|
|
target: test create index with diskann
|
|
|
|
method: 1.create collection, when the dim of the vector Less than 32
|
|
|
|
2.create diskann index
|
|
|
|
expected: create index raise an error
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
fields = [cf.gen_int64_field(is_primary=True), cf.gen_float_field(), cf.gen_string_field(),
|
|
|
|
cf.gen_float_vec_field(dim=dim)]
|
|
|
|
schema = cf.gen_collection_schema(fields=fields)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name, schema=schema)
|
|
|
|
collection_w.create_index(default_float_vec_field_name, ct.default_diskann_index,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
2022-12-14 19:27:35 +08:00
|
|
|
ct.err_msg: "invalid index params"})
|
2023-06-06 12:02:34 +08:00
|
|
|
|
2023-06-08 09:12:35 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.GPU)
|
|
|
|
class TestAutoIndex(TestcaseBase):
|
|
|
|
""" Test case of Auto index """
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
|
|
|
def test_create_autoindex_with_no_params(self):
|
|
|
|
"""
|
|
|
|
target: test create auto index with no params
|
|
|
|
method: create index with only one field name
|
|
|
|
expected: create successfully
|
|
|
|
"""
|
|
|
|
collection_w = self.init_collection_general(prefix, is_index=False)[0]
|
|
|
|
collection_w.create_index(field_name)
|
|
|
|
actual_index_params = collection_w.index()[0].params
|
|
|
|
assert default_autoindex_params == actual_index_params
|
|
|
|
|
2023-06-06 12:02:34 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2023-06-08 09:12:35 +08:00
|
|
|
@pytest.mark.parametrize("index_params", cf.gen_autoindex_params())
|
|
|
|
def test_create_autoindex_with_params(self, index_params):
|
2023-06-06 12:02:34 +08:00
|
|
|
"""
|
2023-06-08 09:12:35 +08:00
|
|
|
target: test create auto index with params
|
|
|
|
method: create index with different params
|
|
|
|
expected: create successfully
|
2023-06-06 12:02:34 +08:00
|
|
|
"""
|
2023-06-08 09:12:35 +08:00
|
|
|
collection_w = self.init_collection_general(prefix, is_index=False)[0]
|
|
|
|
collection_w.create_index(field_name, index_params)
|
|
|
|
actual_index_params = collection_w.index()[0].params
|
|
|
|
log.info(collection_w.index()[0].params)
|
|
|
|
expect_autoindex_params = copy.copy(default_autoindex_params)
|
|
|
|
if index_params.get("index_type"):
|
|
|
|
if index_params["index_type"] != 'AUTOINDEX':
|
|
|
|
expect_autoindex_params = index_params
|
|
|
|
if index_params.get("metric_type"):
|
|
|
|
expect_autoindex_params["metric_type"] = index_params["metric_type"]
|
|
|
|
assert actual_index_params == expect_autoindex_params
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_autoindex_with_invalid_params(self):
|
|
|
|
"""
|
|
|
|
target: test create auto index with invalid params
|
|
|
|
method: create index with invalid params
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
collection_w = self.init_collection_general(prefix, is_index=False)[0]
|
|
|
|
index_params = {"metric_type": "L2", "nlist": "1024", "M": "100"}
|
|
|
|
collection_w.create_index(field_name, index_params,
|
2023-06-06 12:02:34 +08:00
|
|
|
check_task=CheckTasks.err_res,
|
2023-06-08 09:12:35 +08:00
|
|
|
check_items={"err_code": 1,
|
|
|
|
"err_msg": "only metric type can be "
|
|
|
|
"passed when use AutoIndex"})
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_autoindex_on_binary_vectors(self):
|
|
|
|
"""
|
|
|
|
target: test create auto index on binary vectors
|
|
|
|
method: create index on binary vectors
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
collection_w = self.init_collection_general(prefix, is_binary=True, is_index=False)[0]
|
2023-07-17 21:49:19 +08:00
|
|
|
collection_w.create_index(binary_field_name, {})
|
|
|
|
actual_index_params = collection_w.index()[0].params
|
|
|
|
assert default_autoindex_params == actual_index_params
|