From 630088ffbf9a85d63a4f3a64787fb2cb495fd92d Mon Sep 17 00:00:00 2001 From: smellthemoon <64083300+smellthemoon@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:32:57 +0800 Subject: [PATCH] enhance: simplify the structure of search_params(#2507)(#2537)(#2540) (#2550) pr: #2507 #2537 #2540 --------- Signed-off-by: lixinguo Co-authored-by: lixinguo --- pymilvus/client/prepare.py | 5 +++-- pymilvus/client/utils.py | 18 ++++++++++++++++++ pymilvus/milvus_client/milvus_client.py | 4 +++- pymilvus/orm/collection.py | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pymilvus/client/prepare.py b/pymilvus/client/prepare.py index 921ed8257..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: @@ -943,7 +943,6 @@ def search_requests_with_expr( search_params = { "topk": limit, - "params": params, "round_decimal": round_decimal, "ignore_growing": ignore_growing, } @@ -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() 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 4b5e9ab9a..e0fa071f8 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,