{"record":{"id":"a67c3950231c2be2","repo":"chroma-core/chroma","slug":"input-must-be-a-list-of-text-documents-str-or-a","errorCode":null,"errorMessage":"Input must be a list of text documents (str) or a list of images (numpy arrays).","messagePattern":"Input must be a list of text documents \\(str\\) or a list of images \\(numpy arrays\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/cohere_embedding_function.py","lineNumber":126,"sourceCode":"\n            return [\n                np.array(embeddings, dtype=np.float32)\n                for embeddings in self.client.embed(\n                    images=base64_images,\n                    model=self.model_name,\n                    input_type=\"image\",\n                ).embeddings\n            ]\n        else:\n            # Check if it's a mix or neither\n            has_texts = any(is_document(item) for item in input)\n            has_images = any(is_image(item) for item in input)\n            if has_texts and has_images:\n                raise ValueError(\n                    \"Input contains a mix of text documents and images, which is not supported. Provide either all texts or all images.\"\n                )\n            else:\n                raise ValueError(\n                    \"Input must be a list of text documents (str) or a list of images (numpy arrays).\"\n                )\n\n    @staticmethod\n    def name() -> str:\n        return \"cohere\"\n\n    def default_space(self) -> Space:\n        if self.model_name == \"embed-multilingual-v2.0\":\n            return \"ip\"\n        return \"cosine\"\n\n    def supported_spaces(self) -> List[Space]:\n        if self.model_name == \"embed-english-v2.0\":\n            return [\"cosine\"]\n        elif self.model_name == \"embed-english-light-v2.0\":\n            return [\"cosine\"]\n        elif self.model_name == \"embed-multilingual-v2.0\":","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cohere_embedding_function.py#L108-L144","documentation":"This is the catch-all of __call__'s dispatch: the batch is neither all documents nor all images, and it is not even a mix of the two - no element qualifies as a str document or an image. Typical elements are dicts, ints, None, bytes, or row objects whose text field was never extracted.","triggerScenarios":"ef([{'text': 'hello'}]), ef([1, 2, 3]), ef([None]), or ef([b'raw bytes']) - nothing in the list is a str or an ndarray image.","commonSituations":"Forgetting to extract a field before embedding parsed JSON/DB rows; passing None placeholders for empty documents; reading files as bytes without decoding; passing objects that fail both is_document and is_image checks.","solutions":["Coerce items to str explicitly: ef([str(x) for x in items]) when text was intended.","Extract the text field from structured records before embedding (e.g. [r['text'] for r in rows]).","Validate upstream that every element is str or np.ndarray and drop None/empty placeholders."],"exampleFix":"# before\nef([{'text': 'hello'}, {'text': 'world'}])  # ValueError: must be str or ndarrays\n\n# after\ndocs = [r['text'] for r in records]\nef(docs)","handlingStrategy":"type-guard","validationCode":"import numpy as np\nif not all(isinstance(x, (str, np.ndarray)) for x in batch):\n    batch = [x['text'] if isinstance(x, dict) else str(x) for x in batch]","typeGuard":"import numpy as np\n\ndef is_embeddable_batch(batch: list) -> bool:\n    return len(batch) > 0 and all(isinstance(x, (str, np.ndarray)) for x in batch)","tryCatchPattern":"try:\n    embs = ef(batch)\nexcept ValueError as e:\n    if 'must be a list of text documents' in str(e):\n        embs = ef([str(x) for x in batch])  # or extract the right field upstream\n    else:\n        raise","preventionTips":["Extract text fields from structured records before embedding.","Filter None/empty placeholders out of batches at load time.","Keep a single validated input type at the pipeline boundary."],"tags":["chroma","cohere","input-validation","type-error","embedding-function"],"backgroundTag":"invalid-input-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}