{"record":{"id":"b15be9607dc858aa","repo":"Mintplex-Labs/anything-llm","slug":"mistral-failed-to-embed-error-message","errorCode":null,"errorMessage":"Mistral Failed to embed: ${error.message}","messagePattern":"Mistral Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/mistral/index.js","lineNumber":34,"sourceCode":"      Array.isArray(textInput) ? textInput : [textInput]\n    );\n    return result?.[0] || [];\n  }\n\n  async embedChunks(textChunks = []) {\n    try {\n      const response = await this.openai.embeddings.create({\n        model: this.model,\n        input: textChunks,\n        encoding_format: \"float\",\n      });\n      const embeddings = response?.data?.map((emb) => emb.embedding) || [];\n      if (embeddings.length === 0)\n        throw new Error(\"Mistral returned empty embeddings for batch\");\n      return embeddings;\n    } catch (error) {\n      console.error(\"Failed to get embeddings from Mistral.\", error.message);\n      throw new Error(`Mistral Failed to embed: ${error.message}`);\n    }\n  }\n}\n\nmodule.exports = {\n  MistralEmbedder,\n};\n","sourceCodeStart":16,"sourceCodeEnd":42,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/mistral/index.js#L16-L42","documentation":"Thrown in the embedChunks catch block wrapping the entire embeddings.create call. Any rejection — network error, non-2xx HTTP, the explicit 'empty embeddings' throw above, or an SDK parse failure — is caught, logged to console.error, and re-thrown as 'Mistral Failed to embed: <original message>'. It is the single escape hatch for all Mistral embedding failures.","triggerScenarios":"embeddings.create rejects: 401 (bad/expired MISTRAL_API_KEY); 429 rate limit; 5xx Mistral outage; the inner 'Mistral returned empty embeddings for batch' throw; network timeout; SDK unable to parse a non-JSON gateway response.","commonSituations":"Key expired or revoked; hitting Mistral rate limits on a large batch; transient 5xx; running behind a corporate proxy that returns an HTML error page; deprecated model returning an API error.","solutions":["Read error.message in the thrown string: 401 -> rotate/fix MISTRAL_API_KEY; 429 -> reduce batch size / add backoff; 5xx -> retry after a short delay","If the message is 'empty embeddings for batch', follow error 330 fixes (check EMBEDDING_MODEL_PREF is an embedding model)","curl api.mistral.ai/v1/embeddings directly to isolate SDK vs network vs provider","Add retry with exponential backoff in the caller for transient 5xx/429"],"exampleFix":"// before\n// caller does no retry, single 429 aborts the whole doc ingest\n\n// after\n// wrap the embed call with a bounded retry on transient errors\nfor (let attempt = 0; attempt < 3; attempt++) {\n  try { return await embedder.embedChunks(chunks); }\n  catch (e) {\n    if (attempt === 2 || /401|empty embeddings/.test(e.message)) throw e;\n  }\n}","handlingStrategy":"retry","validationCode":"// pre-flight: key valid and not rate-limited on a tiny call\nasync function mistralReachable(openai, model) {\n  await openai.embeddings.create({ model, input: 'ping' });\n}","typeGuard":"function isMistralEmbedError(e) {\n  return e instanceof Error && /Mistral Failed to embed/.test(e.message);\n}","tryCatchPattern":"async function embedWithRetry(embedder, chunks, attempts = 3) {\n  for (let i = 0; i < attempts; i++) {\n    try { return await embedder.embedChunks(chunks); }\n    catch (e) {\n      const transient = /429|5\\d\\d|Failed to fetch|ETIMEDOUT/.test(e.message);\n      if (!transient || i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, 2 ** i * 1000));\n    }\n  }\n}","preventionTips":["Add exponential backoff in the caller for 429/5xx.","Keep batches within Mistral's per-request token limits.","Rotate expired keys promptly."],"tags":["mistral","embedding","runtime","auth","rate-limit"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}