{"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/localAi/index.js#L98-L127","documentation":"Thrown from LocalAiEmbedder.embedChunks when any chunk request to LocalAI fails; distinct errors are collected into a Set and joined with commas, so the text after the colon enumerates each unique upstream failure. Requests are batched up to 50 chunks at once, and a single bad batch aborts the embedding.","triggerScenarios":"EMBEDDING_MODEL_PREF names a model that is not installed in LocalAI (404 error: 'model not found'); the model exists but its backend (e.g. sentence-transformers) is missing or fails to load; 401 when LocalAI requires LOCAL_AI_API_KEY and it is unset/wrong; chunk sizes exceeding the model's max length; LocalAI restarting/crashing under the 50-chunk batch load.","commonSituations":"Gallery model half-installed after an interrupted pull; LocalAI upgraded and backend names changed; CPU/RAM exhaustion on small hosts during bulk embedding causing worker errors.","solutions":["Read the joined message — each entry is LocalAI's own error string (model not found, backend load failure, auth, etc.)","Verify the model is installed and responds: curl the /v1/embeddings endpoint directly with a one-line input","Reinstall or pull the embedding model in the LocalAI gallery and align EMBEDDING_MODEL_PREF with its exact name","Set LOCAL_AI_API_KEY if your LocalAI instance enforces auth","For memory/context failures, lower EMBEDDING_MODEL_MAX_CHUNK_LENGTH or reduce concurrency/batch load"],"exampleFix":"# verify the model actually embeds before blaming AnythingLLM:\ncurl http://localhost:8080/v1/embeddings \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"model\":\"bert-embeddings\",\"input\":[\"hello\"]}'\n# 200 -> fix EMBEDDING_MODEL_PREF to match; 404 -> install the model in LocalAI","handlingStrategy":"try-catch","validationCode":"// Smoke-test LocalAI exactly like production will: POST /embeddings with one input\nasync function localAiEmbedderHealthy(basePath, model, apiKey) {\n  const res = await fetch(`${basePath}/embeddings`, {\n    method: \"POST\",\n    headers: { \"Content-Type\": \"application/json\", ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}) },\n    body: JSON.stringify({ model, input: [\"ping\"] }),\n  });\n  if (!res.ok) { console.error(\"LocalAI pre-flight:\", res.status, await res.text()); return false; }\n  const json = await res.json();\n  return Array.isArray(json?.data?.[0]?.embedding);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedTextInput(text);\n} catch (e) {\n  if (e.message.startsWith(\"LocalAI Failed to embed:\")) {\n    const detail = e.message;\n    if (/not found|404/i.test(detail)) { /* install the model in the LocalAI gallery; no retry until fixed */ }\n    else if (/401|unauthorized/i.test(detail)) { /* set LOCAL_AI_API_KEY */ }\n    else if (/429|load|memory/i.test(detail)) { /* reduce batch load / free resources, then retry once */ }\n    else throw e;\n  } else throw e;\n}","preventionTips":["Verify the model responds to a single-input /embeddings call before bulk embedding","Watch LocalAI logs during embedding — its backend load errors are the root cause of many normalized messages","Size EMBEDDING_MODEL_MAX_CHUNK_LENGTH to the model's limit to avoid rejected batches of 50 chunks"],"tags":["localai","self-hosted","embeddings","api-error","model-install"],"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"}