From d935b23b5624e159b2285782c3f7e2ef8bcd1d00 Mon Sep 17 00:00:00 2001 From: hh-space-invader Date: Wed, 4 Dec 2024 09:43:49 +0200 Subject: [PATCH] chore: Changed warning stack level refactor: Refactored user warnings in local mode when large upload --- qdrant_client/common/client_warnings.py | 2 +- qdrant_client/local/async_qdrant_local.py | 2 +- qdrant_client/local/local_collection.py | 21 +++++++-------------- qdrant_client/local/qdrant_local.py | 4 ++-- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/qdrant_client/common/client_warnings.py b/qdrant_client/common/client_warnings.py index 918622e0..16fb7340 100644 --- a/qdrant_client/common/client_warnings.py +++ b/qdrant_client/common/client_warnings.py @@ -5,7 +5,7 @@ def show_warning(message: str, category: type[Warning] = UserWarning) -> None: - warnings.warn(message, category, stacklevel=2) + warnings.warn(message, category, stacklevel=4) def show_warning_once( diff --git a/qdrant_client/local/async_qdrant_local.py b/qdrant_client/local/async_qdrant_local.py index 772e8e0c..8f34ec24 100644 --- a/qdrant_client/local/async_qdrant_local.py +++ b/qdrant_client/local/async_qdrant_local.py @@ -109,7 +109,7 @@ def _load(self) -> None: self.collections[collection_name] = collection if len(collection.ids) > self.LARGE_DATA_THRESHOLD: show_warning_once( - message=f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points. Consider using Qdrant docker (http/grpc) or Qdrant cloud for better performance with large datasets.", + message=f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points, currect collection contains {len(collection.ids)}.Consider using Qdrant in docker or Qdrant cloud for better performance with large datasets.", category=UserWarning, idx="large-local-collection", ) diff --git a/qdrant_client/local/local_collection.py b/qdrant_client/local/local_collection.py index b33d7db5..2eb850e9 100644 --- a/qdrant_client/local/local_collection.py +++ b/qdrant_client/local/local_collection.py @@ -2161,20 +2161,6 @@ def _upsert_point(self, point: models.PointStruct) -> None: self.storage.persist(point) def upsert(self, points: Union[Sequence[models.PointStruct], models.Batch]) -> None: - points_count = ( - len(points) - if isinstance(points, list) - else len(points.ids) - if isinstance(points, models.Batch) - else 0 - ) - if len(self.ids) + points_count > self.LARGE_DATA_THRESHOLD: - show_warning_once( - f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points. " - "Consider using Qdrant docker (http/grpc) or Qdrant cloud for better performance with large datasets.", - category=UserWarning, - idx="large-local-collection", - ) if isinstance(points, list): for point in points: self._upsert_point(point) @@ -2199,6 +2185,13 @@ def upsert(self, points: Union[Sequence[models.PointStruct], models.Batch]) -> N vector=vector, ) ) + if len(self.ids) > self.LARGE_DATA_THRESHOLD: + show_warning_once( + f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points, currect collection contains {len(self.ids)}." + "Consider using Qdrant in docker or Qdrant cloud for better performance with large datasets.", + category=UserWarning, + idx="large-local-collection", + ) else: raise ValueError(f"Unsupported type: {type(points)}") diff --git a/qdrant_client/local/qdrant_local.py b/qdrant_client/local/qdrant_local.py index 67822b8d..b9e81105 100644 --- a/qdrant_client/local/qdrant_local.py +++ b/qdrant_client/local/qdrant_local.py @@ -112,8 +112,8 @@ def _load(self) -> None: self.collections[collection_name] = collection if len(collection.ids) > self.LARGE_DATA_THRESHOLD: show_warning_once( - message=f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points. " - "Consider using Qdrant docker (http/grpc) or Qdrant cloud for better performance with large datasets.", + message=f"Local mode is not recommended for collections with more than {self.LARGE_DATA_THRESHOLD:,} points, currect collection contains {len(collection.ids)}." + "Consider using Qdrant in docker or Qdrant cloud for better performance with large datasets.", category=UserWarning, idx="large-local-collection", )