{"record":{"id":"3c53ae46507b1823","repo":"Mintplex-Labs/anything-llm","slug":"ollama-failed-to-embed-error","errorCode":null,"errorMessage":"Ollama Failed to embed: ${error}","messagePattern":"Ollama Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/ollama/index.js","lineNumber":133,"sourceCode":"          throw new Error(\"Ollama returned empty embeddings for batch!\");\n\n        // Using prompt param in embed() would return a single embedding (number[])\n        // but input param returns an array of embeddings (number[][]) for batch processing.\n        // This is why we spread the embeddings array into the data array.\n        data.push(...embeddings);\n        reportEmbeddingProgress(data.length, textChunks.length);\n        this.log(\n          `Batch ${currentBatch}/${totalBatches}: Embedded ${embeddings.length} chunks. Total: ${data.length}/${textChunks.length}`\n        );\n      } catch (err) {\n        this.log(err.message);\n        error = err.message;\n        data = [];\n        break;\n      }\n    }\n\n    if (!!error) throw new Error(`Ollama Failed to embed: ${error}`);\n    return data.length > 0 ? data : null;\n  }\n}\n\nmodule.exports = {\n  OllamaEmbedder,\n};\n","sourceCodeStart":115,"sourceCodeEnd":141,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/ollama/index.js#L115-L141","documentation":"Thrown at the end of embedChunks (line 133) if the per-batch loop set `error` — which happens in the catch on any batch failure, including the empty-embeddings throw. The loop breaks on first error, clears data, and re-throws a single aggregated 'Ollama Failed to embed: <message>' so the caller sees one failure rather than partial results.","triggerScenarios":"Any batch's try block throws: client.embed network rejection; the empty-embeddings defensive throw (#335); model not found; Ollama daemon crashed mid-loop; context window exceeded (num_ctx too small for a chunk); auth token rejected for a remote Ollama.","commonSituations":"Ollama OOM mid-batch on low-memory machines (the code comment explicitly calls this out); model unloaded between batches; embeddingMaxChunkLength too small causing truncation errors; remote Ollama connection flapping; OLLAMA_AUTH_TOKEN wrong for a proxied instance.","solutions":["Read the embedded message: 'empty embeddings for batch' -> switch to a real embedding model (#335); 'model not found' -> `ollama pull <model>`; connection errors -> see #334","Increase num_ctx by raising the configured max chunk length if chunks are being truncated","Free Ollama resources (close other models) to avoid unload/reload thrash on low-RAM hosts","For a remote proxy, verify OLLAMA_AUTH_TOKEN and network stability"],"exampleFix":"// before\n// low-RAM host, model thrashing between batches\n\n// after\n// pin one embedding model and free others\nollama stop <chat-model>\nEMBEDDING_MODEL_PREF=nomic-embed-text","handlingStrategy":"try-catch","validationCode":"// reserve enough context so chunks aren't truncated to nothing\nfunction saneChunkLength(n) { return Number.isFinite(n) && n > 0; }\nif (!saneChunkLength(maximumChunkLength())) {\n  throw new Error('embeddingMaxChunkLength is non-positive; chunks would be truncated.');\n}","typeGuard":"function isOllamaEmbedError(e) {\n  return e instanceof Error && /Ollama Failed to embed/.test(e.message);\n}","tryCatchPattern":"try {\n  return await embedder.embedChunks(chunks);\n} catch (e) {\n  if (/model not found|empty embeddings/.test(e.message)) throw e;  // fix config\n  // resource/connection errors may clear on retry\n  await new Promise(r => setTimeout(r, 2000));\n  return await embedder.embedChunks(chunks);\n}","preventionTips":["On low-RAM hosts, stop other models so the embedder isn't unloaded mid-batch.","Keep one embedding model pinned for the duration of the ingest.","Size num_ctx to the largest chunk so nothing is truncated."],"tags":["ollama","embedding","runtime","upstream","resource"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}