chroma-core/chroma · error · ValueError

Cloudflare Workers AI only supports text documents, not imag

Error message

Cloudflare Workers AI only supports text documents, not images

What it means

__call__ posts {'text': input} to the Workers AI endpoint, which accepts text only; unlike CohereEmbeddingFunction there is no image branch. Before making the request it requires every element of input to be a str and rejects the batch otherwise. This is an up-front input-type check, not an API-side failure.

Source

Thrown at chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py:91

            self._api_url = f"{BASE_URL}/{self.account_id}/ai/run/{self.model_name}"

        self._session = httpx.Client()
        self._session.headers.update(
            {"Authorization": f"Bearer {self.api_key}", "Accept-Encoding": "identity"}
        )

    def __call__(self, input: Documents) -> Embeddings:
        """
        Generate embeddings for the given documents.

        Args:
            input: Documents to generate embeddings for.

        Returns:
            Embeddings for the documents.
        """
        if not all(isinstance(item, str) for item in input):
            raise ValueError(
                "Cloudflare Workers AI only supports text documents, not images"
            )

        payload: Dict[str, Any] = {
            "text": input,
        }

        resp = self._session.post(self._api_url, json=payload).json()

        if "result" not in resp and "data" not in resp["result"]:
            raise RuntimeError(resp.get("detail", "Unknown error"))

        return cast(Embeddings, resp["result"]["data"])

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

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Send only str documents to CloudflareWorkersAIEmbeddingFunction.
  2. For images, switch to an image-capable function (e.g. CohereEmbeddingFunction) or convert images to text (OCR/captions) first.
  3. Add a type guard that splits or filters non-str items before calling the function.

Example fix

# before
ef(['a caption', np.zeros((32, 32, 3), dtype=np.uint8)])  # ValueError: only text

# after
texts = [d for d in batch if isinstance(d, str)]
embs = ef(texts)  # images go to a separate, image-capable EF
Defensive patterns

Strategy: type-guard

Validate before calling

texts = [d for d in batch if isinstance(d, str)]
if len(texts) != len(batch):
    raise ValueError('Cloudflare EF accepts str documents only')

Type guard

def is_text_batch(batch: list) -> bool:
    return len(batch) > 0 and all(isinstance(d, str) for d in batch)

Try / catch

try:
    embs = ef(batch)
except ValueError as e:
    if 'only supports text documents' in str(e):
        batch = [d for d in batch if isinstance(d, str)]  # or route images to an image-capable EF
        embs = ef(batch)
    else:
        raise

Prevention

When it happens

Trigger: Calling a CloudflareWorkersAIEmbeddingFunction with any non-string element: ef([np.zeros((32, 32, 3), dtype=np.uint8)]), ef(['hello', pil_image]), or ef([b'bytes']).

Common situations: Reusing a multimodal ingestion pipeline built for Cohere (which accepts ndarray images) against the Cloudflare function; batches where an upstream loader yields PIL images, tensors, or bytes alongside text.

Related errors


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