{"record":{"id":"ef47415af1d55317","repo":"chroma-core/chroma","slug":"cloudflare-workers-ai-only-supports-text-documents","errorCode":null,"errorMessage":"Cloudflare Workers AI only supports text documents, not images","messagePattern":"Cloudflare Workers AI only supports text documents, not images","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py","lineNumber":91,"sourceCode":"            self._api_url = f\"{BASE_URL}/{self.account_id}/ai/run/{self.model_name}\"\n\n        self._session = httpx.Client()\n        self._session.headers.update(\n            {\"Authorization\": f\"Bearer {self.api_key}\", \"Accept-Encoding\": \"identity\"}\n        )\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n\n        Args:\n            input: Documents to generate embeddings for.\n\n        Returns:\n            Embeddings for the documents.\n        \"\"\"\n        if not all(isinstance(item, str) for item in input):\n            raise ValueError(\n                \"Cloudflare Workers AI only supports text documents, not images\"\n            )\n\n        payload: Dict[str, Any] = {\n            \"text\": input,\n        }\n\n        resp = self._session.post(self._api_url, json=payload).json()\n\n        if \"result\" not in resp and \"data\" not in resp[\"result\"]:\n            raise RuntimeError(resp.get(\"detail\", \"Unknown error\"))\n\n        return cast(Embeddings, resp[\"result\"][\"data\"])\n\n    @staticmethod\n    def name() -> str:\n        return \"cloudflare_workers_ai\"\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/cloudflare_workers_ai_embedding_function.py#L73-L109","documentation":"__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.","triggerScenarios":"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']).","commonSituations":"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.","solutions":["Send only str documents to CloudflareWorkersAIEmbeddingFunction.","For images, switch to an image-capable function (e.g. CohereEmbeddingFunction) or convert images to text (OCR/captions) first.","Add a type guard that splits or filters non-str items before calling the function."],"exampleFix":"# before\nef(['a caption', np.zeros((32, 32, 3), dtype=np.uint8)])  # ValueError: only text\n\n# after\ntexts = [d for d in batch if isinstance(d, str)]\nembs = ef(texts)  # images go to a separate, image-capable EF","handlingStrategy":"type-guard","validationCode":"texts = [d for d in batch if isinstance(d, str)]\nif len(texts) != len(batch):\n    raise ValueError('Cloudflare EF accepts str documents only')","typeGuard":"def is_text_batch(batch: list) -> bool:\n    return len(batch) > 0 and all(isinstance(d, str) for d in batch)","tryCatchPattern":"try:\n    embs = ef(batch)\nexcept ValueError as e:\n    if 'only supports text documents' in str(e):\n        batch = [d for d in batch if isinstance(d, str)]  # or route images to an image-capable EF\n        embs = ef(batch)\n    else:\n        raise","preventionTips":["Keep Cloudflare batches homogeneous strings; route images to an image-capable EF.","Assert element types in the ingestion loader before batching.","Document per-provider input contracts in your pipeline (Cloudflare: text-only)."],"tags":["chroma","cloudflare","multimodal","input-validation","embedding-function"],"backgroundTag":"invalid-input-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}