{"record":{"id":"9242995112a7d104","repo":"Mintplex-Labs/anything-llm","slug":"localai-failed-to-embed-error","errorCode":null,"errorMessage":"LocalAI Failed to embed: ${error}","messagePattern":"LocalAI Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/localAi/index.js","lineNumber":116,"sourceCode":"        .flat();\n      if (errors.length > 0) {\n        let uniqueErrors = new Set();\n        errors.map((error) =>\n          uniqueErrors.add(`[${error.type}]: ${error.message}`)\n        );\n\n        return {\n          data: [],\n          error: Array.from(uniqueErrors).join(\", \"),\n        };\n      }\n      return {\n        data: results.map((res) => res?.data || []).flat(),\n        error: null,\n      };\n    });\n\n    if (!!error) throw new Error(`LocalAI Failed to embed: ${error}`);\n    return data.length > 0 &&\n      data.every((embd) => embd.hasOwnProperty(\"embedding\"))\n      ? data.map((embd) => embd.embedding)\n      : null;\n  }\n}\n\nmodule.exports = {\n  LocalAiEmbedder,\n};\n","sourceCodeStart":98,"sourceCodeEnd":127,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/localAi/index.js#L98-L127","documentation":"Thrown at the end of embedChunks after Promise.all when any concurrent batch to the LocalAI endpoint failed. Batches of maxConcurrentChunks (50) are sent via embeddings.create; each rejection is caught and resolved as {data:[],error:e}, errors are deduplicated to a joined string, and presence of any error aborts the sequence to avoid incomplete vector data. This mirrors the LiteLLM/OpenAI batch flow.","triggerScenarios":"One or more batched /embeddings calls rejecting: 404 model not loaded in LocalAI; 401 from a missing/wrong LOCAL_AI_API_KEY; 500 from LocalAI failing to run the model (OOM, GGUF mismatch); input too large; LocalAI returning a non-JSON error breaking SDK parsing.","commonSituations":"LOCAL_AI_API_KEY required by the LocalAI server but unset; model file corrupted or wrong architecture; LocalAI server under-resourced (CPU/GPU) so larger batches OOM; LocalAI version change altering the model id or response shape; network instability to a remote LocalAI instance.","solutions":["Decode the joined [type]: message — a 401/403 means set LOCAL_AI_API_KEY, a 404 means fix EMBEDDING_MODEL_PREF to a loaded model","curl the LocalAI /v1/embeddings endpoint with the same model, key, and a sample input to reproduce","Reduce document chunk size or lower batch volume if LocalAI is OOMing","Check LocalAI logs for the per-request upstream error"],"exampleFix":"// before\n// LOCAL_AI_API_KEY unset but LocalAI requires auth -> 401 in joined error\n\n// after\nEMBEDDING_BASE_PATH=http://localhost:8080/v1\nEMBEDDING_MODEL_PREF=bge-small-en\nLOCAL_AI_API_KEY=my-local-key","handlingStrategy":"retry","validationCode":"// verify auth + model before the bulk run\nasync function localAiReady(openai, model) {\n  const res = await openai.models.list();\n  return res.data.some(m => m.id === model);\n}","typeGuard":"function isLocalAIEmbedError(e) {\n  return e instanceof Error && /LocalAI Failed to embed/.test(e.message);\n}","tryCatchPattern":"try {\n  return await embedder.embedChunks(chunks);\n} catch (e) {\n  if (/401|403|404/.test(e.message)) throw e;     // config error, not transient\n  await new Promise(r => setTimeout(r, 1000));\n  return await embedder.embedChunks(chunks);       // retry transient 5xx\n}","preventionTips":["Set LOCAL_AI_API_KEY if the LocalAI server enforces auth.","Keep batches sized so the server doesn't OOM.","Watch LocalAI logs for per-request model errors."],"tags":["localai","embedding","runtime","upstream","network"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}