{"record":{"id":"42cc6414a2dcabbe","repo":"chroma-core/chroma","slug":"expected-each-value-in-the-embedding-to-be-a-int-o","errorCode":null,"errorMessage":"Expected each value in the embedding to be a int or float, got an embedding with {embedding.dtype} - {embedding}","messagePattern":"Expected each value in the embedding to be a int or float, got an embedding with (.+?) - (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/types.py","lineNumber":1404,"sourceCode":"        )\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            )\n    return embeddings\n\n\ndef validate_sparse_vectors(vectors: SparseVectors) -> SparseVectors:\n    \"\"\"Validates sparse vectors to ensure it is a non-empty list of SparseVector instances.\n\n    This function validates the structure and types of sparse vectors returned by\n    SparseEmbeddingFunction implementations. It ensures:\n    - Vectors is a list\n    - List is non-empty\n    - All items are SparseVector instances\n\n    Note: Individual SparseVector validation (sorted indices, non-negative values, etc.)\n    happens automatically in SparseVector.__post_init__ when each instance is created.\n    This function only validates the list structure and instance types.","sourceCodeStart":1386,"sourceCodeEnd":1422,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/types.py#L1386-L1422","documentation":"Each embedding's dtype must be one of np.float16, np.float32, np.float64, np.int32, np.int64. validate_embeddings rejects other dtypes — notably strings ('<U...'/'object'), bool, and unsigned/low-width ints like uint8/uint16/int8 — reporting the dtype and the array contents.","triggerScenarios":"embeddings=[np.array([\"0.1\", \"0.2\"])] (string dtype from un-parsed data); np.array([True, False], dtype=bool); quantized uint8 embeddings from a binary/PQ index; object dtype created by np.array on a ragged nested list; float128 embeddings.","commonSituations":"Reading vectors from CSV/JSON where everything is strings; binary-quantized (uint8) embeddings from other toolchains (FAISS, sentence-transformers 'binary' modes); ragged lists silently becoming dtype=object; OLTP data loaded via pandas without astype.","solutions":["Cast explicitly: emb = np.asarray(e, dtype=np.float32)","If rows were ragged (different lengths), fix the source — all embeddings must share the collection's dimensionality","For string data, parse first: np.array([float(x) for x in row], dtype=np.float32)"],"exampleFix":"# before\nemb = np.array([\"0.1\", \"0.2\", \"0.3\"])          # dtype '<U3'\n\n# after\nimport numpy as np\nemb = np.asarray([0.1, 0.2, 0.3], dtype=np.float32)","handlingStrategy":"validation","validationCode":"import numpy as np\n\nALLOWED = (np.float16, np.float32, np.float64, np.int32, np.int64)\n\ndef cast_embeddings(embeddings):\n    out = []\n    for i, e in enumerate(embeddings):\n        arr = np.asarray(e)\n        if arr.dtype not in ALLOWED:\n            arr = arr.astype(np.float32)  # parses '<U'/'object'/bool/uint8 safely\n        out.append(arr)\n    return out","typeGuard":"import numpy as np\n\nALLOWED = (np.float16, np.float32, np.float64, np.int32, np.int64)\n\ndef has_allowed_dtype(e) -> bool:\n    return isinstance(e, np.ndarray) and e.dtype in ALLOWED","tryCatchPattern":"try:\n    validate_embeddings(embeddings)\nexcept ValueError as e:\n    if \"int or float\" in str(e):\n        embeddings = [e.astype(np.float32) for e in embeddings]\n        validate_embeddings(embeddings)\n    else:\n        raise","preventionTips":["Standardize on float32 at ingest: np.asarray(vec, dtype=np.float32)","Parse CSV/JSON numbers before array creation — string arrays are the usual culprit","Convert quantized uint8 embeddings back to float before handing them to Chroma"],"tags":["chromadb","embeddings","dtype","numpy"],"backgroundTag":"invalid-embedding-format","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}