chroma-core/chroma · error · ValueError

Mistral only supports text documents, not images

Error message

Mistral only supports text documents, not images

What it means

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.

Source

Thrown at chromadb/utils/embedding_functions/mistral_embedding_function.py:42

            raise ValueError(
                "The mistralai python package is not installed. Please install it with `pip install mistralai`"
            )
        self.model = model
        self.api_key_env_var = api_key_env_var
        self.api_key = os.getenv(api_key_env_var)
        if not self.api_key:
            raise ValueError(f"The {api_key_env_var} environment variable is not set.")
        self.client = Mistral(api_key=self.api_key)

    def __call__(self, input: Documents) -> Embeddings:
        """
        Get the embeddings for a list of texts.

        Args:
            input (Documents): A list of texts to get embeddings for.
        """
        if not all(isinstance(item, str) for item in input):
            raise ValueError("Mistral only supports text documents, not images")
        output = self.client.embeddings.create(
            model=self.model,
            inputs=input,
        )

        # Extract embeddings from the response
        return [np.array(data.embedding) for data in output.data]

    @staticmethod
    def name() -> str:
        return "mistral"

    def default_space(self) -> Space:
        return "cosine"

    def supported_spaces(self) -> List[Space]:
        return ["cosine", "l2", "ip"]

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Filter/convert before calling: decode bytes with .decode('utf-8') and drop or reroute image items
  2. Use a multimodal EF (e.g. JinaEmbeddingFunction) for collections that must embed images
  3. Add an isinstance(item, str) assertion at the boundary of your ingestion code

Example fix

# before
collection.add(documents=[img_array, "caption"], ids=["1", "2"])  # ValueError

# after
text_docs = [d for d in docs if isinstance(d, str)]
collection.add(documents=text_docs, ids=[str(i) for i in range(len(text_docs))])
Defensive patterns

Strategy: type-guard

Validate before calling

if not all(isinstance(d, str) for d in docs):
    raise TypeError("Mistral EF embeds text documents only")
collection.add(documents=docs, ids=ids)

Type guard

from typing import List

def is_all_text(docs: List[object]) -> bool:
    """Narrow to text-only inputs accepted by the Mistral EF."""
    return len(docs) > 0 and all(isinstance(d, str) for d in docs)

Try / catch

try:
    vectors = ef(docs)
except ValueError as e:
    if "only supports text" in str(e):
        docs = [d.decode("utf-8") if isinstance(d, bytes) else d for d in docs]
        docs = [d for d in docs if isinstance(d, str)]
        vectors = ef(docs)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/a218ef04e0d1bdc1. Report an issue: GitHub.