Mintplex-Labs/anything-llm · error · Error

Gemini Failed to embed: ${error}

Error message

Gemini Failed to embed: ${error}

What it means

Thrown after the embedding batches settle if any returned an error. Gemini per-batch errors are collected into a uniqueErrors set and joined into 'Gemini Failed to embed: <errors>'. Any failed batch aborts the whole call and returns no vectors.

Source

Thrown at server/utils/EmbeddingEngines/gemini/index.js:126

        .flat();
      if (errors.length > 0) {
        let uniqueErrors = new Set();
        errors.map((error) =>
          uniqueErrors.add(`[${error.type}]: ${error.message}`)
        );

        return {
          data: [],
          error: Array.from(uniqueErrors).join(", "),
        };
      }
      return {
        data: results.map((res) => res?.data || []).flat(),
        error: null,
      };
    });

    if (!!error) throw new Error(`Gemini Failed to embed: ${error}`);
    return data.length > 0 &&
      data.every((embd) => embd.hasOwnProperty("embedding"))
      ? data.map((embd) => embd.embedding)
      : null;
  }
}

module.exports = {
  GeminiEmbedder,
};

View on GitHub (pinned to 526360e320)

Solutions

  1. Read the joined errors: quota -> wait/upgrade or reduce maxConcurrentChunks (default 4); auth -> fix/restrict the key; model -> set EMBEDDING_MODEL_PREF to gemini-embedding-001.
  2. Lower concurrency (maxConcurrentChunks) and chunk size to fit quota and token limits.
  3. Remove IP/referrer restrictions on the key for server-side use, or provision an unrestricted key.
  4. Retry after the persistent cause is resolved; partial vectors are not returned.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight a small embed to validate key + quota before bulk
try {
  await embedder.embedTextInput('ping');
} catch (e) {
  throw new Error(`Gemini embed preflight failed: ${e.message}`);
}

Try / catch

try {
  await embedder.embedChunks(chunks);
} catch (e) {
  const msg = e.message;
  if (/quota|429|rate/i.test(msg)) reduceConcurrency();
  else if (/api.key|permission|403/i.test(msg)) fixKey();
  else if (/model/i.test(msg)) setEmbeddingModel('gemini-embedding-001');
  else throw e;
}

Prevention

When it happens

Trigger: Invalid/restricted GEMINI_EMBEDDING_API_KEY; 429 quota exceeded on the embedding endpoint; EMBEDDING_MODEL_PREF set to a model not in MODEL_MAP (only 'gemini-embedding-001' is mapped) or unsupported for embeddings; chunks exceeding the model token limit; partial network failures.

Common situations: Free-tier quota exhausted during bulk embed; wrong model id; API key restricted to a different API; transient 503 from Google.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/17a3c83851b3a267. Report an issue: GitHub.