{"record":{"id":"31a91c2dd06e77f2","repo":"chroma-core/chroma","slug":"expected-a-1-dimensional-array-got-a-0-dimensiona","errorCode":null,"errorMessage":"Expected a 1-dimensional array, got a 0-dimensional array {embedding}","messagePattern":"Expected a 1-dimensional array, got a 0-dimensional array (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1389,"sourceCode":"\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,\n            np.int64,\n        ]:\n            raise ValueError(\n                \"Expected each value in the embedding to be a int or float, got an embedding with \"\n                f\"{embedding.dtype} - {embedding}\"\n            )","sourceCodeStart":1371,"sourceCodeEnd":1407,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1371-L1407","documentation":"Each embedding must be a 1-dimensional array. validate_embeddings checks embedding.ndim and raises when it equals 0 — a numpy scalar such as np.array(0.5) or np.float32(0.5), which has no length axis and cannot be a vector.","triggerScenarios":"embeddings=[np.array(0.5)] or [np.float32(x) for x in values] — typically the result of reducing/aggregating per-dimension (e.g. taking mean over the wrong axis) or unrolling a matrix with scalars instead of rows.","commonSituations":"Averaging embeddings with .mean() without axis=1; indexing arr[i, j] instead of arr[i]; converting a single vector with np.array(value) where value is already a scalar.","solutions":["Build vectors as 1-D arrays: np.asarray(values, dtype=np.float32) where values is a flat sequence","Fix the reduction: use axis=0/axis=1 correctly, or arr.mean(axis=1) to keep one vector per row","Index rows, not cells: use matrix[i] not matrix[i][j]"],"exampleFix":"# before\nemb = np.array(scores).mean()          # 0-dim scalar\nembeddings = [emb]\n\n# after\nemb = np.asarray(scores, dtype=np.float32)  # 1-D vector\nembeddings = [emb]","handlingStrategy":"type-guard","validationCode":"import numpy as np\n\ndef ensure_1d(embeddings):\n    out = []\n    for i, e in enumerate(embeddings):\n        arr = np.asarray(e)\n        if arr.ndim != 1:\n            raise ValueError(f\"embedding {i} has ndim={arr.ndim}, expected 1\")\n        out.append(arr)\n    return out","typeGuard":"import numpy as np\n\ndef is_1d_vector(e) -> bool:\n    return isinstance(e, np.ndarray) and e.ndim == 1","tryCatchPattern":"try:\n    validate_embeddings(embeddings)\nexcept ValueError as e:\n    if \"0-dimensional array\" in str(e):\n        embeddings = [np.atleast_1d(np.asarray(e, dtype=np.float32)) for e in embeddings]\n        validate_embeddings(embeddings)\n    else:\n        raise","preventionTips":["Use reductions with an explicit axis so results keep a dimension: mean(axis=1)","Index rows (arr[i]) not cells (arr[i, j]) when extracting vectors","Build vectors from flat sequences via np.asarray(values, dtype=np.float32)"],"tags":["chromadb","embeddings","numpy","dimensionality"],"backgroundTag":"invalid-embedding-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}