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

enhance: simplify the structure of search_params(#2507)(#2537)(#2540) #2550

Merged
merged 3 commits into from
Jan 8, 2025
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
5 changes: 3 additions & 2 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ResourceGroupConfig,
get_consistency_level,
)
from .utils import traverse_info, traverse_upsert_info
from .utils import get_params, traverse_info, traverse_upsert_info


class Prepare:
Expand Down Expand Up @@ -943,7 +943,6 @@ def search_requests_with_expr(

search_params = {
"topk": limit,
"params": params,
"round_decimal": round_decimal,
"ignore_growing": ignore_growing,
}
Expand Down Expand Up @@ -999,6 +998,8 @@ def search_requests_with_expr(
if param.get(HINTS) is not None:
search_params[HINTS] = param[HINTS]

search_params["params"] = get_params(param)

req_params = [
common_types.KeyValuePair(key=str(key), value=utils.dumps(value))
for key, value in search_params.items()
Expand Down
18 changes: 18 additions & 0 deletions pymilvus/client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,24 @@ def traverse_upsert_info(fields_info: Any):
return location, primary_key_loc


def get_params(search_params: Dict):
# after 2.5.2, all parameters of search_params can be written into one layer
# no more parameters will be written searchParams.params
# to ensure compatibility and milvus can still get a json format parameter
# try to write all the parameters under searchParams into searchParams.Params
params = search_params.get("params", {})
for key, value in search_params.items():
if key in params:
if params[key] != value:
raise ParamError(
message=f"ambiguous parameter: {key}, in search_param: {value}, in search_param.params: {params[key]}"
)
elif key != "params":
params[key] = value

return params


def get_server_type(host: str):
return ZILLIZ if (isinstance(host, str) and "zilliz" in host.lower()) else MILVUS

Expand Down
4 changes: 3 additions & 1 deletion pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ResourceGroupConfig,
construct_cost_extra,
)
from pymilvus.client.utils import is_vector_type
from pymilvus.client.utils import get_params, is_vector_type
from pymilvus.exceptions import (
DataTypeNotMatchException,
ErrorCode,
Expand Down Expand Up @@ -657,6 +657,8 @@ def search_iterator(
ParamError, f"Cannot set up metrics type for anns_field:{anns_field}"
)

search_params["params"] = get_params(search_params)

return SearchIterator(
connection=self._get_connection(),
collection_name=collection_name,
Expand Down
1 change: 1 addition & 0 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ def search_iterator(
):
if expr is not None and not isinstance(expr, str):
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(expr))
param["params"] = utils.get_params(param)
return SearchIterator(
connection=self._get_connection(),
collection_name=self._name,
Expand Down
Loading