Skip to content

Commit

Permalink
enhance: intro ServerVersionIncompatibleException
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Weizhi Xu <[email protected]>
  • Loading branch information
PwzXxm committed Dec 30, 2024
1 parent 3ce4ac0 commit 0359222
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
11 changes: 4 additions & 7 deletions pymilvus/client/search_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions pymilvus/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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.
"""
9 changes: 6 additions & 3 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MilvusException,
ParamError,
PrimaryKeyException,
ServerVersionIncompatibleException,
)
from pymilvus.orm import utility
from pymilvus.orm.collection import CollectionSchema
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0359222

Please sign in to comment.