chroma-core/chroma · error · ValueError

Input contains a mix of text documents and images, which is

Error message

Input contains a mix of text documents and images, which is not supported. Provide either all texts or all images.

What it means

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.

Source

Thrown at chromadb/utils/embedding_functions/cohere_embedding_function.py:122

                except Exception as e:
                    raise ValueError(
                        f"Failed to convert image numpy array to base64 data URI: {e}"
                    ) from e

            return [
                np.array(embeddings, dtype=np.float32)
                for embeddings in self.client.embed(
                    images=base64_images,
                    model=self.model_name,
                    input_type="image",
                ).embeddings
            ]
        else:
            # Check if it's a mix or neither
            has_texts = any(is_document(item) for item in input)
            has_images = any(is_image(item) for item in input)
            if has_texts and has_images:
                raise ValueError(
                    "Input contains a mix of text documents and images, which is not supported. Provide either all texts or all images."
                )
            else:
                raise ValueError(
                    "Input must be a list of text documents (str) or a list of images (numpy arrays)."
                )

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

    def default_space(self) -> Space:
        if self.model_name == "embed-multilingual-v2.0":
            return "ip"
        return "cosine"

    def supported_spaces(self) -> List[Space]:
        if self.model_name == "embed-english-v2.0":

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Split the batch by type and call ef() twice - once for texts, once for ndarrays.
  2. Structure the ingestion pipeline to embed text and image streams separately from the start.
  3. Tag items upstream (e.g. {'kind': 'text'|'image'}) so routing happens before the embedding function sees them.

Example fix

# before
ef(['hello', img_array])  # ValueError: mix of text and images

# after
texts = [x for x in batch if isinstance(x, str)]
images = [x for x in batch if isinstance(x, np.ndarray)]
text_embs = ef(texts)
img_embs = ef(images) if images else []
Defensive patterns

Strategy: type-guard

Validate before calling

import numpy as np
texts = [x for x in batch if isinstance(x, str)]
images = [x for x in batch if isinstance(x, np.ndarray)]
if texts and images:
    raise ValueError('split batch: embed texts and images in separate ef() calls')

Type guard

import numpy as np

def is_homogeneous(batch: list) -> bool:
    return (len(batch) > 0 and
            (all(isinstance(x, str) for x in batch) or
             all(isinstance(x, np.ndarray) for x in batch)))

Try / catch

try:
    embs = ef(batch)
except ValueError as e:
    if 'mix of text documents and images' in str(e):
        texts = [x for x in batch if isinstance(x, str)]
        images = [x for x in batch if isinstance(x, np.ndarray)]
        embs = ef(texts) + (ef(images) if images else [])
    else:
        raise

Prevention

When it happens

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

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

Related errors


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