Mintplex-Labs/anything-llm · error
Mistral Failed to embed
Error message
Mistral Failed to embed: ${error} What it means
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).
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.
Defensive patterns
Strategy: retry
Validate before calling
if (!process.env.MISTRAL_API_KEY) throw new Error('MISTRAL_API_KEY is not set');
// keep chunks well under the token limit
const safeChunks = chunks.filter(c => c.length <= 8000); Try / catch
async function embedWithRetry(chunks, attempts = 3) {
for (let i = 0; i < attempts; i++) {
try { return await mistralEmbedder.embedChunks(chunks); }
catch (e) {
if (/429|rate/i.test(e.message) && i < attempts - 1) {
await new Promise(r => setTimeout(r, 2 ** i * 1000)); continue;
}
throw e;
}
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AnthropicLLM::getChatCompletion failed to communicate with…
- Cannot create: maximum of
- e.message
- An error occurred while deleting the model
- Bad Request
AI-assisted analysis of Mintplex-Labs/anything-llm@f92433b4ea (2026-09-22).
Data as JSON: /api/errors/436f4f38bebb7479.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/EmbeddingEngines/mistral/index.js:117
).then((results) => {
const errors = results
.filter((res) => !!res.error)
.map((res) => res.error)
.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(`Mistral Failed to embed: ${error}`);
// Throw rather than return null so a document is never silently embedded with empty vectors (#5513).
const embeddings = data.map((emb) => emb.embedding);
if (embeddings.length === 0)
throw new Error("Mistral returned empty embeddings for batch");
return embeddings;
}
}
module.exports = {
MistralEmbedder,
};
View on GitHub (pinned to f92433b4ea)