{"record":{"id":"a218ef04e0d1bdc1","repo":"chroma-core/chroma","slug":"mistral-only-supports-text-documents-not-images","errorCode":null,"errorMessage":"Mistral only supports text documents, not images","messagePattern":"Mistral only supports text documents, not images","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/mistral_embedding_function.py","lineNumber":42,"sourceCode":"            raise ValueError(\n                \"The mistralai python package is not installed. Please install it with `pip install mistralai`\"\n            )\n        self.model = model\n        self.api_key_env_var = api_key_env_var\n        self.api_key = os.getenv(api_key_env_var)\n        if not self.api_key:\n            raise ValueError(f\"The {api_key_env_var} environment variable is not set.\")\n        self.client = Mistral(api_key=self.api_key)\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Get the embeddings for a list of texts.\n\n        Args:\n            input (Documents): A list of texts to get embeddings for.\n        \"\"\"\n        if not all(isinstance(item, str) for item in input):\n            raise ValueError(\"Mistral only supports text documents, not images\")\n        output = self.client.embeddings.create(\n            model=self.model,\n            inputs=input,\n        )\n\n        # Extract embeddings from the response\n        return [np.array(data.embedding) for data in output.data]\n\n    @staticmethod\n    def name() -> str:\n        return \"mistral\"\n\n    def default_space(self) -> Space:\n        return \"cosine\"\n\n    def supported_spaces(self) -> List[Space]:\n        return [\"cosine\", \"l2\", \"ip\"]\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/mistral_embedding_function.py#L24-L60","documentation":"MistralEmbeddingFunction.__call__ validates that every input item is a str before calling client.embeddings.create, raising this ValueError for any non-string document. The mistral-embed model is text-only, and Chroma's Documents union permits image values (numpy arrays, PIL images) for multimodal EFs, so this guard rejects image payloads before the API call.","triggerScenarios":"collection.add(documents=[np_image_array]) with the Mistral EF; ef([b'raw bytes', 'text']) where bytes were not decoded; feeding PIL.Image objects from a multimodal pipeline.","commonSituations":"Shared ingestion pipelines that carry images for other collections; documents read from binary sources (databases, kafka) arriving as bytes; switching a multimodal collection's EF to Mistral without filtering inputs.","solutions":["Filter/convert before calling: decode bytes with .decode('utf-8') and drop or reroute image items","Use a multimodal EF (e.g. JinaEmbeddingFunction) for collections that must embed images","Add an isinstance(item, str) assertion at the boundary of your ingestion code"],"exampleFix":"# before\ncollection.add(documents=[img_array, \"caption\"], ids=[\"1\", \"2\"])  # ValueError\n\n# after\ntext_docs = [d for d in docs if isinstance(d, str)]\ncollection.add(documents=text_docs, ids=[str(i) for i in range(len(text_docs))])","handlingStrategy":"type-guard","validationCode":"if not all(isinstance(d, str) for d in docs):\n    raise TypeError(\"Mistral EF embeds text documents only\")\ncollection.add(documents=docs, ids=ids)","typeGuard":"from typing import List\n\ndef is_all_text(docs: List[object]) -> bool:\n    \"\"\"Narrow to text-only inputs accepted by the Mistral EF.\"\"\"\n    return len(docs) > 0 and all(isinstance(d, str) for d in docs)","tryCatchPattern":"try:\n    vectors = ef(docs)\nexcept ValueError as e:\n    if \"only supports text\" in str(e):\n        docs = [d.decode(\"utf-8\") if isinstance(d, bytes) else d for d in docs]\n        docs = [d for d in docs if isinstance(d, str)]\n        vectors = ef(docs)\n    else:\n        raise","preventionTips":["Decode bytes at the ingestion boundary; keep document payloads typed as str end-to-end","Route image documents to a multimodal-capable collection","Add a schema assertion on incoming batches before touching chroma"],"tags":["python","validation","text-only","mistral","multimodal"],"backgroundTag":"unsupported-input-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}