chroma-core/chroma · error · Error

Please install the cohere-ai package to use the CohereEmbedd

Error message

Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`

What it means

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.

Source

Thrown at clients/js/packages/chromadb-core/src/embeddings/CohereEmbeddingFunction.ts:151

    this.apiKeyEnvVar = cohere_api_key_env_var;
  }

  private async initCohereClient() {
    if (this.cohereAiApi) return;
    try {
      // @ts-ignore
      this.cohereAiApi = await import("cohere-ai").then((cohere) => {
        // @ts-ignore
        if (cohere.CohereClient) {
          return new CohereAISDK7({ apiKey: this.apiKey });
        } else {
          return new CohereAISDK56({ apiKey: this.apiKey });
        }
      });
    } catch (e) {
      // @ts-ignore
      if (e.code === "MODULE_NOT_FOUND") {
        throw new Error(
          "Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`",
        );
      }
      throw e;
    }
  }

  public async generate(texts: string[]): Promise<number[][]> {
    await this.initCohereClient();
    // @ts-ignore
    return await this.cohereAiApi.createEmbedding({
      model: this.model,
      input: texts,
      isImage: this.isImage,
    });
  }

  buildFromConfig(config: StoredConfig): CohereEmbeddingFunction {

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Install the SDK: npm install -S cohere-ai (or pnpm/yarn equivalent).
  2. Keep it in 'dependencies', not 'devDependencies', so production installs include it.
  3. For bundlers, ensure dynamic imports are not statically broken - test an actual embedding in CI, not just typecheck.
  4. 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.

Example fix

# before
npm install chromadb

# after
npm install -S chromadb cohere-ai
Defensive patterns

Strategy: validation

Validate before calling

import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
let cohereAvailable = false;
try {
  require.resolve('cohere-ai');
  cohereAvailable = true;
} catch {
  cohereAvailable = false;
}
if (!cohereAvailable) {
  throw new Error('cohere-ai is not installed - run: npm install -S cohere-ai');
}
const ef = new CohereEmbeddingFunction({ model_name });

Try / catch

try {
  await ef.generate(texts);
} catch (e) {
  if (e instanceof Error && e.message.includes('npm install -S cohere-ai')) {
    // install the SDK and restart; this is not a runtime/transient failure
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/cc542e7d8edef0b9. Report an issue: GitHub.