Add test case for search with expressions. (#5768)

Signed-off-by: Binbin Lv <binbin.lv@zilliz.com>
pull/5794/head
binbin 2021-06-15 15:11:57 +08:00 committed by GitHub
parent bec9f2c182
commit a2787cad9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View File

@ -119,6 +119,7 @@ class TestcaseBase(Base):
res, is_succ = self.connection_wrap.connect(alias='default')
if not is_succ:
raise res
log.info("_connect: Connected")
return res
def init_collection_wrap(self, name=None, data=None, schema=None, check_task=None, **kwargs):
@ -161,7 +162,7 @@ class TestcaseBase(Base):
default_schema = cf.gen_default_binary_collection_schema()
else:
default_schema = cf.gen_default_collection_schema()
log.info("init_data: collection creation")
log.info("init_collection_general: collection creation")
collection_w = self.init_collection_wrap(name=collection_name,
schema=default_schema)
# 2 add extra partitions if specified (default is 1 partition named "_default")

View File

@ -177,6 +177,15 @@ def gen_all_type_fields():
fields.append(field)
return fields
def gen_normal_expressions():
expressions = [
"int64 > 0",
"(int64 > 0 && int64 < 400) or (int64 > 500 && int64 < 1000)",
"int64 not in [1, 2, 3]",
"int64 in [1, 2, 3] and float != 2",
"int64 == 0 || int64 == 1 || int64 == 2",
]
return expressions
def jaccard(x, y):
x = np.asarray(x, np.bool)

View File

@ -653,3 +653,28 @@ class TestCollectionSearch(TestcaseBase):
for t in threads:
t.join()
log.info("test_search_concurrent_multi_threads: searched with %s processes" % threads_num)
@pytest.mark.tags(CaseLabel.L3)
@pytest.mark.parametrize("expression, limit",
zip(cf.gen_normal_expressions(),
[999, 898, 997, 2, 3]))
def test_search_with_expression(self, expression, limit):
"""
target: test search with different expressions
method: test search with different expressions
expected: searched successfully with correct limit(topK)
"""
log.info("Test case of search interface: test_search_with_expression")
# 1. initialize with data
collection_w = self.init_collection_general(prefix, True, 1000)[0]
# 2. create index
index_param = {"index_type": "IVF_FLAT", "metric_type": "L2", "params": {"nlist": 100}}
collection_w.create_index("float_vector", index_param)
# 3. search with different expressions
log.info("test_search_with_expression: searching with expression: %s" % expression)
vectors = [[random.random() for _ in range(default_dim)] for _ in range(default_nq)]
res, _ = collection_w.search(vectors[:default_nq], default_search_field,
default_search_params, 1000, expression,
check_task=CheckTasks.check_search_results,
check_items={"nq": default_nq,
"limit": limit})