From c70d44c45e7f96761d1d3808c7d7401eb65d5afe Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:28:49 +0800 Subject: [PATCH] fix: check params consistency failed in search iterator v1 (#2540) Signed-off-by: lixinguo Co-authored-by: lixinguo --- pymilvus/client/prepare.py | 16 ++-------------- pymilvus/client/utils.py | 18 ++++++++++++++++++ pymilvus/milvus_client/milvus_client.py | 4 +++- pymilvus/orm/collection.py | 1 + 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/pymilvus/client/prepare.py b/pymilvus/client/prepare.py index 8c4e6666a..f0210b69d 100644 --- a/pymilvus/client/prepare.py +++ b/pymilvus/client/prepare.py @@ -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: @@ -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)) diff --git a/pymilvus/client/utils.py b/pymilvus/client/utils.py index 1ddee57bf..c7c657377 100644 --- a/pymilvus/client/utils.py +++ b/pymilvus/client/utils.py @@ -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 diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index 994b1a8a4..8535036e6 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -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, @@ -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, diff --git a/pymilvus/orm/collection.py b/pymilvus/orm/collection.py index 4484b3b3c..669076186 100644 --- a/pymilvus/orm/collection.py +++ b/pymilvus/orm/collection.py @@ -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,