diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ec4471..9ea7689 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,4 +40,4 @@ repos: "hypothesis", "pytest", "numpy", - ] \ No newline at end of file + ] diff --git a/chromadb/api/types.py b/chromadb/api/types.py index ae22866..8f1eb32 100644 --- a/chromadb/api/types.py +++ b/chromadb/api/types.py @@ -126,10 +126,13 @@ def validate_metadata(metadata: Metadata) -> Metadata: raise ValueError(f"Expected metadata to be a dict, got {metadata}") for key, value in metadata.items(): if not isinstance(key, str): - raise ValueError(f"Expected metadata key to be a str, got {key}") - if not isinstance(value, (str, int, float)): raise ValueError( - f"Expected metadata value to be a str, int, or float, got {value}" + f"Expected metadata key to be a str, got {key} which is a {type(key)}" + ) + # isinstance(True, int) evaluates to True, so we need to check for bools separately + if not isinstance(value, (str, int, float)) or isinstance(value, bool): + raise ValueError( + f"Expected metadata value to be a str, int, or float, got {value} which is a {type(value)}" ) return metadata diff --git a/chromadb/test/property/test_filtering.py b/chromadb/test/property/test_filtering.py index ac6ec11..08fddb7 100644 --- a/chromadb/test/property/test_filtering.py +++ b/chromadb/test/property/test_filtering.py @@ -190,7 +190,7 @@ def test_filterable_metadata_query( api.reset() coll = api.create_collection( name=collection.name, - metadata=collection.metadata, + metadata=collection.metadata, # type: ignore embedding_function=collection.embedding_function, ) coll.add(**record_set) @@ -259,3 +259,20 @@ def test_empty_filter(api: API) -> None: assert res["embeddings"] is None assert res["distances"] == [[], []] assert res["metadatas"] == [[], []] + + +@pytest.mark.xfail(reason="Boolean metadata is not supported yet") +def test_boolean_metadata(api: API) -> None: + """Test that metadata with boolean values is correctly filtered""" + api.reset() + coll = api.create_collection(name="test") + + test_ids: IDs = ["1", "2", "3"] + test_embeddings: Embeddings = [[1, 1], [2, 2], [3, 3]] + test_metadatas: Metadatas = [{"test": True}, {"test": False}, {"test": True}] + + coll.add(ids=test_ids, embeddings=test_embeddings, metadatas=test_metadatas) + + res = coll.get(where={"test": True}) + + assert res["ids"] == ["1", "3"] diff --git a/clients/js/src/embeddings/CohereEmbeddingFunction.ts b/clients/js/src/embeddings/CohereEmbeddingFunction.ts index 847b800..c291a62 100644 --- a/clients/js/src/embeddings/CohereEmbeddingFunction.ts +++ b/clients/js/src/embeddings/CohereEmbeddingFunction.ts @@ -26,4 +26,4 @@ export class CohereEmbeddingFunction implements IEmbeddingFunction { }); return response.body.embeddings; } -} \ No newline at end of file +} diff --git a/clients/js/src/embeddings/IEmbeddingFunction.ts b/clients/js/src/embeddings/IEmbeddingFunction.ts index c3ecc50..dcc21ab 100644 --- a/clients/js/src/embeddings/IEmbeddingFunction.ts +++ b/clients/js/src/embeddings/IEmbeddingFunction.ts @@ -1,3 +1,3 @@ export interface IEmbeddingFunction { generate(texts: string[]): Promise; -} \ No newline at end of file +} diff --git a/clients/js/src/embeddings/OpenAIEmbeddingFunction.ts b/clients/js/src/embeddings/OpenAIEmbeddingFunction.ts index dd1f62a..334a5a0 100644 --- a/clients/js/src/embeddings/OpenAIEmbeddingFunction.ts +++ b/clients/js/src/embeddings/OpenAIEmbeddingFunction.ts @@ -45,4 +45,4 @@ export class OpenAIEmbeddingFunction implements IEmbeddingFunction { } return embeddings; } -} \ No newline at end of file +} diff --git a/clients/js/src/utils.ts b/clients/js/src/utils.ts index 744b7af..afca589 100644 --- a/clients/js/src/utils.ts +++ b/clients/js/src/utils.ts @@ -62,4 +62,4 @@ export async function handleSuccess(response: Response | string | Count200Respon default: return repack(response); } -} \ No newline at end of file +}