{"record":{"id":"f19f01e0520792c3","repo":"chroma-core/chroma","slug":"expected-embeddings-to-be-a-list-got-type-embedd","errorCode":null,"errorMessage":"Expected embeddings to be a list, got {type(embeddings).__name__}","messagePattern":"Expected embeddings to be a list, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1375,"sourceCode":"\ndef validate_n_results(n_results: int) -> int:\n    \"\"\"Validates n_results to ensure it is a positive Integer. Since hnswlib does not allow n_results to be negative.\"\"\"\n    # Check Number of requested results\n    if not isinstance(n_results, int):\n        raise ValueError(\n            f\"Expected requested number of results to be a int, got {n_results}\"\n        )\n    if n_results <= 0:\n        raise TypeError(\n            f\"Number of requested results {n_results}, cannot be negative, or zero.\"\n        )\n    return n_results\n\n\ndef validate_embeddings(embeddings: Embeddings) -> Embeddings:\n    \"\"\"Validates embeddings to ensure it is a list of numpy arrays of ints, or floats\"\"\"\n    if not isinstance(embeddings, (list, np.ndarray)):\n        raise ValueError(\n            f\"Expected embeddings to be a list, got {type(embeddings).__name__}\"\n        )\n    if len(embeddings) == 0:\n        raise ValueError(\n            f\"Expected embeddings to be a list with at least one item, got {len(embeddings)} embeddings\"\n        )\n    if not all([isinstance(e, np.ndarray) for e in embeddings]):\n        raise ValueError(\n            \"Expected each embedding in the embeddings to be a numpy array, got \"\n            f\"{list(set([type(e).__name__ for e in embeddings]))}\"\n        )\n    for i, embedding in enumerate(embeddings):\n        if embedding.ndim == 0:\n            raise ValueError(\n                f\"Expected a 1-dimensional array, got a 0-dimensional array {embedding}\"\n            )\n        if embedding.size == 0:\n            raise ValueError(","sourceCodeStart":1357,"sourceCodeEnd":1393,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1357-L1393","documentation":"validate_embeddings requires the embeddings argument to be a Python list or numpy ndarray. Any other type — generator, tuple, string, dict, None — raises this ValueError, with the message reporting the offending type name.","triggerScenarios":"Passing a generator or map object (embeddings=map(ef, texts)) instead of materializing it; passing a tuple of arrays; passing the output of an embedding function that returns a bare ndarray-of-ndarray or a dict keyed by id; passing None where embeddings are required (e.g. query_embeddings=None).","commonSituations":"Streaming/pipeline code that keeps lazy iterators; tuple literals used for immutability; custom EmbeddingFunction implementations with non-standard return shapes; version changes where a wrapper stopped calling list().","solutions":["Materialize iterables: embeddings=list(embeddings)","Convert tuples: embeddings=list(tuples) — tuple is not accepted even though it is sequence-like","If your custom embedding function returns an ndarray, wrap as list(arr) or keep the ndarray itself (both accepted)"],"exampleFix":"# before\nresults = collection.query(query_embeddings=map(ef, [query]), n_results=5)\n\n# after\nresults = collection.query(query_embeddings=list(map(ef, [query])), n_results=5)","handlingStrategy":"type-guard","validationCode":"def materialize_embeddings(embeddings):\n    if isinstance(embeddings, (list, np.ndarray)):\n        return embeddings\n    return list(embeddings)  # materialize generators/maps/tuples\n\nres = collection.query(query_embeddings=materialize_embeddings(embeds), n_results=5)","typeGuard":"import numpy as np\n\ndef is_embeddings_container(v) -> bool:\n    return isinstance(v, (list, np.ndarray))","tryCatchPattern":"try:\n    collection.add(ids=ids, embeddings=embeddings, documents=docs)\nexcept ValueError as e:\n    if \"Expected embeddings to be a list\" in str(e):\n        collection.add(ids=ids, embeddings=list(embeddings), documents=docs)\n    else:\n        raise","preventionTips":["Never pass lazy iterables (map/filter/generators) to add/query — call list() first","Convert tuples to lists at API boundaries","Keep custom EmbeddingFunctions returning list[np.ndarray] or a single ndarray"],"tags":["chromadb","embeddings","type-mismatch","input-validation"],"backgroundTag":"invalid-embedding-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}