add the testcase (#20891)

Signed-off-by: jingkl <jingjing.jia@zilliz.com>

Signed-off-by: jingkl <jingjing.jia@zilliz.com>
pull/20914/head
jingkl 2022-12-01 20:13:19 +08:00 committed by GitHub
parent 9724ae5e27
commit e5c9da7152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 2 deletions

View File

@ -1816,4 +1816,23 @@ class TestIndexDiskann(TestcaseBase):
t.start()
time.sleep(0.2)
for t in threads:
t.join()
t.join()
@pytest.mark.tags(CaseLabel.L1)
@pytest.mark.parametrize("dim", [1,2, 8, 16, 24])
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,
ct.err_msg: "invalid index params"})

View File

@ -1671,7 +1671,7 @@ class TestqueryString(TestcaseBase):
res, _ = collection_w.query(expr, output_fields=output_fields)
assert len(res) == nb
@pytest.mark.tags(CaseLabel.L2)
def test_query_with_create_diskann_index(self):
"""
@ -1706,4 +1706,37 @@ class TestqueryString(TestcaseBase):
output_fields = [default_float_field_name, default_string_field_name]
collection_w.query(default_mix_expr, output_fields=output_fields,
check_task=CheckTasks.check_query_results, check_items={exp_res: res})
@pytest.mark.tags(CaseLabel.L1)
def test_query_with_scalar_field(self):
"""
target: test query with Scalar field
method: create collection , string field is primary
collection load and insert empty data with string field
collection query uses string expr in string field
expected: query successfully
"""
# 1. create a collection
collection_w, vectors = self.init_collection_general(prefix, insert_data=False, is_index=True)[0:2]
nb = 3000
df = cf.gen_default_list_data(nb)
df[2] = [""for _ in range(nb)]
collection_w.insert(df)
assert collection_w.num_entities == nb
collection_w.create_index(ct.default_float_vec_field_name, default_index_params)
assert collection_w.has_index()[0]
index_params = {}
collection_w.create_index(ct.default_int64_field_name, index_params=index_params)
collection_w.load()
output_fields = [default_int_field_name, default_float_field_name]
expr = "int64 in [2,4,6,8]"
res, _ = collection_w.query(expr, output_fields=output_fields)
assert len(res) == 4

View File

@ -4476,3 +4476,45 @@ class TestsearchDiskann(TestcaseBase):
"limit": default_limit,
"_async": _async}
)
@pytest.mark.tags(CaseLabel.L1)
def test_search_with_scalar_field(self, dim, _async):
"""
target: test search with scalar field
method: 1.create collection , insert data
2.create more index ,then load
3.search with expr
expected: assert index and search successfully
"""
# 1. initialize with data
collection_w, _, _, ids = \
self.init_collection_general(prefix, True, dim=dim, primary_field=ct.default_string_field_name, is_index=True)[0:4]
# 2. create index
default_index = {"index_type": "IVF_SQ8", "metric_type": "L2", "params": {"nlist": 64}}
collection_w.create_index(ct.default_float_vec_field_name, default_index)
index_params = {}
collection_w.create_index(ct.default_float_field_name, index_params=index_params)
collection_w.create_index(ct.default_int64_field_name, index_params=index_params)
collection_w.load()
default_expr = "int64 in [1, 2, 3, 4]"
limit = 4
default_search_params ={"metric_type": "L2", "params": {"nprobe": 64}}
vectors = [[random.random() for _ in range(dim)] for _ in range(default_nq)]
output_fields = [default_int64_field_name, default_float_field_name, default_string_field_name]
search_res = collection_w.search(vectors[:default_nq], default_search_field,
default_search_params, limit,
default_expr,
output_fields=output_fields,
_async=_async,
travel_timestamp=0,
check_task=CheckTasks.check_search_results,
check_items={"nq": default_nq,
"ids": ids,
"limit": limit,
"_async": _async}
)