Skip to content

Commit

Permalink
fix: check params consistency failed in search iterator v1 (#2540)
Browse files Browse the repository at this point in the history
Signed-off-by: lixinguo <xinguo.li@zilliz.com>
Co-authored-by: lixinguo <xinguo.li@zilliz.com>
  • Loading branch information
smellthemoon and lixinguo authored Jan 3, 2025
1 parent cd89fe4 commit c70d44c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
16 changes: 2 additions & 14 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 @@ -998,19 +998,7 @@ def search_requests_with_expr(
if param.get(HINTS) is not None:
search_params[HINTS] = param[HINTS]

# after 2.5.1, 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
for key, value in param.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
search_params["params"] = params
search_params["params"] = get_params(param)

req_params = [
common_types.KeyValuePair(key=str(key), value=utils.dumps(value))
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

0 comments on commit c70d44c

Please sign in to comment.