Skip to content

Commit

Permalink
reorder validation business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
spikechroma committed Aug 27, 2024
1 parent b356ccd commit 9511c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion chromadb/api/models/CollectionCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _validate_embedding_set(
) -> None:
valid_documents = documents
valid_images = images

# Only one of documents or images can be provided
if valid_documents is not None and valid_images is not None:
raise ValueError("You can only provide documents or images, not both.")
Expand Down
18 changes: 10 additions & 8 deletions chromadb/api/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
)

import chromadb.types as t
from typing import Optional, Sequence, Generator, List, cast, Set, Dict, Tuple, Any
from typing import Optional, Sequence, Generator, List, cast, Set, Dict, Tuple, Union
from overrides import override
from uuid import UUID, uuid4
import time
Expand Down Expand Up @@ -831,17 +831,13 @@ def _validate_embedding_record_set(
uris: Optional[URIs] = None,
metadatas: Optional[Metadatas] = None,
) -> None:
add_attributes_to_current_span({"collection_id": str(collection["id"])})

validate_batch(
(ids, embeddings, metadatas, documents, uris),
{"max_batch_size": self.get_max_batch_size()},
)

add_attributes_to_current_span({"collection_id": str(collection["id"])})

validate_ids(ids)
validate_embeddings(embeddings) if embeddings is not None else None
validate_metadatas(metadatas) if metadatas is not None else None

if (
require_embeddings_or_data
and embeddings is None
Expand All @@ -850,7 +846,13 @@ def _validate_embedding_record_set(
):
raise ValueError("You must provide embeddings, documents, or uris.")

entities: List[Tuple[Any, str]] = [
validate_ids(ids)
validate_embeddings(embeddings) if embeddings is not None else None
validate_metadatas(metadatas) if metadatas is not None else None

entities: List[
Tuple[Union[Embeddings, Metadatas, Documents, URIs, None], str]
] = [
(embeddings, "embeddings"),
(metadatas, "metadatas"),
(documents, "documents"),
Expand Down

0 comments on commit 9511c08

Please sign in to comment.