{"record":{"id":"432efb9586be3c27","repo":"Mintplex-Labs/anything-llm","slug":"mistral-returned-empty-embeddings-for-batch","errorCode":null,"errorMessage":"Mistral returned empty embeddings for batch","messagePattern":"Mistral returned empty embeddings for batch","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/mistral/index.js","lineNumber":30,"sourceCode":"  }\n\n  async embedTextInput(textInput) {\n    const result = await this.embedChunks(\n      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":12,"sourceCodeEnd":42,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/mistral/index.js#L12-L42","documentation":"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'.","triggerScenarios":"Thrown at server/utils/EmbeddingEngines/mistral/index.js:30 when the library encounters an invalid state.","commonSituations":"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.","solutions":["Verify EMBEDDING_MODEL_PREF is an embedding model (mistral-embed) and not a chat model","Sanitize inputs to remove empty/whitespace-only strings before embedding","Reproduce with a curl to api.mistral.ai/v1/embeddings with the same model and one known-good string","If the model was deprecated, switch to a current Mistral embedding model id"],"exampleFix":"// before\nEMBEDDING_MODEL_PREF=mistral-large-latest   // chat model, returns no embeddings\n\n// after\nEMBEDDING_MODEL_PREF=mistral-embed","handlingStrategy":"validation","validationCode":"// drop empty inputs and assert the model is an embedder before bulk run\nconst cleanChunks = textChunks.filter(s => typeof s === 'string' && s.trim().length > 0);\nif (cleanChunks.length === 0) throw new Error('No non-empty text to embed.');\nif (!/embed/.test(process.env.EMBEDDING_MODEL_PREF || '')) {\n  throw new Error('EMBEDDING_MODEL_PREF does not look like an embedding model.');\n}","typeGuard":"function isEmptyEmbeddingsError(e) {\n  return e instanceof Error && /empty embeddings/.test(e.message);\n}","tryCatchPattern":"try {\n  return await embedder.embedChunks(chunks);\n} catch (e) {\n  if (/empty embeddings for batch/.test(e.message)) {\n    throw new Error('Mistral returned no vectors — check EMBEDDING_MODEL_PREF is an embedding model', { cause: e });\n  }\n  throw e;\n}","preventionTips":["Only set EMBEDDING_MODEL_PREF to a real Mistral embedding model (mistral-embed).","Filter empty/whitespace chunks before embedding.","Watch Mistral deprecation notices for renamed model ids."],"tags":["mistral","embedding","runtime","data-validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}