Skip to content

[CHORE] Propogate error messages correctly to user #4235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions chromadb/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
Embeddings,
IDs,
Include,
IncludeMetadataDocumentsEmbeddings,
IncludeMetadataDocumentsEmbeddingsDistances,
IncludeMetadataDocumentsDistances,
IncludeMetadataDocuments,
Loadable,
Metadatas,
URIs,
Expand Down Expand Up @@ -223,27 +223,21 @@ def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = IncludeMetadataDocumentsEmbeddings,
include: Include = IncludeMetadataDocuments,
) -> GetResult:
"""[Internal] Returns entries from a collection specified by UUID.

Args:
ids: The IDs of the entries to get. Defaults to None.
where: Conditional filtering on metadata. Defaults to {}.
sort: The column to sort the entries by. Defaults to None.
limit: The maximum number of entries to return. Defaults to None.
offset: The number of entries to skip before returning. Defaults to None.
page: The page number to return. Defaults to None.
page_size: The number of entries to return per page. Defaults to None.
where_document: Conditional filtering on documents. Defaults to {}.
include: The fields to include in the response.
Defaults to ["embeddings", "metadatas", "documents"].
Defaults to ["metadatas", "documents"].
Returns:
GetResult: The entries in the collection that match the query.

Expand Down Expand Up @@ -279,7 +273,7 @@ def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = IncludeMetadataDocumentsEmbeddingsDistances,
include: Include = IncludeMetadataDocumentsDistances,
) -> QueryResult:
"""[Internal] Performs a nearest neighbors query on a collection specified by UUID.

Expand All @@ -290,7 +284,7 @@ def _query(
where: Conditional filtering on metadata. Defaults to {}.
where_document: Conditional filtering on documents. Defaults to {}.
include: The fields to include in the response.
Defaults to ["embeddings", "metadatas", "documents", "distances"].
Defaults to ["metadatas", "documents", "distances"].

Returns:
QueryResult: The results of the query.
Expand Down Expand Up @@ -670,13 +664,10 @@ def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents"], # type: ignore[list-item]
include: Include = IncludeMetadataDocuments,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> GetResult:
Expand Down Expand Up @@ -736,7 +727,7 @@ def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents", "distances"], # type: ignore[list-item]
include: Include = IncludeMetadataDocumentsDistances,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> QueryResult:
Expand Down
19 changes: 6 additions & 13 deletions chromadb/api/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
QueryResult,
GetResult,
WhereDocument,
IncludeMetadataDocuments,
IncludeMetadataDocumentsDistances,
)
from chromadb.config import Component, Settings
from chromadb.types import Database, Tenant, Collection as CollectionModel
Expand Down Expand Up @@ -215,24 +217,18 @@ async def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents"], # type: ignore[list-item]
include: Include = IncludeMetadataDocuments,
) -> GetResult:
"""[Internal] Returns entries from a collection specified by UUID.

Args:
ids: The IDs of the entries to get. Defaults to None.
where: Conditional filtering on metadata. Defaults to {}.
sort: The column to sort the entries by. Defaults to None.
limit: The maximum number of entries to return. Defaults to None.
offset: The number of entries to skip before returning. Defaults to None.
page: The page number to return. Defaults to None.
page_size: The number of entries to return per page. Defaults to None.
where_document: Conditional filtering on documents. Defaults to {}.
include: The fields to include in the response.
Defaults to ["embeddings", "metadatas", "documents"].
Expand Down Expand Up @@ -271,7 +267,7 @@ async def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents", "distances"], # type: ignore[list-item]
include: Include = IncludeMetadataDocumentsDistances,
) -> QueryResult:
"""[Internal] Performs a nearest neighbors query on a collection specified by UUID.

Expand Down Expand Up @@ -662,13 +658,10 @@ async def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents"], # type: ignore[list-item]
include: Include = IncludeMetadataDocuments,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> GetResult:
Expand Down Expand Up @@ -728,7 +721,7 @@ async def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents", "distances"], # type: ignore[list-item]
include: Include = IncludeMetadataDocumentsDistances,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> QueryResult:
Expand Down
12 changes: 4 additions & 8 deletions chromadb/api/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
GetResult,
IDs,
Include,
IncludeMetadataDocuments,
IncludeMetadataDocumentsDistances,
Loadable,
Metadatas,
QueryResult,
Expand Down Expand Up @@ -363,23 +365,17 @@ async def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents"], # type: ignore[list-item]
include: Include = IncludeMetadataDocuments,
) -> GetResult:
return await self._server._get(
collection_id=collection_id,
ids=ids,
where=where,
sort=sort,
limit=limit,
offset=offset,
page=page,
page_size=page_size,
where_document=where_document,
include=include,
tenant=self.tenant,
Expand Down Expand Up @@ -410,7 +406,7 @@ async def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents", "distances"], # type: ignore[list-item]
include: Include = IncludeMetadataDocumentsDistances,
) -> QueryResult:
return await self._server._query(
collection_id=collection_id,
Expand Down
17 changes: 6 additions & 11 deletions chromadb/api/async_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
CollectionMetadata,
validate_batch,
convert_np_embeddings_to_list,
IncludeMetadataDocuments,
IncludeMetadataDocumentsDistances,
IncludeMetadataDocumentsEmbeddings,
)


Expand Down Expand Up @@ -439,7 +442,7 @@ async def _peek(
tenant=tenant,
database=database,
limit=n,
include=["embeddings", "documents", "metadatas"],
include=IncludeMetadataDocumentsEmbeddings,
)

return resp
Expand All @@ -451,20 +454,13 @@ async def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents"],
include: Include = IncludeMetadataDocuments,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> GetResult:
if page and page_size:
offset = (page - 1) * page_size
limit = page_size

# Servers do not support the "data" include, as that is hydrated on the client side
filtered_include = [i for i in include if i != "data"]

Expand All @@ -474,7 +470,6 @@ async def _get(
json={
"ids": ids,
"where": where,
"sort": sort,
"limit": limit,
"offset": offset,
"where_document": where_document,
Expand Down Expand Up @@ -631,7 +626,7 @@ async def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents", "distances"],
include: Include = IncludeMetadataDocumentsDistances,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> QueryResult:
Expand Down
12 changes: 4 additions & 8 deletions chromadb/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
Metadatas,
QueryResult,
URIs,
IncludeMetadataDocuments,
IncludeMetadataDocumentsDistances,
)
from chromadb.auth import UserIdentity
from chromadb.auth.utils import maybe_set_tenant_and_database
Expand Down Expand Up @@ -334,25 +336,19 @@ def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents"], # type: ignore[list-item]
include: Include = IncludeMetadataDocuments,
) -> GetResult:
return self._server._get(
collection_id=collection_id,
tenant=self.tenant,
database=self.database,
ids=ids,
where=where,
sort=sort,
limit=limit,
offset=offset,
page=page,
page_size=page_size,
where_document=where_document,
include=include,
)
Expand Down Expand Up @@ -381,7 +377,7 @@ def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["embeddings", "metadatas", "documents", "distances"], # type: ignore[list-item]
include: Include = IncludeMetadataDocumentsDistances,
) -> QueryResult:
return self._server._query(
collection_id=collection_id,
Expand Down
17 changes: 6 additions & 11 deletions chromadb/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
CollectionMetadata,
validate_batch,
convert_np_embeddings_to_list,
IncludeMetadataDocuments,
IncludeMetadataDocumentsDistances,
IncludeMetadataDocumentsEmbeddings,
)
from chromadb.auth import UserIdentity
from chromadb.auth import (
Expand Down Expand Up @@ -393,7 +396,7 @@ def _peek(
tenant=tenant,
database=database,
limit=n,
include=["embeddings", "documents", "metadatas"],
include=IncludeMetadataDocumentsEmbeddings,
),
)

Expand All @@ -404,20 +407,13 @@ def _get(
collection_id: UUID,
ids: Optional[IDs] = None,
where: Optional[Where] = None,
sort: Optional[str] = None,
limit: Optional[int] = None,
offset: Optional[int] = None,
page: Optional[int] = None,
page_size: Optional[int] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents"],
include: Include = IncludeMetadataDocuments,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> GetResult:
if page and page_size:
offset = (page - 1) * page_size
limit = page_size

# Servers do not support receiving "data", as that is hydrated by the client as a loadable
filtered_include = [i for i in include if i != "data"]

Expand All @@ -427,7 +423,6 @@ def _get(
json={
"ids": ids,
"where": where,
"sort": sort,
"limit": limit,
"offset": offset,
"where_document": where_document,
Expand Down Expand Up @@ -599,7 +594,7 @@ def _query(
n_results: int = 10,
where: Optional[Where] = None,
where_document: Optional[WhereDocument] = None,
include: Include = ["metadatas", "documents", "distances"],
include: Include = IncludeMetadataDocumentsDistances,
tenant: str = DEFAULT_TENANT,
database: str = DEFAULT_DATABASE,
) -> QueryResult:
Expand Down
1 change: 0 additions & 1 deletion chromadb/api/models/AsyncCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ async def get(
where=get_request["where"],
where_document=get_request["where_document"],
include=get_request["include"],
sort=None,
limit=limit,
offset=offset,
tenant=self.tenant,
Expand Down
1 change: 0 additions & 1 deletion chromadb/api/models/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def get(
where=get_request["where"],
where_document=get_request["where_document"],
include=get_request["include"],
sort=None,
limit=limit,
offset=offset,
tenant=self.tenant,
Expand Down
6 changes: 5 additions & 1 deletion chromadb/api/models/CollectionCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ def wrapper(self: Any, *args: Any, **kwargs: Any) -> T:
try:
return func(self, *args, **kwargs)
except Exception as e:
# modify the error message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this comment doesn't add much value, i can see the msg is modified already

msg = f"{str(e)} in {name}."
raise type(e)(msg).with_traceback(e.__traceback__)
# add the rest of the args to the error message if they exist
e.args = (msg,) + e.args[1:] if e.args else ()
# raise the same error that was caught with the modified message
raise

return wrapper

Expand Down
Loading
Loading