diff --git a/pymilvus/client/search_iterator.py b/pymilvus/client/search_iterator.py index b393845dd..f0225a720 100644 --- a/pymilvus/client/search_iterator.py +++ b/pymilvus/client/search_iterator.py @@ -12,7 +12,7 @@ ITER_SEARCH_V2_KEY, ITERATOR_FIELD, ) -from pymilvus.exceptions import MilvusException, ParamError +from pymilvus.exceptions import ExceptionsMessage, ParamError, ServerVersionIncompatibleException from pymilvus.orm.connections import Connections from pymilvus.orm.constants import MAX_BATCH_SIZE, MILVUS_LIMIT, OFFSET from pymilvus.orm.iterator import SearchPage, fall_back_to_latest_session_ts @@ -21,11 +21,6 @@ class SearchIteratorV2: - _NOT_SUPPORT_V2_MSG = """ - The server does not support Search Iterator V2. - Please upgrade your Milvus server, or create a search_iterator (v1) instead. - """ - # for compatibility, save the first result during init _saved_first_res = None _is_saved = False @@ -94,7 +89,9 @@ def next(self): if iter_info.token is not None and iter_info.token != "": self._params[ITER_SEARCH_ID_KEY] = iter_info.token else: - raise MilvusException(message=self.NOT_SUPPORT_V2_MSG) + raise ServerVersionIncompatibleException( + message=ExceptionsMessage.SearchIteratorV2FallbackWarning + ) if self._params[GUARANTEE_TIMESTAMP] <= 0: if res.get_session_ts() > 0: self._params[GUARANTEE_TIMESTAMP] = res.get_session_ts() diff --git a/pymilvus/exceptions.py b/pymilvus/exceptions.py index 4ffe503b6..5a8f881de 100644 --- a/pymilvus/exceptions.py +++ b/pymilvus/exceptions.py @@ -145,6 +145,10 @@ class InvalidConsistencyLevel(MilvusException): """Raise when consistency level is invalid""" +class ServerVersionIncompatibleException(MilvusException): + """Raise when server version is incompatible""" + + class ExceptionsMessage: NoHostPort = "connection configuration must contain 'host' and 'port'." HostType = "Type of 'host' must be str." @@ -269,3 +273,7 @@ class ExceptionsMessage: DefaultValueInvalid = ( "Default value cannot be None for a field that is defined as nullable == false." ) + SearchIteratorV2FallbackWarning = """ + The server does not support Search Iterator V2. The search_iterator (v1) is used instead. + Please upgrade your Milvus server or use an SDK version before 2.5.2 (excluded) to avoid this issue. + """ diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index 19a695610..6d468e1ef 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -22,6 +22,7 @@ MilvusException, ParamError, PrimaryKeyException, + ServerVersionIncompatibleException, ) from pymilvus.orm import utility from pymilvus.orm.collection import CollectionSchema @@ -599,9 +600,11 @@ def search_iterator( round_decimal=round_decimal, **kwargs, ) - except MilvusException as ex: - if ex.message != SearchIteratorV2._NOT_SUPPORT_V2_MSG: - raise ex from ex + except ServerVersionIncompatibleException: + # for compatibility, return search_iterator V1 + logger.warning(ExceptionsMessage.SearchIteratorV2FallbackWarning) + except Exception as ex: + raise ex from ex # following is the old code for search_iterator V1 if filter is not None and not isinstance(filter, str):