Mintplex-Labs/anything-llm · error · Error

Mistral returned empty embeddings for batch

Error message

Mistral returned empty embeddings for batch

What it means

Thrown inside embedChunks (line 30) when the Mistral embeddings response yielded zero vectors — i.e. response.data was empty/undefined so the mapped embeddings array has length 0. This is a defensive check after a successful HTTP call: Mistral returned 200 but no usable data, so the embedder refuses to return an incomplete result and the surrounding catch re-wraps it as 'Mistral Failed to embed'.

Source

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

  }

  async embedTextInput(textInput) {
    const result = await this.embedChunks(
      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 526360e320)

Solutions

  1. Verify EMBEDDING_MODEL_PREF is an embedding model (mistral-embed) and not a chat model
  2. Sanitize inputs to remove empty/whitespace-only strings before embedding
  3. Reproduce with a curl to api.mistral.ai/v1/embeddings with the same model and one known-good string
  4. If the model was deprecated, switch to a current Mistral embedding model id

Example fix

// before
EMBEDDING_MODEL_PREF=mistral-large-latest   // chat model, returns no embeddings

// after
EMBEDDING_MODEL_PREF=mistral-embed
Defensive patterns

Strategy: validation

Validate before calling

// drop empty inputs and assert the model is an embedder before bulk run
const cleanChunks = textChunks.filter(s => typeof s === 'string' && s.trim().length > 0);
if (cleanChunks.length === 0) throw new Error('No non-empty text to embed.');
if (!/embed/.test(process.env.EMBEDDING_MODEL_PREF || '')) {
  throw new Error('EMBEDDING_MODEL_PREF does not look like an embedding model.');
}

Type guard

function isEmptyEmbeddingsError(e) {
  return e instanceof Error && /empty embeddings/.test(e.message);
}

Try / catch

try {
  return await embedder.embedChunks(chunks);
} catch (e) {
  if (/empty embeddings for batch/.test(e.message)) {
    throw new Error('Mistral returned no vectors — check EMBEDDING_MODEL_PREF is an embedding model', { cause: e });
  }
  throw e;
}

Prevention

When it happens

Trigger: Thrown at server/utils/EmbeddingEngines/mistral/index.js:30 when the library encounters an invalid state.

Common situations: EMBEDDING_MODEL_PREF pointing at a chat model instead of an embedding model; an upstream filter dropping all inputs; using a model id that was deprecated/renamed on Mistral's side; passing a batch of empty/whitespace-only strings.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/432efb9586be3c27. Report an issue: GitHub.