{"record":{"id":"3918943333d9d0e3","repo":"Mintplex-Labs/anything-llm","slug":"cohere-failed-to-embed-error","errorCode":null,"errorMessage":"Cohere Failed to embed: ${error}","messagePattern":"Cohere Failed to embed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/cohere/index.js","lineNumber":90,"sourceCode":"        .filter((res) => !!res.error)\n        .map((res) => res.error)\n        .flat();\n\n      if (errors.length > 0) {\n        let uniqueErrors = new Set();\n        errors.map((error) =>\n          uniqueErrors.add(`[${error.type}]: ${error.message}`)\n        );\n        return { data: [], error: Array.from(uniqueErrors).join(\", \") };\n      }\n\n      return {\n        data: results.map((res) => res?.data || []).flat(),\n        error: null,\n      };\n    });\n\n    if (!!error) throw new Error(`Cohere Failed to embed: ${error}`);\n\n    return data.length > 0 &&\n      data.every((embd) => embd.hasOwnProperty(\"embedding\"))\n      ? data.map((embd) => embd.embedding)\n      : null;\n  }\n}\n\nmodule.exports = {\n  CohereEmbedder,\n};\n","sourceCodeStart":72,"sourceCodeEnd":102,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/cohere/index.js#L72-L102","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight one small embed to validate key + model before bulk\ntry {\n  await embedder.embedTextInput('ping');\n} catch (e) {\n  throw new Error(`Cohere embed preflight failed: ${e.message}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await embedder.embedChunks(chunks);\n} catch (e) {\n  const msg = e.message;\n  if (/\\[auth\\]|401|unauthorized/i.test(msg)) rotateKey();\n  else if (/rate|429|quota/i.test(msg)) reduceConcurrency();\n  else if (/too.large|token/i.test(msg)) shortenChunks();\n  else throw e;\n}","preventionTips":["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."],"tags":["cohere","embeddings","rate-limit","batch","content-filter"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}