Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [2.4] move page_retain_order to the same level as radius #2250

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,20 @@ def search_requests_with_expr(
if not isinstance(params, dict):
raise ParamError(message=f"Search params must be a dict, got {type(params)}")

if PAGE_RETAIN_ORDER_FIELD in kwargs and PAGE_RETAIN_ORDER_FIELD in param:
raise ParamError(
message="Provide page_retain_order both in kwargs and param, expect just one"
)
page_retain_order = kwargs.get(PAGE_RETAIN_ORDER_FIELD) or param.get(
PAGE_RETAIN_ORDER_FIELD
)
if page_retain_order is not None:
if not isinstance(page_retain_order, bool):
raise ParamError(
message=f"wrong type for page_retain_order, expect bool, got {type(page_retain_order)}"
)
params[PAGE_RETAIN_ORDER_FIELD] = page_retain_order

search_params = {
"topk": limit,
"params": params,
Expand All @@ -697,20 +711,6 @@ def search_requests_with_expr(
raise ParamError(message=f"wrong type for offset, expect int, got {type(offset)}")
search_params["offset"] = offset

if PAGE_RETAIN_ORDER_FIELD in kwargs and PAGE_RETAIN_ORDER_FIELD in param:
raise ParamError(
message="Provide page_retain_order both in kwargs and param, expect just one"
)
page_retain_order = kwargs.get(PAGE_RETAIN_ORDER_FIELD) or param.get(
PAGE_RETAIN_ORDER_FIELD
)
if page_retain_order is not None:
if not isinstance(page_retain_order, bool):
raise ParamError(
message=f"wrong type for page_retain_order, expect bool, got {type(page_retain_order)}"
)
search_params[PAGE_RETAIN_ORDER_FIELD] = page_retain_order

is_iterator = kwargs.get(ITERATOR_FIELD)
if is_iterator is not None:
search_params[ITERATOR_FIELD] = is_iterator
Expand Down
6 changes: 0 additions & 6 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,13 @@ def search(
similar metricy types, the value must be of type str.
* *offset* (``int``, optional)
offset for pagination.
* *page_retain_order* (``bool``, optional)
Whether to retain the order of the search result when offset is provided.
* *params of index: *nprobe*, *ef*, *search_k*, etc
Corresponding search params for a certain index.
example for param::

{
"metric_type": "L2",
"offset": 10,
"page_retain_order": True,
"params": {"nprobe": 12},
}

Expand Down Expand Up @@ -723,9 +720,6 @@ def search(
* *offset* (``int``, optinal)
offset for pagination.

* *page_retain_order* (``bool``, optional)
Whether to retain the order of the search result when offset is provided.

* *consistency_level* (``str/int``, optional)
Which consistency level to use when searching in the collection.

Expand Down
4 changes: 0 additions & 4 deletions pymilvus/orm/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ def search(
* *offset* (``int``, optional)
offset for pagination.

* *page_retain_order* (``bool``, optional)
Whether to retain the order of the search result when offset is provided.

* *limit* (``int``, optional)
limit for the search results and pagination.

Expand All @@ -399,7 +396,6 @@ def search(
"nprobe": 128,
"metric_type": "L2",
"offset": 10,
"page_retain_order": True,
"limit": 10,
}

Expand Down
13 changes: 9 additions & 4 deletions tests/test_prepare.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import json

from pymilvus.client.constants import PAGE_RETAIN_ORDER_FIELD
from pymilvus.client.prepare import Prepare
from pymilvus import DataType, MilvusException, CollectionSchema, FieldSchema
from pymilvus import DefaultConfig
Expand All @@ -24,20 +26,23 @@ def test_search_requests_with_expr_offset(self):
search_params = {
"metric_type": "L2",
"offset": 10,
"page_retain_order": True,
"params": {"page_retain_order": True}
}

ret = Prepare.search_requests_with_expr("name", data, "v", search_params, 100)

offset_exists = False
page_retain_order_exists = False
print(ret.search_params)
for p in ret.search_params:
if p.key == "offset":
offset_exists = True
assert p.value == "10"
elif p.key == "page_retain_order":
page_retain_order_exists = True
assert p.value == "True" # it was dumped as string
elif p.key == "params":
params = json.loads(p.value)
if PAGE_RETAIN_ORDER_FIELD in params:
page_retain_order_exists = True
assert params[PAGE_RETAIN_ORDER_FIELD] == True

assert offset_exists is True
assert page_retain_order_exists is True
Expand Down