{"record":{"id":"f4b433b98060a502","repo":"chroma-core/chroma","slug":"input-must-be-a-list-or-tuple-of-documents","errorCode":null,"errorMessage":"Input must be a list or tuple of documents","messagePattern":"Input must be a list or tuple of documents","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":92,"sourceCode":"            http_options=types.HttpOptions(\n                headers={\"x-goog-api-client\": f\"chroma/{__version__}\"}\n            ),\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 input:\n            raise ValueError(\"Input documents cannot be empty\")\n        if not isinstance(input, (list, tuple)):\n            raise ValueError(\"Input must be a list or tuple of documents\")\n        if not all(isinstance(doc, str) for doc in input):\n            raise ValueError(\"All input documents must be strings\")\n\n        from google.genai.types import EmbedContentConfig\n\n        config = EmbedContentConfig(\n            task_type=self.task_type,\n            output_dimensionality=self.dimension,\n        )\n\n        try:\n            response = self.client.models.embed_content(\n                model=self.model_name,\n                contents=input,\n                config=config,\n            )\n        except Exception as e:\n            raise ValueError(f\"Failed to generate embeddings: {str(e)}\") from e","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L74-L110","documentation":"GoogleGeminiEmbeddingFunction.__call__ requires the input container itself to be a list or tuple. Generators, numpy arrays, pandas Series, and even a bare Python string all fail this isinstance check - a bare str is deliberately not accepted because it would be ambiguous (one document vs a sequence of characters).","triggerScenarios":"Passing a generator expression (ef((d for d in docs))); a numpy array of strings (df['text'].values); a pandas Series; a single document as ef('hello') instead of ef(['hello']); any custom iterable that is not list/tuple.","commonSituations":"Data-science pipelines handing df['text'].values straight to the embedding function; map()/filter() results passed without materialization; single-document code paths that forget to wrap the string in a list.","solutions":["Materialize iterables: ef(list(docs))","Wrap single documents in a list: ef(['hello'])","Convert numpy arrays with .tolist() and pandas Series with .tolist() or list(series)"],"exampleFix":"# before\nef = GoogleGeminiEmbeddingFunction()\nvecs = ef(df['text'].values)      # numpy array -> ValueError\nvecs = ef('single document')      # bare str -> ValueError\n\n# after\nvecs = ef(df['text'].tolist())\nvecs = ef(['single document'])","handlingStrategy":"type-guard","validationCode":"docs = list(docs)  # materialize generators/arrays/Series before embedding\nvecs = ef(docs)","typeGuard":"from typing import Any, TypeGuard\n\ndef is_document_list(docs: Any) -> TypeGuard[list[str]]:\n    return isinstance(docs, (list, tuple)) and all(isinstance(d, str) for d in docs)\n\nif is_document_list(docs):\n    vecs = ef(docs)  # narrowed and safe\nelse:\n    docs = list(docs) if not isinstance(docs, str) else [docs]\n    vecs = ef(docs)","tryCatchPattern":null,"preventionTips":["Convert numpy arrays / pandas Series with .tolist() before embedding","Wrap single documents in a list: ef(['doc'])","Standardize on List[str] at API boundaries via type annotations"],"tags":["gemini","input-validation","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"}