{"record":{"id":"436f4f38bebb7479","repo":"Mintplex-Labs/anything-llm","slug":"mistral-failed-to-embed-error","errorCode":null,"errorMessage":"Mistral Failed to embed: ${error}","messagePattern":"Mistral Failed to embed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/mistral/index.js","lineNumber":117,"sourceCode":"    ).then((results) => {\n      const errors = results\n        .filter((res) => !!res.error)\n        .map((res) => res.error)\n        .flat();\n      if (errors.length > 0) {\n        let uniqueErrors = new Set();\n        errors.map((error) =>\n          uniqueErrors.add(`[${error.type}]: ${error.message}`)\n        );\n        return { data: [], error: Array.from(uniqueErrors).join(\", \") };\n      }\n      return {\n        data: results.map((res) => res?.data || []).flat(),\n        error: null,\n      };\n    });\n\n    if (!!error) throw new Error(`Mistral Failed to embed: ${error}`);\n\n    // Throw rather than return null so a document is never silently embedded with empty vectors (#5513).\n    const embeddings = data.map((emb) => emb.embedding);\n    if (embeddings.length === 0)\n      throw new Error(\"Mistral returned empty embeddings for batch\");\n    return embeddings;\n  }\n}\n\nmodule.exports = {\n  MistralEmbedder,\n};\n","sourceCodeStart":99,"sourceCodeEnd":130,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/f92433b4ea0598492a1e6645ea22addbb4dd1287/server/utils/EmbeddingEngines/mistral/index.js#L99-L130","documentation":"Mistral's embedChunks throws when the Mistral embeddings API batch call reports an error. It wraps the SDK/API error so callers get a single clear message that a document batch could not be embedded. Separately, empty embedding results also throw to prevent silently storing empty vectors (issue #5513).","triggerScenarios":"Calling embedChunks when the Mistral API key is invalid/missing, the batch exceeds rate or size limits, the model name is wrong, or the network call to Mistral fails.","commonSituations":"Expired or missing MISTRAL_API_KEY; embedding very large chunks exceeding the API's token limit; rate limiting on high-volume ingestion; transient network failures during document upload.","solutions":["Read the wrapped ${error} in the message for the root cause (401 vs 429 vs network).","Verify the MISTRAL_API_KEY env var is set and valid.","Reduce chunk size / batch size and retry, especially on 429 rate-limit errors.","Confirm the embedding model name matches a valid Mistral embedding model.","Retry transient failures with backoff before re-uploading the document."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (!process.env.MISTRAL_API_KEY) throw new Error('MISTRAL_API_KEY is not set');\n// keep chunks well under the token limit\nconst safeChunks = chunks.filter(c => c.length <= 8000);","typeGuard":null,"tryCatchPattern":"async function embedWithRetry(chunks, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await mistralEmbedder.embedChunks(chunks); }\n    catch (e) {\n      if (/429|rate/i.test(e.message) && i < attempts - 1) {\n        await new Promise(r => setTimeout(r, 2 ** i * 1000)); continue;\n      }\n      throw e;\n    }\n  }\n}","preventionTips":["Validate the Mistral API key before ingestion runs.","Throttle batch volume to avoid 429 rate limits.","Keep chunk sizes within the embedding model's token limit.","Log the wrapped inner error to distinguish auth vs rate vs network causes."],"tags":["embedding","api","network","rate-limit"],"backgroundTag":"api-error-response","analyzedSha":"f92433b4ea0598492a1e6645ea22addbb4dd1287","analyzedAt":"2026-09-22T02:13:38.154Z","contentChangedAt":"2026-09-22T02:13:38.154Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}