chroma-core/chroma · error · Error
Please install the @google/generative-ai package to use the
Error message
Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install @google/generative-ai`
What it means
GoogleGenerativeAiEmbeddingFunction.loadClient() lazily dynamic-imports the optional @google/generative-ai SDK on the first generate() call. If that import fails with MODULE_NOT_FOUND, this install-hint error is thrown; any other import failure is re-thrown raw. The SDK is optional so chromadb-core does not force it on users who embed with other providers.
Source
Thrown at clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts:59
this.api_key = apiKey;
this.api_key_env_var = apiKeyEnvVar;
this.model = model;
this.taskType = taskType;
}
private async loadClient() {
if (this.googleGenAiApi) return;
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
const { googleGenAi } =
await GoogleGenerativeAiEmbeddingFunction.import();
googleGenAiApi = googleGenAi;
// googleGenAiApi.init(this.api_key);
googleGenAiApi = new googleGenAiApi(this.api_key);
} catch (_a) {
// @ts-ignore
if (_a.code === "MODULE_NOT_FOUND") {
throw new Error(
"Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install @google/generative-ai`",
);
}
throw _a; // Re-throw other errors
}
this.googleGenAiApi = googleGenAiApi;
}
public async generate(texts: string[]) {
await this.loadClient();
const model = this.googleGenAiApi.getGenerativeModel({ model: this.model });
const response = await model.batchEmbedContents({
requests: texts.map((t) => ({
content: { parts: [{ text: t }] },
taskType: this.taskType,
})),
});
const embeddings = response.embeddings.map((e: any) => e.values);View on GitHub (pinned to aecdd12c8a)
Solutions
- npm install @google/generative-ai in the executing app, then retry
- Or switch to an embedding function whose dependency you already ship (ONNXMiniLM, OpenAI, etc.)
- If installed but still failing, test the import directly: node -e "import('@google/generative-ai').then(()=>console.log('ok'),e=>console.error(e))" and fix the underlying resolution error
- Reinstall cleanly with a committed lockfile (npm ci) to repair a partially installed tree
Example fix
// before
const ef = new GoogleGenerativeAiEmbeddingFunction({ googleApiKey: KEY, model: "embedding-001" });
await ef.generate(["ping"]); // -> Please install the @google/generative-ai package...
// after
// $ npm install @google/generative-ai
await ef.generate(["ping"]); // ok Defensive patterns
Strategy: validation
Validate before calling
async function googleGenAiAvailable(): Promise<boolean> {
try {
await import("@google/generative-ai");
return true;
} catch {
return false;
}
}
// before creating a collection that uses the Google embedding function:
if (!(await googleGenAiAvailable())) throw new Error("Install @google/generative-ai to use Google embeddings"); Try / catch
try {
await collection.add({ ids, documents });
} catch (e) {
if (e instanceof Error && /@google\/generative-ai/.test(e.message)) {
// dependency missing: install the SDK or switch embedding function
}
throw e;
} Prevention
- Smoke-test the first generate() at startup, not on the first user request
- List every provider SDK you use as an explicit dependency in the deploying app's package.json
- Run npm ci in build pipelines to keep optional deps consistent
When it happens
Trigger: Creating a collection with the Google embedding function and triggering the first generate()/add() in a project where @google/generative-ai is not installed.
Common situations: Installing chromadb without the Google SDK; monorepo hoisting issues; bundlers producing errors without .code (then a raw error appears instead); Docker images built from a trimmed dependency set.
Related errors
- Please install the chromadb-default-embed package to use the
- Please install @google/generative-ai as a dependency with, e
- Please install the ollama package to use the OllamaEmbedding
- Please install the openai package to use the OpenAIEmbedding
- Please install chromadb-default-embed as a dependency with,
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/98cbc4cd49677287.
Report an issue: GitHub.