Mintplex-Labs/anything-llm · error · Error
GenericOpenAI Failed to embed: ${error.message}
Error message
GenericOpenAI Failed to embed: ${error.message} What it means
Thrown inside the embedChunks loop when a batch returns an error. Unlike the Azure/Cohere/Gemini embedders, this is a single per-batch error (error.message), not an aggregated set, and the loop aborts on the first batch that fails. The message is prefixed 'GenericOpenAI Failed to embed:'.
Source
Thrown at server/utils/EmbeddingEngines/genericOpenAi/index.js:156
.create({
model: this.model,
input: chunk,
})
.then((result) => resolve({ data: result?.data, error: null }))
.catch((e) => {
e.type =
e?.response?.data?.error?.code ||
e?.response?.status ||
"failed_to_embed";
e.message = e?.response?.data?.error?.message || e.message;
resolve({ data: [], error: e });
});
});
// If any errors were returned from OpenAI abort the entire sequence because the embeddings
// will be incomplete.
if (error)
throw new Error(`GenericOpenAI Failed to embed: ${error.message}`);
allResults.push(...(data || []));
reportEmbeddingProgress(allResults.length, textChunks.length);
if (this.apiRequestDelay) await this.runDelay();
}
return allResults.length > 0 &&
allResults.every((embd) => embd.hasOwnProperty("embedding"))
? allResults.map((embd) => embd.embedding)
: null;
}
}
module.exports = {
GenericOpenAiEmbedder,
};
View on GitHub (pinned to 526360e320)
Solutions
- Read error.message: 'model not found' -> pull/load the model and set EMBEDDING_MODEL_PREF correctly; 'unauthorized' -> set GENERIC_OPEN_AI_EMBEDDING_API_KEY; connection errors -> confirm the server is up at EMBEDDING_BASE_PATH.
- GET <EMBEDDING_BASE_PATH>/models to confirm the model id is exposed before embedding.
- Shorten chunks to fit the local model's context; reduce concurrency if the server is resource-limited.
- Retry transient local-server errors after the server is healthy.
Example fix
// before
if (error) throw new Error(`GenericOpenAI Failed to embed: ${error.message}`);
// after (retry once on transient, then surface)
if (error) {
if (isTransient(error)) { /* retry batch */ }
else throw new Error(`GenericOpenAI Failed to embed: ${error.message}`);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight: confirm the upstream exposes the model before bulk embedding
const { OpenAI } = require('openai');
const client = new OpenAI({ baseURL: process.env.EMBEDDING_BASE_PATH, apiKey: process.env.GENERIC_OPEN_AI_EMBEDDING_API_KEY ?? null });
const list = await client.models.list();
if (!list.body.some((m) => m.id === process.env.EMBEDDING_MODEL_PREF)) {
throw new Error(`Generic upstream does not expose model ${process.env.EMBEDDING_MODEL_PREF}`);
} Try / catch
try {
await embedder.embedChunks(chunks);
} catch (e) {
const msg = e.message;
if (/model.*not|404/i.test(msg)) loadModel();
else if (/unauthorized|401/i.test(msg)) setApiKey();
else if (/econnrefused|timeout|socket/i.test(msg)) waitForServer();
else throw e;
} Prevention
- Pre-flight models.list() to confirm the upstream exposes your model id.
- Keep the local/generic server running and the model loaded before embedding.
- Set GENERIC_OPEN_AI_EMBEDDING_API_KEY if the proxy enforces auth.
When it happens
Trigger: Upstream at EMBEDDING_BASE_PATH returns non-200 (auth required but key unset/invalid, model not loaded, internal error); EMBEDDING_MODEL_PREF names a model the server does not expose; chunks exceed the server's max tokens; network/timeout to the local or remote generic endpoint.
Common situations: Local LLM server (Ollama/LM Studio/vLLM) not running or model not pulled; GENERIC_OPEN_AI_EMBEDDING_API_KEY required by the proxy but unset; mistyped model id; proxy rate limiting.
Related errors
- Lemonade Failed to embed: [${error.type}]: ${error.message}
- GenericOpenAI must have a valid base path to use for the api
- Could not find indexes.
- Failed to fetch documents by paths.
- e.message
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/360ff021173fe66d.
Report an issue: GitHub.