mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-02-04 11:18:44 +08:00
Signed-off-by: MrPresent-Han <chun.han@zilliz.com>
This commit is contained in:
parent
cc584551fb
commit
f31c6786ab
@ -177,13 +177,13 @@ class ApiCollectionWrapper:
|
||||
return res, check_result
|
||||
|
||||
@trace()
|
||||
def search_iterator(self, data, anns_field, param, limit, expr=None,
|
||||
def search_iterator(self, data, anns_field, param, batch_size, limit=-1, expr=None,
|
||||
partition_names=None, output_fields=None, timeout=None, round_decimal=-1,
|
||||
check_task=None, check_items=None, **kwargs):
|
||||
timeout = TIMEOUT if timeout is None else timeout
|
||||
|
||||
func_name = sys._getframe().f_code.co_name
|
||||
res, check = api_request([self.collection.search_iterator, data, anns_field, param, limit,
|
||||
res, check = api_request([self.collection.search_iterator, data, anns_field, param, batch_size, limit,
|
||||
expr, partition_names, output_fields, timeout, round_decimal], **kwargs)
|
||||
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
||||
data=data, anns_field=anns_field, param=param, limit=limit,
|
||||
@ -207,13 +207,13 @@ class ApiCollectionWrapper:
|
||||
return res, check_result
|
||||
|
||||
@trace()
|
||||
def query_iterator(self, expr, output_fields=None, partition_names=None, timeout=None, check_task=None,
|
||||
def query_iterator(self, batch_size, limit=-1, expr=None, output_fields=None, partition_names=None, timeout=None, check_task=None,
|
||||
check_items=None, **kwargs):
|
||||
# time.sleep(5)
|
||||
timeout = TIMEOUT if timeout is None else timeout
|
||||
|
||||
func_name = sys._getframe().f_code.co_name
|
||||
res, check = api_request([self.collection.query_iterator, expr, output_fields, partition_names, timeout], **kwargs)
|
||||
res, check = api_request([self.collection.query_iterator, batch_size, limit, expr, output_fields, partition_names, timeout], **kwargs)
|
||||
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
||||
expression=expr, partition_names=partition_names,
|
||||
output_fields=output_fields,
|
||||
|
||||
@ -364,25 +364,25 @@ class ResponseChecker:
|
||||
pk_list = []
|
||||
while True:
|
||||
res = search_iterator.next()
|
||||
if len(res[0]) == 0:
|
||||
if len(res) == 0:
|
||||
log.info("search iteration finished, close")
|
||||
search_iterator.close()
|
||||
break
|
||||
if check_items.get("limit", None):
|
||||
assert len(res[0].ids) <= check_items["limit"]
|
||||
if check_items.get("batch_size", None):
|
||||
assert len(res) <= check_items["batch_size"]
|
||||
if check_items.get("radius", None):
|
||||
for distance in res[0].distances:
|
||||
for distance in res.distances():
|
||||
if check_items["metric_type"] == "L2":
|
||||
assert distance < check_items["radius"]
|
||||
else:
|
||||
assert distance > check_items["radius"]
|
||||
if check_items.get("range_filter", None):
|
||||
for distance in res[0].distances:
|
||||
for distance in res.distances():
|
||||
if check_items["metric_type"] == "L2":
|
||||
assert distance >= check_items["range_filter"]
|
||||
else:
|
||||
assert distance <= check_items["range_filter"]
|
||||
pk_list.extend(res[0].ids)
|
||||
pk_list.extend(res.ids())
|
||||
assert len(pk_list) == len(set(pk_list))
|
||||
log.info("check: total %d results" % len(pk_list))
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ allure-pytest==2.7.0
|
||||
pytest-print==0.2.1
|
||||
pytest-level==0.1.1
|
||||
pytest-xdist==2.5.0
|
||||
pymilvus==2.4.0.dev115
|
||||
pymilvus==2.3.0b0.post1.dev126
|
||||
pytest-rerunfailures==9.1.1
|
||||
git+https://github.com/Projectplace/pytest-tags
|
||||
ndg-httpsclient
|
||||
|
||||
@ -3267,16 +3267,16 @@ class TestQueryIterator(TestcaseBase):
|
||||
expected: query successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
collection_w.create_index(ct.default_float_vec_field_name, {"metric_type": "L2"})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
expr = "int64 >= 0"
|
||||
collection_w.query_iterator(expr, limit=limit,
|
||||
collection_w.query_iterator(batch_size, expr=expr,
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"count": ct.default_nb,
|
||||
"limit": limit})
|
||||
"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("offset", [500, 1000, 1777])
|
||||
@ -3288,20 +3288,20 @@ class TestQueryIterator(TestcaseBase):
|
||||
expected: query successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
collection_w.create_index(ct.default_float_vec_field_name, {"metric_type": "L2"})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
expr = "int64 >= 0"
|
||||
collection_w.query_iterator(expr, limit=limit, offset=offset,
|
||||
collection_w.query_iterator(batch_size, expr=expr, offset=offset,
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"count": ct.default_nb - offset,
|
||||
"limit": limit})
|
||||
"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
@pytest.mark.parametrize("limit", [10, 100, 777, 2000])
|
||||
def test_query_iterator_with_different_limit(self, limit):
|
||||
@pytest.mark.parametrize("batch_size", [10, 100, 777, 2000])
|
||||
def test_query_iterator_with_different_limit(self, batch_size):
|
||||
"""
|
||||
target: test query iterator normal
|
||||
method: 1. query iterator
|
||||
@ -3315,10 +3315,10 @@ class TestQueryIterator(TestcaseBase):
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
expr = "int64 >= 0"
|
||||
collection_w.query_iterator(expr, limit=limit, offset=offset,
|
||||
collection_w.query_iterator(batch_size, expr=expr, offset=offset,
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"count": ct.default_nb - offset,
|
||||
"limit": limit})
|
||||
"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.skip("issue #26397")
|
||||
@ -3334,12 +3334,12 @@ class TestQueryIterator(TestcaseBase):
|
||||
# 2. search iterator
|
||||
expr = "int64 >= 0"
|
||||
error = {"err_code": 1, "err_msg": "invalid max query result window, limit [-1] is invalid, should be greater than 0"}
|
||||
collection_w.query_iterator(expr, limit=-1, check_task=CheckTasks.err_res, check_items=error)
|
||||
collection_w.query_iterator(-1, expr=expr, check_task=CheckTasks.err_res, check_items=error)
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L0)
|
||||
@pytest.mark.parametrize("limit", [100, 500])
|
||||
@pytest.mark.parametrize("batch_size", [100, 500])
|
||||
@pytest.mark.parametrize("auto_id", [True, False])
|
||||
def test_query_iterator_empty_expr(self, auto_id, limit):
|
||||
def test_query_iterator_empty_expr(self, auto_id, batch_size):
|
||||
"""
|
||||
target: test query iterator with empty expression
|
||||
method: query iterator empty expression with a limit
|
||||
@ -3349,16 +3349,16 @@ class TestQueryIterator(TestcaseBase):
|
||||
collection_w, _, _, insert_ids = self.init_collection_general(prefix, True, auto_id=auto_id)[0:4]
|
||||
|
||||
# 2. query with limit
|
||||
collection_w.query_iterator("", limit=limit,
|
||||
collection_w.query_iterator(batch_size,
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"limit": limit,
|
||||
check_items={"batch_size": batch_size,
|
||||
"count": ct.default_nb,
|
||||
"exp_ids": insert_ids})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("offset", [100, 1000])
|
||||
@pytest.mark.parametrize("limit", [500, 1000])
|
||||
def test_query_iterator_expr_empty_with_random_pk_pagination(self, limit, offset):
|
||||
@pytest.mark.parametrize("batch_size", [500, 1000])
|
||||
def test_query_iterator_expr_empty_with_random_pk_pagination(self, batch_size, offset):
|
||||
"""
|
||||
target: test query iterator with empty expression
|
||||
method: create a collection using random pk, query empty expression with a limit
|
||||
@ -3369,12 +3369,12 @@ class TestQueryIterator(TestcaseBase):
|
||||
|
||||
# 3. query with empty expr and check the result
|
||||
exp_ids = sorted(insert_ids)
|
||||
collection_w.query_iterator("", limit=limit, output_fields=[ct.default_string_field_name],
|
||||
collection_w.query_iterator(batch_size, output_fields=[ct.default_string_field_name],
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"limit": limit, "count": ct.default_nb, "exp_ids": exp_ids})
|
||||
check_items={"batch_size": batch_size, "count": ct.default_nb, "exp_ids": exp_ids})
|
||||
|
||||
# 4. query with pagination
|
||||
exp_ids = sorted(insert_ids)[offset:]
|
||||
collection_w.query_iterator("", limit=limit, offset=offset, output_fields=[ct.default_string_field_name],
|
||||
collection_w.query_iterator(batch_size, offset=offset, output_fields=[ct.default_string_field_name],
|
||||
check_task=CheckTasks.check_query_iterator,
|
||||
check_items={"limit": limit, "count": ct.default_nb - offset, "exp_ids": exp_ids})
|
||||
check_items={"batch_size": batch_size, "count": ct.default_nb - offset, "exp_ids": exp_ids})
|
||||
|
||||
@ -8450,14 +8450,14 @@ class TestSearchIterator(TestcaseBase):
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": "L2"}
|
||||
limit = 200
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
batch_size = 200
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"limit": limit})
|
||||
limit = 600
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
check_items={"batch_size": batch_size})
|
||||
batch_size = 600
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"limit": limit})
|
||||
check_items={"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L1)
|
||||
def test_search_iterator_binary(self):
|
||||
@ -8468,14 +8468,14 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 200
|
||||
batch_size = 200
|
||||
collection_w = self.init_collection_general(prefix, True, is_binary=True)[0]
|
||||
# 2. search iterator
|
||||
_, binary_vectors = cf.gen_binary_vectors(2, ct.default_dim)
|
||||
collection_w.search_iterator(binary_vectors[:1], binary_field_name,
|
||||
ct.default_search_binary_params, limit,
|
||||
ct.default_search_binary_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"limit": limit})
|
||||
check_items={"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metrics", ct.float_metrics)
|
||||
@ -8487,7 +8487,7 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
dim = 128
|
||||
collection_w = self.init_collection_general(prefix, True, dim=dim, is_index=False)[0]
|
||||
collection_w.create_index(field_name, {"metric_type": metrics})
|
||||
@ -8495,7 +8495,7 @@ class TestSearchIterator(TestcaseBase):
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": metrics}
|
||||
expression = "1000.0 <= float < 2000.0"
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
expr=expression, check_task=CheckTasks.check_search_iterator,
|
||||
check_items={})
|
||||
|
||||
@ -8508,17 +8508,15 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
collection_w.create_index(field_name, {"metric_type": "L2"})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": "L2", "params": {"radius": 35.0, "range_filter": 34.0}}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
search_params = {"metric_type": "L2"}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"metric_type": "L2",
|
||||
"radius": 35.0,
|
||||
"range_filter": 34.0})
|
||||
check_items={"metric_type": "L2"})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("metrics", ct.float_metrics[1:])
|
||||
@ -8530,17 +8528,15 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
collection_w.create_index(field_name, {"metric_type": metrics})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": metrics, "params": {"radius": 0, "range_filter": 45}}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
search_params = {"metric_type": metrics, "params": {}}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"metric_type": metrics,
|
||||
"radius": 0,
|
||||
"range_filter": 45})
|
||||
check_items={"metric_type": metrics})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_range_search_iterator_only_radius(self):
|
||||
@ -8551,16 +8547,15 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
collection_w.create_index(field_name, {"metric_type": "L2"})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": "L2", "params": {"radius": 35.0}}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
search_params = {"metric_type": "L2", "params": {}}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"metric_type": "L2",
|
||||
"radius": 35.0})
|
||||
check_items={"metric_type": "L2"})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.skip("issue #25145")
|
||||
@ -8576,20 +8571,20 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
collection_w = self.init_collection_general(prefix, True, is_index=False)[0]
|
||||
default_index = {"index_type": index, "params": params, "metric_type": metrics}
|
||||
collection_w.create_index(field_name, default_index)
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": metrics}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
@pytest.mark.parametrize("limit", [10, 100, 777, 1000])
|
||||
def test_search_iterator_with_different_limit(self, limit):
|
||||
@pytest.mark.parametrize("batch_size", [10, 100, 777, 1000])
|
||||
def test_search_iterator_with_different_limit(self, batch_size):
|
||||
"""
|
||||
target: test search iterator normal
|
||||
method: 1. search iterator
|
||||
@ -8600,9 +8595,9 @@ class TestSearchIterator(TestcaseBase):
|
||||
collection_w = self.init_collection_general(prefix, True)[0]
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": "COSINE"}
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, limit,
|
||||
collection_w.search_iterator(vectors[:1], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.check_search_iterator,
|
||||
check_items={"limit": limit})
|
||||
check_items={"batch_size": batch_size})
|
||||
|
||||
@pytest.mark.tags(CaseLabel.L2)
|
||||
def test_search_iterator_invalid_nq(self):
|
||||
@ -8613,14 +8608,14 @@ class TestSearchIterator(TestcaseBase):
|
||||
expected: search successfully
|
||||
"""
|
||||
# 1. initialize with data
|
||||
limit = 100
|
||||
batch_size = 100
|
||||
dim = 128
|
||||
collection_w = self.init_collection_general(prefix, True, dim=dim, is_index=False)[0]
|
||||
collection_w.create_index(field_name, {"metric_type": "L2"})
|
||||
collection_w.load()
|
||||
# 2. search iterator
|
||||
search_params = {"metric_type": "L2"}
|
||||
collection_w.search_iterator(vectors[:2], field_name, search_params, limit,
|
||||
collection_w.search_iterator(vectors[:2], field_name, search_params, batch_size,
|
||||
check_task=CheckTasks.err_res,
|
||||
check_items={"err_code": 1,
|
||||
"err_msg": "Not support multiple vector iterator at present"})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user