{"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/lmstudio/index.js#L92-L123","documentation":"Thrown from LMStudioEmbedder.embedChunks after the sequential per-chunk loop. Because LM Studio drops queued requests, chunks are embedded one at a time; any failure sets hasError and stops the loop. Each error is normalized to '[type]: message' (type from the HTTP error code/status, default 'failed_to_embed', or the sentinel 'EMPTY_ARR'), de-duplicated, and joined with commas.","triggerScenarios":"EMBEDDING_MODEL_PREF points at a loaded chat/LLM model rather than an embedding model (server rejects or returns unusable output); model id not loaded (404 from the server); a chunk exceeding the loaded model's context length; embedding returns an empty array, producing \"[EMPTY_ARR]: The embedding was empty from LMStudio\"; server stopped between the #isAlive check and the embedding call.","commonSituations":"Selecting a conversational model (e.g. a Mistral or Llama chat model) as the embedder; nomic-embed-text loaded with a tiny context so large chunks fail; LM Studio's JIT server unloading the model mid-run.","solutions":["Match on the [type] segment: EMPTY_ARR means the server answered but produced no usable embedding; an HTTP code means the server rejected the request","Load a real embedding model (e.g. nomic-embed-text-v1.5) and set EMBEDDING_MODEL_PREF to exactly that id","If chunks overflow context, raise the model's context in LM Studio or lower EMBEDDING_MODEL_MAX_CHUNK_LENGTH","Confirm the model stays loaded for the whole embedding (disable JIT unload / keep model in memory)","Re-run the document embed after fixing — the loop aborts on first error so later chunks were skipped"],"exampleFix":"# before: chat model selected, fails with EMPTY_ARR or 4xx\nEMBEDDING_MODEL_PREF=mistral-7b-instruct\n\n# after: dedicated embedding model loaded in LM Studio\nEMBEDDING_MODEL_PREF=text-embedding-nomic-embed-text-v1.5","handlingStrategy":"try-catch","validationCode":"// Pre-flight: the configured model must be an embedding model that round-trips one input\nasync function lmStudioCanEmbed(openai, model) {\n  try {\n    const res = await openai.embeddings.create({ model, input: \"ping\", encoding_format: \"base64\" });\n    const emb = res.data?.[0]?.embedding;\n    return Array.isArray(emb) && emb.length > 0;\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedTextInput(text);\n} catch (e) {\n  if (e.message.startsWith(\"LMStudio Failed to embed:\")) {\n    if (e.message.includes(\"[EMPTY_ARR]\")) { /* model returned no embedding — usually a chat model selected; switch EMBEDDING_MODEL_PREF */ }\n    else if (/\\[(4\\d\\d|5\\d\\d)\\]/.test(e.message)) { /* server rejected the request — check model id / context length */ }\n    else throw e;\n  } else throw e;\n}","preventionTips":["Use a true embedding model as EMBEDDING_MODEL_PREF; chat LLMs trigger EMPTY_ARR or 4xx errors","Keep the model resident in memory (disable JIT unload) so it survives a long sequential embed","Set the model's context large enough for EMBEDDING_MODEL_MAX_CHUNK_LENGTH-sized chunks"],"tags":["lmstudio","local-server","embeddings","model-name","context-length"],"backgroundTag":"embedding-api-request-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}