Skip to content

Commit

Permalink
fix: Disallowing 0-dimensional embeddings
Browse files Browse the repository at this point in the history
  • Loading branch information
tazarov committed Feb 9, 2024
1 parent c665838 commit ac0f89c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chromadb/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ def validate_embeddings(embeddings: Embeddings) -> Embeddings:
raise ValueError(
f"Expected each embedding in the embeddings to be a list, got {embeddings}"
)
for embedding in embeddings:
for i,embedding in enumerate(embeddings):
if len(embedding) == 0:
raise ValueError(
f"Expected each embedding in the embeddings to be a non-empty list, got empty embedding at pos {i}"
)
if not all(
[
isinstance(value, (int, float)) and not isinstance(value, bool)
Expand Down
7 changes: 7 additions & 0 deletions chromadb/test/property/test_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,10 @@ def test_autocasting_validate_embeddings_incompatible_types(
validate_embeddings(Collection._normalize_embeddings(embds))

assert "Expected each value in the embedding to be a int or float" in str(e)


def test_0dim_embedding_validation() -> None:
embds = [[]]
with pytest.raises(ValueError) as e:
validate_embeddings(embds)
assert "Expected each embedding in the embeddings to be a non-empty list" in str(e)

0 comments on commit ac0f89c

Please sign in to comment.