{"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":127,"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":109,"sourceCodeEnd":138,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/EmbeddingEngines/gemini/index.js#L109-L138","documentation":"Thrown from GeminiEmbedder.embedChunks after the per-chunk embedding requests complete. The class fans chunks out (maxConcurrentChunks = 4) against Google's OpenAI-compatible endpoint, collects every distinct failure string into a Set, and throws with all of them joined by commas. The text after the colon is the real diagnosis: it is the raw error body returned by the Gemini endpoint.","triggerScenarios":"A revoked or wrong API key (401/403 API_KEY_INVALID); hitting project quota or rate limits (429 RESOURCE_EXHAUSTED) because 4 concurrent batch requests are in flight; EMBEDDING_MODEL_PREF set to a model that does not exist on generativelanguage.googleapis.com; a batch or single input exceeding the model's token/request limits; network egress blocked to googleapis.com.","commonSituations":"Embedding a large workspace for the first time and tripping Gemini free-tier quota; rotating an AI Studio key but not updating GEMINI_EMBEDDING_API_KEY; setting a preview/GA model name that is not available to the account; corporate proxies that block or MITM the Google API.","solutions":["Read the joined message after 'Gemini Failed to embed:' — each comma-separated entry maps to one failed chunk request","For 401/403 errors, verify GEMINI_EMBEDDING_API_KEY is active in Google AI Studio and regenerate it if revoked","For 429 RESOURCE_EXHAUSTED, wait for quota reset or request a quota increase, then re-embed the document","Verify EMBEDDING_MODEL_PREF is a real model id (default 'gemini-embedding-001')","If inputs are very large, lower EMBEDDING_MODEL_MAX_CHUNK_LENGTH so each request stays within model limits"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm the key can list models before embedding a whole workspace\nasync function geminiEmbedderReachable(openai) {\n  try {\n    await openai.models.list();\n    return true;\n  } catch (e) {\n    console.error(\"Gemini pre-flight failed:\", e.status, e.message);\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedTextInput(text);\n} catch (e) {\n  if (e.message.startsWith(\"Gemini Failed to embed:\")) {\n    const detail = e.message.slice(\"Gemini Failed to embed:\".length);\n    if (detail.includes(\"429\") || detail.includes(\"RESOURCE_EXHAUSTED\")) {\n      // back off and retry this document later — quota is time-windowed\n    } else if (detail.includes(\"401\") || detail.includes(\"API_KEY\")) {\n      // stop the batch: key is invalid, retrying cannot succeed\n    }\n  } else throw e;\n}","preventionTips":["Wrap per-document embedding so one failed document doesn't kill a workspace-wide embed job","Log the full joined message — it contains every distinct upstream error, not just the first","For large workspaces, embed during off-peak quota windows or request quota increases up front"],"tags":["gemini","embeddings","api-error","rate-limit","quota","openai-compat"],"backgroundTag":"embedding-api-request-failed","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}