Mintplex-Labs/anything-llm · error · Error
Cohere Failed to embed: ${error}
Error message
Cohere Failed to embed: ${error} What it means
Thrown after the embedding batches settle if any returned an error. Cohere per-batch errors are normalized into uniqueErrors entries shaped '[<error.type>]: <error.message>' and joined; the combined string is prefixed 'Cohere Failed to embed:'. Any failed batch aborts the whole call and no vectors are returned.
Source
Thrown at server/utils/EmbeddingEngines/cohere/index.js:90
.filter((res) => !!res.error)
.map((res) => res.error)
.flat();
if (errors.length > 0) {
let uniqueErrors = new Set();
errors.map((error) =>
uniqueErrors.add(`[${error.type}]: ${error.message}`)
);
return { data: [], error: Array.from(uniqueErrors).join(", ") };
}
return {
data: results.map((res) => res?.data || []).flat(),
error: null,
};
});
if (!!error) throw new Error(`Cohere Failed to embed: ${error}`);
return data.length > 0 &&
data.every((embd) => embd.hasOwnProperty("embedding"))
? data.map((embd) => embd.embedding)
: null;
}
}
module.exports = {
CohereEmbedder,
};
View on GitHub (pinned to 526360e320)
Solutions
- Parse the joined '[type]: message' tokens: 'auth'/'401' -> key; 'rate_limit'/'429' -> back off and reduce concurrency; 'request_too_large' -> shorten chunks.
- Set EMBEDDING_MODEL_PREF to a Cohere embedding model (e.g. embed-english-v3.0, embed-multilingual-v3.0).
- Reduce maxConcurrentChunks or batch size to stay under Cohere limits.
- Retry after resolving the persistent cause; partial vectors are not returned.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-flight one small embed to validate key + model before bulk
try {
await embedder.embedTextInput('ping');
} catch (e) {
throw new Error(`Cohere embed preflight failed: ${e.message}`);
} Try / catch
try {
await embedder.embedChunks(chunks);
} catch (e) {
const msg = e.message;
if (/\[auth\]|401|unauthorized/i.test(msg)) rotateKey();
else if (/rate|429|quota/i.test(msg)) reduceConcurrency();
else if (/too.large|token/i.test(msg)) shortenChunks();
else throw e;
} Prevention
- Pre-flight a tiny embed before bulk runs.
- Use a Cohere embedding model (embed-english-v3.0 / embed-multilingual-v3.0), not a rerank/chat model.
- Reduce concurrency and chunk size to fit Cohere limits.
When it happens
Trigger: Invalid/revoked COHERE_API_KEY surfacing as auth errors on the batch; 429 rate limits on embed-english-v3.0 or similar; input too long for the model's max token limit; embedding model id in EMBEDDING_MODEL_PREF not enabled for the account; network errors on some concurrent batches.
Common situations: Bulk-embedding a large corpus that trips Cohere rate limits; wrong model id (e.g. a rerank model used for embedding); oversized chunks; key rotated mid-job.
Related errors
- Azure OpenAI Failed to embed: ${error}
- Gemini Failed to embed: ${error}
- No Cohere API key was set.
- GenericOpenAI Failed to embed: ${error.message}
- Lemonade Failed to embed: [${error.type}]: ${error.message}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/3918943333d9d0e3.
Report an issue: GitHub.