{"record":{"id":"75572a358e57c046","repo":"chroma-core/chroma","slug":"failed-to-generate-embeddings-str-e","errorCode":null,"errorMessage":"Failed to generate embeddings: {str(e)}","messagePattern":"Failed to generate embeddings: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":110,"sourceCode":"            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\n\n        # Validate response structure\n        if not hasattr(response, \"embeddings\") or not response.embeddings:\n            raise ValueError(\"No embeddings returned from the API\")\n\n        embeddings_list = []\n        for ce in response.embeddings:\n            if not hasattr(ce, \"values\"):\n                raise ValueError(\"Malformed embedding response: missing 'values'\")\n            embeddings_list.append(np.array(ce.values, dtype=np.float32))\n\n        return cast(Embeddings, embeddings_list)\n\n    @staticmethod\n    def name() -> str:\n        return \"google_gemini\"\n\n    def default_space(self) -> Space:","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L92-L128","documentation":"GoogleGeminiEmbeddingFunction.__call__ wraps every exception raised by client.models.embed_content into this ValueError, preserving the original message and __cause__. The underlying failure is a Google API error: bad model name, invalid dimension (outside 128-3072), auth failure (401/403), rate limit (429), server error (5xx), or network unreachability. Read the embedded message to identify which one.","triggerScenarios":"model_name typo like 'gemini-embedding-001 ' or a deprecated model; dimension=64 or dimension=4096 outside the supported 128-3072 range; invalid/revoked API key; quota exhausted during a large batch ingestion; transient 5xx or DNS/proxy failure in restricted networks; Vertex project without the Generative Language API enabled.","commonSituations":"Bulk ingestion hitting Gemini free-tier rate limits; corporate egress proxies blocking googleapis.com; rotating a deleted API key; switching model versions without updating dimension; intermittent failures that succeed on retry.","solutions":["Inspect the full message and exc.__cause__ - it contains the Google error code (400 vs 401/403 vs 429 vs 500) that determines the fix","For 400: correct model_name and ensure dimension is within 128-3072 or leave it None","For 429: retry with exponential backoff and reduce batch size / add quota headroom","For 401/403: verify the API key or Vertex credentials","For 5xx/network: retry with backoff; check proxy/firewall reachability of generativelanguage.googleapis.com"],"exampleFix":"# before\nef = GoogleGeminiEmbeddingFunction()\nvecs = ef(docs)  # ValueError: Failed to generate embeddings: 429 RESOURCE_EXHAUSTED ...\n\n# after - bounded retry with backoff for transient (429/5xx) failures\nimport time\n\ndef embed_with_retry(ef, docs, attempts=5):\n    for i in range(attempts):\n        try:\n            return ef(docs)\n        except ValueError as e:\n            msg = str(e)\n            if \"429\" in msg or \"500\" in msg or \"503\" in msg:\n                time.sleep(2 ** i)\n                continue\n            raise\n    raise RuntimeError(\"embedding retries exhausted\")","handlingStrategy":"retry","validationCode":"import os\n\nassert 128 <= int(os.getenv(\"EMBED_DIM\", \"3072\")) <= 3072, \"dimension must be 128-3072\"\nassert ef.model_name == \"gemini-embedding-001\", \"unexpected model name\"\nassert os.getenv(ef.api_key_env_var), \"API key missing\"","typeGuard":null,"tryCatchPattern":"import time\n\ndef embed_with_retry(ef, docs, attempts=5, base=1.0):\n    last = None\n    for i in range(attempts):\n        try:\n            return ef(docs)\n        except ValueError as e:\n            last = e\n            msg = str(e)\n            transient = any(code in msg for code in (\"429\", \"500\", \"503\", \"timeout\", \"unavailable\"))\n            if not transient or i == attempts - 1:\n                raise  # permanent (400/401/403) or retries exhausted\n            time.sleep(base * 2 ** i)\n    raise last","preventionTips":["Read the wrapped message and __cause__ first - 400s are config bugs, only 429/5xx are retryable","Keep dimension within 128-3072 or leave it None","Throttle ingestion batches and add exponential backoff to survive quota limits","Verify API-key validity and API enablement before bulk runs"],"tags":["gemini","api-error","rate-limit","network","google-genai","chroma"],"backgroundTag":"embedding-api-request-failed","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}