Mintplex-Labs/anything-llm · error · Error
LMStudio Failed to embed: ${Array.from(uniqueErrors).join(",
Error message
LMStudio Failed to embed: ${Array.from(uniqueErrors).join(", ")} What it means
Thrown at the end of embedChunks (line 110) when at least one per-chunk embedding request failed. Because LMStudio drops concurrent requests, embedChunks processes sequentially; on the first error hasError is set and the loop breaks. Errors are collected, deduplicated into [type]: message strings, and the whole batch is aborted since partial data would be incomplete. error.type comes from response.data.error.code, HTTP status, or 'failed_to_embed'; a missing embedding array yields type 'EMPTY_ARR'.
Source
Thrown at server/utils/EmbeddingEngines/lmstudio/index.js:110
);
}
// Accumulate errors from embedding.
// If any are present throw an abort error.
const errors = results
.filter((res) => !!res.error)
.map((res) => res.error)
.flat();
if (errors.length > 0) {
let uniqueErrors = new Set();
console.log(errors);
errors.map((error) =>
uniqueErrors.add(`[${error.type}]: ${error.message}`)
);
if (errors.length > 0)
throw new Error(
`LMStudio Failed to embed: ${Array.from(uniqueErrors).join(", ")}`
);
}
const data = results.map((res) => res?.data || []);
return data.length > 0 ? data : null;
}
}
module.exports = {
LMStudioEmbedder,
};
View on GitHub (pinned to 526360e320)
Solutions
- Match the [type] prefix: EMPTY_ARR means the model returned no vector (verify the loaded model is an embedding model, not a chat model); an HTTP status means check LMStudio logs for that request
- curl the LMStudio /v1/embeddings endpoint with the exact model and a sample chunk to reproduce
- Lower the document chunk size so no chunk exceeds the embedding model's max context
- Ensure no other process is restarting/unloading the LMStudio model mid-batch
Example fix
// before EMBEDDING_MODEL_PREF=some-chat-model // not an embedding model -> EMPTY_ARR // after EMBEDDING_MODEL_PREF=nomic-ai/nomic-embed-text-v1.5
Defensive patterns
Strategy: try-catch
Validate before calling
// confirm the model returns vectors before the bulk run
async function lmstudioEmbeds(openai, model, sample = 'hello') {
const r = await openai.embeddings.create({ model, input: sample, encoding_format: 'base64' });
return Array.isArray(r.data?.[0]?.embedding) && r.data[0].embedding.length > 0;
} Type guard
function isLMStudioEmbedError(e) {
return e instanceof Error && /LMStudio Failed to embed/.test(e.message);
} Try / catch
try {
return await embedder.embedChunks(chunks);
} catch (e) {
if (/EMPTY_ARR/.test(e.message)) {
throw new Error('Loaded LMStudio model is not an embedding model', { cause: e });
}
throw e;
} Prevention
- Load an actual embedding model in LMStudio, not a chat model.
- Keep chunks within the embedding model's context window.
- Avoid mid-batch model swaps while a job runs.
When it happens
Trigger: A sequential embeddings.create call rejecting: LMStudio returns 404/500 for the model name; the response.data[0].embedding is missing/empty (throws {type:'EMPTY_ARR'} inline at line 76); context length exceeded for the chunk; LMStudio crashed mid-batch; encoding_format base64 not supported by the loaded model.
Common situations: EMBEDDING_MODEL_PREF does not match the loaded model identifier; chunk too long for the embedding model's context; LMStudio OOM or model swap mid-run; LMStudio version that mishandles base64 encoding_format; concurrent AnythingLLM jobs hitting the single-threaded LMStudio server.
Related errors
- LiteLLM Failed to embed: ${error}
- LMStudio service could not be reached. Is LMStudio running?
- LocalAI Failed to embed: ${error}
- Ollama Failed to embed: ${error}
- OpenAI Failed to embed: ${error}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/88ecd3f8bf9e205b.
Report an issue: GitHub.