chroma-core/chroma · error · ValueError

Failed to generate embeddings: {str(e)}

Error message

Failed to generate embeddings: {str(e)}

What it means

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.

Source

Thrown at chromadb/utils/embedding_functions/google_embedding_function.py:110

            raise ValueError("Input must be a list or tuple of documents")
        if not all(isinstance(doc, str) for doc in input):
            raise ValueError("All input documents must be strings")

        from google.genai.types import EmbedContentConfig

        config = EmbedContentConfig(
            task_type=self.task_type,
            output_dimensionality=self.dimension,
        )

        try:
            response = self.client.models.embed_content(
                model=self.model_name,
                contents=input,
                config=config,
            )
        except Exception as e:
            raise ValueError(f"Failed to generate embeddings: {str(e)}") from e

        # Validate response structure
        if not hasattr(response, "embeddings") or not response.embeddings:
            raise ValueError("No embeddings returned from the API")

        embeddings_list = []
        for ce in response.embeddings:
            if not hasattr(ce, "values"):
                raise ValueError("Malformed embedding response: missing 'values'")
            embeddings_list.append(np.array(ce.values, dtype=np.float32))

        return cast(Embeddings, embeddings_list)

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

    def default_space(self) -> Space:

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. 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
  2. For 400: correct model_name and ensure dimension is within 128-3072 or leave it None
  3. For 429: retry with exponential backoff and reduce batch size / add quota headroom
  4. For 401/403: verify the API key or Vertex credentials
  5. For 5xx/network: retry with backoff; check proxy/firewall reachability of generativelanguage.googleapis.com

Example fix

# before
ef = GoogleGeminiEmbeddingFunction()
vecs = ef(docs)  # ValueError: Failed to generate embeddings: 429 RESOURCE_EXHAUSTED ...

# after - bounded retry with backoff for transient (429/5xx) failures
import time

def embed_with_retry(ef, docs, attempts=5):
    for i in range(attempts):
        try:
            return ef(docs)
        except ValueError as e:
            msg = str(e)
            if "429" in msg or "500" in msg or "503" in msg:
                time.sleep(2 ** i)
                continue
            raise
    raise RuntimeError("embedding retries exhausted")
Defensive patterns

Strategy: retry

Validate before calling

import os

assert 128 <= int(os.getenv("EMBED_DIM", "3072")) <= 3072, "dimension must be 128-3072"
assert ef.model_name == "gemini-embedding-001", "unexpected model name"
assert os.getenv(ef.api_key_env_var), "API key missing"

Try / catch

import time

def embed_with_retry(ef, docs, attempts=5, base=1.0):
    last = None
    for i in range(attempts):
        try:
            return ef(docs)
        except ValueError as e:
            last = e
            msg = str(e)
            transient = any(code in msg for code in ("429", "500", "503", "timeout", "unavailable"))
            if not transient or i == attempts - 1:
                raise  # permanent (400/401/403) or retries exhausted
            time.sleep(base * 2 ** i)
    raise last

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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