{"record":{"id":"bdd8bf3602ed3f17","repo":"chroma-core/chroma","slug":"expected-each-embedding-in-the-embeddings-to-be-a","errorCode":null,"errorMessage":"Expected each embedding in the embeddings to be a numpy array, got {list(set([type(e).__name__ for e in embeddings]))}","messagePattern":"Expected each embedding in the embeddings to be a numpy array, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1383,"sourceCode":"    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(\n                f\"Expected each embedding in the embeddings to be a 1-dimensional numpy array with at least 1 int/float value. Got a 1-dimensional numpy array with no values at pos {i}\"\n            )\n\n        if embedding.dtype not in [\n            np.float16,\n            np.float32,\n            np.float64,\n            np.int32,","sourceCodeStart":1365,"sourceCodeEnd":1401,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1365-L1401","documentation":"Every element of the embeddings list must be a numpy ndarray. validate_embeddings checks isinstance(e, np.ndarray) for each element and reports the distinct offending type names. Plain Python lists/tuples inside embeddings are rejected by this specific check (the public client normally converts, so this fires on direct calls to validation or custom API/EF implementations that skip conversion).","triggerScenarios":"Calling validate_embeddings (directly, or via a custom SegmentAPI/server or EmbeddingFunction path that does not np.array-convert) with embeddings=[[0.1, 0.2], [0.3, 0.4]] — raw lists of floats — or mixing one np.ndarray with plain lists.","commonSituations":"Custom embedding functions returning list-of-lists; loading embeddings from JSON and passing them unconverted; older Chroma versions or self-built server layers that call validation on raw input.","solutions":["Convert each item: embeddings=[np.asarray(e, dtype=np.float32) for e in embeddings]","Convert wholesale: embeddings=list(np.array(embeddings, dtype=np.float32))","Fix a custom EmbeddingFunction to return np.ndarray instances"],"exampleFix":"# before\nembeddings = [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]  # plain lists\n\n# after\nimport numpy as np\nembeddings = [np.asarray(e, dtype=np.float32) for e in embeddings]","handlingStrategy":"type-guard","validationCode":"import numpy as np\n\ndef normalize_embeddings(embeddings):\n    if isinstance(embeddings, np.ndarray):\n        embeddings = list(embeddings)\n    return [e if isinstance(e, np.ndarray) else np.asarray(e, dtype=np.float32) for e in embeddings]\n\nembeddings = normalize_embeddings(embeddings)  # every element now np.ndarray","typeGuard":"import numpy as np\n\ndef all_ndarray(embeddings) -> bool:\n    return all(isinstance(e, np.ndarray) for e in embeddings)","tryCatchPattern":"try:\n    validate_embeddings(embeddings)\nexcept ValueError as e:\n    if \"to be a numpy array\" in str(e):\n        embeddings = [np.asarray(e, dtype=np.float32) for e in embeddings]\n        validate_embeddings(embeddings)\n    else:\n        raise","preventionTips":["Always np.asarray(..., dtype=np.float32) embeddings loaded from JSON/CSV/REST","Custom embedding functions should return np.ndarray vectors, not lists","Run validation once in a shared preprocessing helper instead of trusting every call site"],"tags":["chromadb","embeddings","numpy","type-mismatch"],"backgroundTag":"invalid-embedding-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}