Skip to content

Commit

Permalink
change func header
Browse files Browse the repository at this point in the history
  • Loading branch information
spikechroma committed Sep 11, 2024
1 parent c6a3226 commit 3668936
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
8 changes: 4 additions & 4 deletions chromadb/api/models/CollectionCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _validate_record_set(
record_set, include=["embeddings", "documents", "images", "metadatas"]
):
raise ValueError("You must provide either data or metadatas.")

validate_record_set(record_set)

def _compute_embeddings(
Expand All @@ -215,7 +215,7 @@ def _compute_embeddings(
else:
if uris is None:
raise ValueError(
"You must provide either embeddings, documents, images, or uris."
"You must provide either embeddings, documents, images, or URIs."
)
if self._data_loader is None:
raise ValueError(
Expand Down Expand Up @@ -430,7 +430,7 @@ def _process_upsert_request(
)

if unpacked_record_set["ids"] is None:
raise ValueError("You must provide ids.")
raise ValueError("You must provide ids when upserting.")

self._validate_record_set(
unpacked_record_set,
Expand Down Expand Up @@ -470,7 +470,7 @@ def _process_update_request(
)

if unpacked_record_set["ids"] is None:
raise ValueError("You must provide ids.")
raise ValueError("You must provide ids when updating.")

self._validate_record_set(
unpacked_record_set,
Expand Down
2 changes: 1 addition & 1 deletion chromadb/api/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def generate_ids_when_not_present(
if ids is not None:
return ids

(_, n) = get_n_items_from_record_set(record_set)
n = get_n_items_from_record_set(record_set)
generated_ids: List[str] = [str(uuid4()) for _ in range(n)]

return generated_ids
Expand Down
11 changes: 5 additions & 6 deletions chromadb/api/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Union, TypeVar, List, Dict, Any, Tuple, cast
from typing import Optional, Union, TypeVar, List, Dict, Any, cast
from numpy.typing import NDArray
import numpy as np
from typing_extensions import TypedDict, Protocol, runtime_checkable
Expand Down Expand Up @@ -566,7 +566,7 @@ def validate_batch_size(
record_set: RecordSet,
limits: Dict[str, Any],
) -> None:
(_, batch_size) = get_n_items_from_record_set(record_set)
batch_size = get_n_items_from_record_set(record_set)

if batch_size > limits["max_batch_size"]:
raise ValueError(
Expand Down Expand Up @@ -620,16 +620,15 @@ def validate_record_set_consistency(record_set: RecordSet) -> None:

def get_n_items_from_record_set(
record_set: RecordSet,
) -> Tuple[str, int]:
) -> int:
"""
Get the number of items in the record set.
"""

validate_record_set_consistency(record_set)

for field, value in record_set.items():
for value in record_set.values():
if isinstance(value, list) and len(value) > 0:
return field, len(value)
return len(value)

raise ValueError("Expected record set to contain at least one record")

Expand Down
2 changes: 1 addition & 1 deletion chromadb/test/api/test_api_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def test_update_with_none_ids(client: ClientAPI) -> None:
collection = client.create_collection("test")
with pytest.raises(ValueError) as e:
collection.update(ids=None, embeddings=[[0.1, 0.2, 0.3]]) # type: ignore[arg-type]
assert "You must provide ids." in str(e)
assert "You must provide ids when updating." in str(e)
2 changes: 1 addition & 1 deletion chromadb/test/api/test_api_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ def test_upsert_with_none_ids(client: ClientAPI) -> None:
collection = client.create_collection("test")
with pytest.raises(ValueError) as e:
collection.upsert(ids=None, embeddings=[[0.1, 0.2, 0.3]]) # type: ignore[arg-type]
assert "You must provide ids." in str(e)
assert "You must provide ids when upserting." in str(e)
7 changes: 2 additions & 5 deletions chromadb/test/property/invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ def get_n_items_from_record_set_state(state_record_set: StateMachineRecordSet) -
if all_fields_are_empty:
return 0

(_, n) = types.get_n_items_from_record_set(record_set_with_empty_lists_replaced)
return n
return types.get_n_items_from_record_set(record_set_with_empty_lists_replaced)


def get_n_items_from_record_set(record_set: RecordSet) -> int:
"""Get the number of items from a record set"""
normalized_record_set = wrap_all(record_set)

(_, n) = types.get_n_items_from_record_set(
return types.get_n_items_from_record_set(
{
"ids": normalized_record_set["ids"],
"embeddings": normalized_record_set["embeddings"],
Expand All @@ -121,8 +120,6 @@ def get_n_items_from_record_set(record_set: RecordSet) -> int:
}
)

return n


def count(collection: Collection, record_set: RecordSet) -> None:
"""The given collection count is equal to the number of embeddings"""
Expand Down
2 changes: 1 addition & 1 deletion chromadb/test/property/test_cross_version_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_cycle_versions(
# the previous versions
version, settings = version_settings

# TODO: This conditionn is subject to change as we decide on whether we want
# TODO: This condition is subject to change as we decide on whether we want to
# release auto ID generation feature after 0.5.5
if (
packaging_version.Version(version) > packaging_version.Version("0.5.5")
Expand Down

0 comments on commit 3668936

Please sign in to comment.