From 35b24d22fd66302acc3f0cabd31333e09a28395d Mon Sep 17 00:00:00 2001 From: Jiquan Long Date: Mon, 18 Mar 2024 16:18:59 +0800 Subject: [PATCH] enhance: retry on inconsistent requery (#1975) * enhance: retry on inconsistent requery Signed-off-by: longjiquan * fix Signed-off-by: longjiquan * fix lint Signed-off-by: longjiquan * revert Signed-off-by: longjiquan * fix Signed-off-by: longjiquan * fix Signed-off-by: longjiquan --------- Signed-off-by: longjiquan --- pymilvus/client/grpc_handler.py | 4 ++-- pymilvus/decorators.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index 8865b55a3..a069a1698 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -753,7 +753,7 @@ def _execute_hybrid_search( return SearchFuture(None, None, e) raise e from e - @retry_on_rpc_failure() + @retry_on_rpc_failure(retry_on_inconsistent_requery=True) def search( self, collection_name: str, @@ -793,7 +793,7 @@ def search( ) return self._execute_search(request, timeout, round_decimal=round_decimal, **kwargs) - @retry_on_rpc_failure() + @retry_on_rpc_failure(retry_on_inconsistent_requery=True) def hybrid_search( self, collection_name: str, diff --git a/pymilvus/decorators.py b/pymilvus/decorators.py index e897c3405..980e046a5 100644 --- a/pymilvus/decorators.py +++ b/pymilvus/decorators.py @@ -45,6 +45,7 @@ def retry_on_rpc_failure( initial_back_off: float = 0.01, max_back_off: float = 3, back_off_multiplier: int = 3, + retry_on_inconsistent_requery: bool = False, ): def wrapper(func: Any): @functools.wraps(func) @@ -106,8 +107,14 @@ def timeout(start_time: Optional[float] = None) -> bool: raise MilvusException( code=e.code, message=f"{to_msg}, message={e.message}" ) from e - if _retry_on_rate_limit and ( - e.code == ErrorCode.RATE_LIMIT or e.compatible_code == common_pb2.RateLimit + if ( + _retry_on_rate_limit + and ( + e.code == ErrorCode.RATE_LIMIT + or e.compatible_code == common_pb2.RateLimit + ) + or retry_on_inconsistent_requery + and e.code == 2200 ): time.sleep(back_off) back_off = min(back_off * back_off_multiplier, max_back_off)