{"record":{"id":"cb6a5d0a61ae09f7","repo":"chroma-core/chroma","slug":"google-generative-ai-only-supports-text-documents","errorCode":null,"errorMessage":"Google Generative AI only supports text documents, not images","messagePattern":"Google Generative AI only supports text documents, not images","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":283,"sourceCode":"\n        genai.configure(\n            api_key=self.api_key,\n            client_options={\"headers\": {\"x-goog-api-client\": f\"chroma/{__version__}\"}},\n        )\n        self._genai = genai\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                \"Google Generative AI only supports text documents, not images\"\n            )\n\n        embeddings_list: List[npt.NDArray[np.float32]] = []\n        for text in input:\n            kwargs: Dict[str, Any] = {\n                \"model\": self.model_name,\n                \"content\": text,\n                \"task_type\": self.task_type,\n            }\n            if self.dimension is not None:\n                kwargs[\"output_dimensionality\"] = self.dimension\n            embedding_result = self._genai.embed_content(**kwargs)\n            embeddings_list.append(\n                np.array(embedding_result[\"embedding\"], dtype=np.float32)\n            )\n\n        return cast(Embeddings, embeddings_list)","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L265-L301","documentation":"The legacy GoogleGenerativeAiEmbeddingFunction.__call__ verifies every input element is a str before calling genai.embed_content. The Gemini text-embedding API it wraps has no image input, so any non-string entry (image bytes, PIL objects, None, ints) is rejected up front.","triggerScenarios":"Passing document lists containing bytes (e.g. image file contents), None from missing fields, or numbers; attempting multimodal retrieval with this text-only function.","commonSituations":"Building image search and reusing the text embedding function; DataFrame columns with NaN/None; JSON documents with null content fields.","solutions":["Filter or coerce inputs to strings before calling: [d for d in docs if isinstance(d, str)]","For image/multimodal workloads use a multimodal embedding function (e.g. a CLIP-based one) instead","Sanitize upstream data so missing content never reaches the embedding function"],"exampleFix":"# before\nvecs = ef([\"a cat photo\", open('cat.jpg', 'rb').read()])  # ValueError: only supports text documents\n\n# after\ntexts = [d for d in docs if isinstance(d, str)]\nvecs = ef(texts)  # embed images with a separate multimodal embedding function","handlingStrategy":"type-guard","validationCode":"texts = [d for d in docs if isinstance(d, str)]\nif not texts:\n    raise ValueError(\"no text documents to embed\")\nvecs = ef(texts)","typeGuard":"from typing import Any, Iterable, TypeGuard\n\ndef is_text_only(docs: Any) -> TypeGuard[list[str]]:\n    return isinstance(docs, (list, tuple)) and all(isinstance(d, str) for d in docs)\n\nif is_text_only(docs):\n    vecs = ef(docs)\nelse:\n    texts = [d for d in docs if isinstance(d, str)]\n    vecs = ef(texts)  # route images to a multimodal embedding function separately","tryCatchPattern":null,"preventionTips":["Use a text-only embedding function exclusively for str documents; pick a multimodal EF for images","Sanitize sources (fillna, drop nulls) so non-strings never reach the EF","Add isinstance checks at ingestion boundaries where mixed media arrives"],"tags":["google-generativeai","input-validation","multimodal","type-error","chroma"],"backgroundTag":"invalid-input-type","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}