{"record":{"id":"88ecd3f8bf9e205b","repo":"Mintplex-Labs/anything-llm","slug":"lmstudio-failed-to-embed-array-from-uniqueerror","errorCode":null,"errorMessage":"LMStudio Failed to embed: ${Array.from(uniqueErrors).join(\", \")}","messagePattern":"LMStudio Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/lmstudio/index.js","lineNumber":110,"sourceCode":"      );\n    }\n\n    // Accumulate errors from embedding.\n    // If any are present throw an abort error.\n    const errors = results\n      .filter((res) => !!res.error)\n      .map((res) => res.error)\n      .flat();\n\n    if (errors.length > 0) {\n      let uniqueErrors = new Set();\n      console.log(errors);\n      errors.map((error) =>\n        uniqueErrors.add(`[${error.type}]: ${error.message}`)\n      );\n\n      if (errors.length > 0)\n        throw new Error(\n          `LMStudio Failed to embed: ${Array.from(uniqueErrors).join(\", \")}`\n        );\n    }\n\n    const data = results.map((res) => res?.data || []);\n    return data.length > 0 ? data : null;\n  }\n}\n\nmodule.exports = {\n  LMStudioEmbedder,\n};\n","sourceCodeStart":92,"sourceCodeEnd":123,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/lmstudio/index.js#L92-L123","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nEMBEDDING_MODEL_PREF=some-chat-model   // not an embedding model -> EMPTY_ARR\n\n// after\nEMBEDDING_MODEL_PREF=nomic-ai/nomic-embed-text-v1.5","handlingStrategy":"try-catch","validationCode":"// confirm the model returns vectors before the bulk run\nasync function lmstudioEmbeds(openai, model, sample = 'hello') {\n  const r = await openai.embeddings.create({ model, input: sample, encoding_format: 'base64' });\n  return Array.isArray(r.data?.[0]?.embedding) && r.data[0].embedding.length > 0;\n}","typeGuard":"function isLMStudioEmbedError(e) {\n  return e instanceof Error && /LMStudio Failed to embed/.test(e.message);\n}","tryCatchPattern":"try {\n  return await embedder.embedChunks(chunks);\n} catch (e) {\n  if (/EMPTY_ARR/.test(e.message)) {\n    throw new Error('Loaded LMStudio model is not an embedding model', { cause: e });\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["lmstudio","embedding","runtime","upstream"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}