{"record":{"id":"cc542e7d8edef0b9","repo":"chroma-core/chroma","slug":"please-install-the-cohere-ai-package-to-use-the-co","errorCode":null,"errorMessage":"Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`","messagePattern":"Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/CohereEmbeddingFunction.ts","lineNumber":151,"sourceCode":"    this.apiKeyEnvVar = cohere_api_key_env_var;\n  }\n\n  private async initCohereClient() {\n    if (this.cohereAiApi) return;\n    try {\n      // @ts-ignore\n      this.cohereAiApi = await import(\"cohere-ai\").then((cohere) => {\n        // @ts-ignore\n        if (cohere.CohereClient) {\n          return new CohereAISDK7({ apiKey: this.apiKey });\n        } else {\n          return new CohereAISDK56({ apiKey: this.apiKey });\n        }\n      });\n    } catch (e) {\n      // @ts-ignore\n      if (e.code === \"MODULE_NOT_FOUND\") {\n        throw new Error(\n          \"Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`\",\n        );\n      }\n      throw e;\n    }\n  }\n\n  public async generate(texts: string[]): Promise<number[][]> {\n    await this.initCohereClient();\n    // @ts-ignore\n    return await this.cohereAiApi.createEmbedding({\n      model: this.model,\n      input: texts,\n      isImage: this.isImage,\n    });\n  }\n\n  buildFromConfig(config: StoredConfig): CohereEmbeddingFunction {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/CohereEmbeddingFunction.ts#L133-L169","documentation":"CohereEmbeddingFunction lazy-loads the SDK on first generate() via dynamic import('cohere-ai'). If the module resolution fails with MODULE_NOT_FOUND, it rethrows this friendly message telling you to install the package. cohere-ai is an optional peer dependency of chromadb - the JS client supports many embedding backends, so none of their SDKs ship with the core install. The constructor succeeds; the failure is deferred to the first embedding call.","triggerScenarios":"First await ef.generate([...]) (or collection.add/query with documents) after npm install chromadb without cohere-ai; bundlers (esbuild/webpack) that tree-shake or externalize dynamic imports incorrectly; missing dependency after switching package managers or pruning node_modules.","commonSituations":"Fresh projects assuming all EFs are built in; production Docker images built with npm prune --production where cohere-ai was a devDependency; monorepo hoisting hiding a missing dependency until runtime.","solutions":["Install the SDK: npm install -S cohere-ai (or pnpm/yarn equivalent).","Keep it in 'dependencies', not 'devDependencies', so production installs include it.","For bundlers, ensure dynamic imports are not statically broken - test an actual embedding in CI, not just typecheck.","Warm up the import at startup (call a 1-token generate or pre-import 'cohere-ai') so failures surface at boot instead of mid-request."],"exampleFix":"# before\nnpm install chromadb\n\n# after\nnpm install -S chromadb cohere-ai","handlingStrategy":"validation","validationCode":"import { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\nlet cohereAvailable = false;\ntry {\n  require.resolve('cohere-ai');\n  cohereAvailable = true;\n} catch {\n  cohereAvailable = false;\n}\nif (!cohereAvailable) {\n  throw new Error('cohere-ai is not installed - run: npm install -S cohere-ai');\n}\nconst ef = new CohereEmbeddingFunction({ model_name });","typeGuard":null,"tryCatchPattern":"try {\n  await ef.generate(texts);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('npm install -S cohere-ai')) {\n    // install the SDK and restart; this is not a runtime/transient failure\n  }\n  throw e;\n}","preventionTips":["Install optional embedding SDKs (cohere-ai) as regular dependencies, not devDependencies.","Warm up embedding functions at boot so missing modules fail startup, not user requests.","In Docker, run the app's actual embedding path once in CI to catch resolution issues."],"tags":["embeddings","cohere","missing-dependency","module-not-found","npm"],"backgroundTag":"missing-dependency","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}