Mintplex-Labs/anything-llm · error · Error
Ollama returned empty embeddings for batch!
Error message
Ollama returned empty embeddings for batch!
What it means
Thrown inside the per-batch loop (line 114) when client.embed returns an `embeddings` field that is not a non-empty array. It is a defensive check on a successful RPC: Ollama answered but produced no vectors for the batch, which would leave gaps in the vector data, so the loop's catch captures it and the batch aborts.
Source
Thrown at server/utils/EmbeddingEngines/ollama/index.js:115
for (let i = 0; i < textChunks.length; i += this.maxConcurrentChunks) {
const batch = textChunks.slice(i, i + this.maxConcurrentChunks);
currentBatch++;
try {
// Use input param instead of prompt param to support batch processing
const res = await this.client.embed({
model: this.model,
input: batch,
options: {
// Always set the num_ctx to the max chunk length defined by the user in the settings
// so that the maximum context window is used and content is not truncated.
num_ctx: this.embeddingMaxChunkLength,
},
});
const { embeddings } = res;
if (!Array.isArray(embeddings) || embeddings.length === 0)
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}`);View on GitHub (pinned to 526360e320)
Solutions
- Set EMBEDDING_MODEL_PREF to an actual embedding model (e.g. nomic-embed-text) — run `ollama pull nomic-embed-text`
- Sanitize batch inputs to drop empty/whitespace-only strings before calling embedChunks
- Verify with `ollama run <model>` / a direct embed call that the model returns vectors
- Check maximumChunkLength() returns a sane positive value so num_ctx isn't zero
Example fix
// before EMBEDDING_MODEL_PREF=llama3 // chat model, no embeddings // after EMBEDDING_MODEL_PREF=nomic-embed-text
Defensive patterns
Strategy: validation
Validate before calling
// probe the model returns vectors before the bulk run
async function ollamaEmbeds(client, model, sample = 'hello') {
const res = await client.embed({ model, input: [sample] });
return Array.isArray(res?.embeddings) && res.embeddings.length > 0;
} Type guard
function isOllamaEmptyEmbeddings(e) {
return e instanceof Error && /empty embeddings for batch/.test(e.message);
} Try / catch
try {
return await embedder.embedChunks(chunks);
} catch (e) {
if (/empty embeddings for batch/.test(e.message)) {
throw new Error('Ollama model produced no vectors — use an embedding model', { cause: e });
}
throw e;
} Prevention
- Use an embedding model (nomic-embed-text), not a chat model.
- Filter empty/whitespace chunks before batching.
- Ensure maximumChunkLength() returns a sane positive value so num_ctx isn't zero.
When it happens
Trigger: client.embed resolves but res.embeddings is undefined/null or []. Causes: the named model is a chat/LLM model with no embedding support; model loaded but input batch was empty after slicing; Ollama build that does not populate embeddings for the given model; num_ctx set so small the input is fully truncated to nothing.
Common situations: EMBEDDING_MODEL_PREF pointing at a chat model (e.g. llama3) instead of an embedding model (nomic-embed-text); Ollama version regression; all-whitespace chunks; embeddingMaxChunkLength misconfigured to 0 causing total truncation.
Related errors
- Mistral returned empty embeddings for batch
- Ollama service could not be reached. Is Ollama running?
- Ollama Failed to embed: ${error}
- Ollama::getChatCompletion failed to communicate with Ollama.
- Stream returned undefined chunk. Aborting reply - check mode
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/c4fefaea93306e88.
Report an issue: GitHub.