Mintplex-Labs/anything-llm · error

Mistral Failed to embed

Error message

Mistral Failed to embed: ${error.message}

What it means

The catch-all thrown from MistralEmbedder.embedChunks: any failure of the embeddings.create call (or of the empty-batch guard, which is thrown inside the same try) is logged to console.error and re-thrown with the original error.message appended. The console line 'Failed to get embeddings from Mistral.' plus the message is the best diagnostic — it carries Mistral's own error text.

Solutions

  1. Check the server console — 'Failed to get embeddings from Mistral.' precedes the exact upstream message
  2. For 401/403, verify MISTRAL_API_KEY in console.mistral.ai and rotate if needed
  3. For 429, slow down or wait out the quota window, then re-embed remaining documents
  4. Confirm EMBEDDING_MODEL_PREF is 'mistral-embed' or another valid embedding model for your account
  5. Reduce batch pressure with EMBEDDING_MODEL_MAX_CHUNK_LENGTH if inputs are oversized
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: validate key + model with one cheap call before the real batch
async function mistralEmbedderHealthy(openai, model) {
  try {
    const res = await openai.embeddings.create({ model, input: ["ping"], encoding_format: "float" });
    return Array.isArray(res?.data?.[0]?.embedding);
  } catch (e) {
    console.error("Mistral pre-flight failed:", e.status, e.message);
    return false;
  }
}

Try / catch

try {
  const vectors = await embedder.embedTextInput(text);
} catch (e) {
  if (e.message.startsWith("Mistral Failed to embed:")) {
    const detail = e.message;
    if (/401|403/i.test(detail)) { /* invalid MISTRAL_API_KEY — stop the job, fix the key */ }
    else if (/429|quota/i.test(detail)) { /* rate-limited: exponential backoff, retry the batch */ }
    else if (/empty embeddings/i.test(detail)) { /* batch-content problem — see empty-batch guard */ }
    else throw e;
  } else throw e;
}

Prevention

When it happens

Trigger: 401/403 with an invalid or revoked MISTRAL_API_KEY; 429 after exceeding the Mistral free-tier/plan rate limits during bulk embedding; 404/400 when EMBEDDING_MODEL_PREF is not a valid model id; batch exceeding Mistral's input limits (too many items or tokens per request); network/TLS failures reaching api.mistral.ai; the wrapped 'Mistral returned empty embeddings for batch' case.

Common situations: Bulk re-embedding a large workspace and hitting Mistral's per-minute quotas; keys rotated in the console but not updated in env; a typo'd model name that only fails at embed time (the constructor does not validate it).

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/b15be9607dc858aa. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/EmbeddingEngines/mistral/index.js:34

      Array.isArray(textInput) ? textInput : [textInput]
    );
    return result?.[0] || [];
  }

  async embedChunks(textChunks = []) {
    try {
      const response = await this.openai.embeddings.create({
        model: this.model,
        input: textChunks,
        encoding_format: "float",
      });
      const embeddings = response?.data?.map((emb) => emb.embedding) || [];
      if (embeddings.length === 0)
        throw new Error("Mistral returned empty embeddings for batch");
      return embeddings;
    } catch (error) {
      console.error("Failed to get embeddings from Mistral.", error.message);
      throw new Error(`Mistral Failed to embed: ${error.message}`);
    }
  }
}

module.exports = {
  MistralEmbedder,
};

View on GitHub (pinned to 3aec848f28)