{"record":{"id":"17a3c83851b3a267","repo":"Mintplex-Labs/anything-llm","slug":"gemini-failed-to-embed-error","errorCode":null,"errorMessage":"Gemini Failed to embed: ${error}","messagePattern":"Gemini Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/gemini/index.js","lineNumber":126,"sourceCode":"        .flat();\n      if (errors.length > 0) {\n        let uniqueErrors = new Set();\n        errors.map((error) =>\n          uniqueErrors.add(`[${error.type}]: ${error.message}`)\n        );\n\n        return {\n          data: [],\n          error: Array.from(uniqueErrors).join(\", \"),\n        };\n      }\n      return {\n        data: results.map((res) => res?.data || []).flat(),\n        error: null,\n      };\n    });\n\n    if (!!error) throw new Error(`Gemini Failed to embed: ${error}`);\n    return data.length > 0 &&\n      data.every((embd) => embd.hasOwnProperty(\"embedding\"))\n      ? data.map((embd) => embd.embedding)\n      : null;\n  }\n}\n\nmodule.exports = {\n  GeminiEmbedder,\n};\n","sourceCodeStart":108,"sourceCodeEnd":137,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/gemini/index.js#L108-L137","documentation":"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.","triggerScenarios":"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.","commonSituations":"Free-tier quota exhausted during bulk embed; wrong model id; API key restricted to a different API; transient 503 from Google.","solutions":["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.","Lower concurrency (maxConcurrentChunks) and chunk size to fit quota and token limits.","Remove IP/referrer restrictions on the key for server-side use, or provision an unrestricted key.","Retry after the persistent cause is resolved; partial vectors are not returned."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight a small embed to validate key + quota before bulk\ntry {\n  await embedder.embedTextInput('ping');\n} catch (e) {\n  throw new Error(`Gemini embed preflight failed: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await embedder.embedChunks(chunks);\n} catch (e) {\n  const msg = e.message;\n  if (/quota|429|rate/i.test(msg)) reduceConcurrency();\n  else if (/api.key|permission|403/i.test(msg)) fixKey();\n  else if (/model/i.test(msg)) setEmbeddingModel('gemini-embedding-001');\n  else throw e;\n}","preventionTips":["Pre-flight a tiny embed before bulk runs.","Keep EMBEDDING_MODEL_PREF to gemini-embedding-001 (the only mapped model).","Reduce maxConcurrentChunks (default 4) to stay within Gemini free-tier quota."],"tags":["gemini","google","embeddings","rate-limit","quota","batch"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}