Mintplex-Labs/anything-llm · error · Error
Ollama Failed to embed: ${error}
Error message
Ollama Failed to embed: ${error} What it means
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.
Source
Thrown at server/utils/EmbeddingEngines/ollama/index.js:133
throw new Error("Ollama returned empty embeddings for batch!");
// Using prompt param in embed() would return a single embedding (number[])
// but input param returns an array of embeddings (number[][]) for batch processing.
// This is why we spread the embeddings array into the data array.
data.push(...embeddings);
reportEmbeddingProgress(data.length, textChunks.length);
this.log(
`Batch ${currentBatch}/${totalBatches}: Embedded ${embeddings.length} chunks. Total: ${data.length}/${textChunks.length}`
);
} catch (err) {
this.log(err.message);
error = err.message;
data = [];
break;
}
}
if (!!error) throw new Error(`Ollama Failed to embed: ${error}`);
return data.length > 0 ? data : null;
}
}
module.exports = {
OllamaEmbedder,
};
View on GitHub (pinned to 526360e320)
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
Example fix
// before // low-RAM host, model thrashing between batches // after // pin one embedding model and free others ollama stop <chat-model> EMBEDDING_MODEL_PREF=nomic-embed-text
Defensive patterns
Strategy: try-catch
Validate before calling
// reserve enough context so chunks aren't truncated to nothing
function saneChunkLength(n) { return Number.isFinite(n) && n > 0; }
if (!saneChunkLength(maximumChunkLength())) {
throw new Error('embeddingMaxChunkLength is non-positive; chunks would be truncated.');
} Type guard
function isOllamaEmbedError(e) {
return e instanceof Error && /Ollama Failed to embed/.test(e.message);
} Try / catch
try {
return await embedder.embedChunks(chunks);
} catch (e) {
if (/model not found|empty embeddings/.test(e.message)) throw e; // fix config
// resource/connection errors may clear on retry
await new Promise(r => setTimeout(r, 2000));
return await embedder.embedChunks(chunks);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- LiteLLM Failed to embed: ${error}
- LMStudio Failed to embed: ${Array.from(uniqueErrors).join(",
- LocalAI Failed to embed: ${error}
- Ollama service could not be reached. Is Ollama running?
- Ollama returned empty embeddings for batch!
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/3c53ae46507b1823.
Report an issue: GitHub.