Skip to content

Commit

Permalink
chore: Changed warning stack level
Browse files Browse the repository at this point in the history
refactor: Refactored user warnings in local mode when large upload
  • Loading branch information
hh-space-invader committed Dec 4, 2024
1 parent 581f580 commit d935b23
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion qdrant_client/common/client_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion qdrant_client/local/async_qdrant_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
21 changes: 7 additions & 14 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)}")

Expand Down
4 changes: 2 additions & 2 deletions qdrant_client/local/qdrant_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit d935b23

Please sign in to comment.