{"record":{"id":"bf229ca54057a5b8","repo":"chroma-core/chroma","slug":"input-contains-a-mix-of-text-documents-and-images","errorCode":null,"errorMessage":"Input contains a mix of text documents and images, which is not supported. Provide either all texts or all images.","messagePattern":"Input contains a mix of text documents and images, which is not supported\\. Provide either all texts or all images\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/cohere_embedding_function.py","lineNumber":122,"sourceCode":"                except Exception as e:\n                    raise ValueError(\n                        f\"Failed to convert image numpy array to base64 data URI: {e}\"\n                    ) from e\n\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\":","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cohere_embedding_function.py#L104-L140","documentation":"Cohere is called either in text mode (texts=[...], input_type='search_document') or image mode (images=[...], input_type='image') - never both in one request. __call__ dispatches on the homogeneous type of the batch; when some items are documents and others images it cannot choose a mode and rejects the batch with this explicit message.","triggerScenarios":"ef(['a caption', np.zeros((32, 32, 3), dtype=np.uint8)]) - at least one str-like document and at least one image in the same list.","commonSituations":"Ingesting mixed media (product titles + product photos) in one batch; concatenating text and image lists before a single ef() call; upstream loaders yielding heterogeneous records.","solutions":["Split the batch by type and call ef() twice - once for texts, once for ndarrays.","Structure the ingestion pipeline to embed text and image streams separately from the start.","Tag items upstream (e.g. {'kind': 'text'|'image'}) so routing happens before the embedding function sees them."],"exampleFix":"# before\nef(['hello', img_array])  # ValueError: mix of text and images\n\n# after\ntexts = [x for x in batch if isinstance(x, str)]\nimages = [x for x in batch if isinstance(x, np.ndarray)]\ntext_embs = ef(texts)\nimg_embs = ef(images) if images else []","handlingStrategy":"type-guard","validationCode":"import numpy as np\ntexts = [x for x in batch if isinstance(x, str)]\nimages = [x for x in batch if isinstance(x, np.ndarray)]\nif texts and images:\n    raise ValueError('split batch: embed texts and images in separate ef() calls')","typeGuard":"import numpy as np\n\ndef is_homogeneous(batch: list) -> bool:\n    return (len(batch) > 0 and\n            (all(isinstance(x, str) for x in batch) or\n             all(isinstance(x, np.ndarray) for x in batch)))","tryCatchPattern":"try:\n    embs = ef(batch)\nexcept ValueError as e:\n    if 'mix of text documents and images' in str(e):\n        texts = [x for x in batch if isinstance(x, str)]\n        images = [x for x in batch if isinstance(x, np.ndarray)]\n        embs = ef(texts) + (ef(images) if images else [])\n    else:\n        raise","preventionTips":["Never concatenate text and image lists before embedding.","Route media types to separate queues/requests at ingestion design time.","Tag records with their modality so dispatch happens before the EF."],"tags":["chroma","cohere","multimodal","batch-input","input-validation"],"backgroundTag":"mixed-input-types","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}