chroma-core/chroma · error · Error
Please install @google/generative-ai as a dependency with, e
Error message
Please install @google/generative-ai as a dependency with, e.g. `npm install @google/generative-ai`
What it means
Static import helper for the Google embedding function: it wraps import("@google/generative-ai") in an unconditional try/catch, so every import failure — missing package, broken install, or bundler resolution — becomes the same 'install it as a dependency' message. The original error is discarded, which can mask non-obvious causes. Note the import destructures the named/default GoogleGenerativeAI export, so it targets the legacy @google/generative-ai package specifically.
Source
Thrown at clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts:94
});
const embeddings = response.embeddings.map((e: any) => e.values);
return embeddings;
}
/** @ignore */
static async import(): Promise<{
// @ts-ignore
googleGenAi: typeof import("@google/generative-ai");
}> {
try {
// @ts-ignore
const { GoogleGenerativeAI } = await import("@google/generative-ai");
const googleGenAi = GoogleGenerativeAI;
// @ts-ignore
return { googleGenAi };
} catch (e) {
throw new Error(
"Please install @google/generative-ai as a dependency with, e.g. `npm install @google/generative-ai`",
);
}
}
buildFromConfig(config: StoredConfig): GoogleGenerativeAiEmbeddingFunction {
return new GoogleGenerativeAiEmbeddingFunction({
model: config.model_name,
apiKeyEnvVar: config.api_key_env_var,
taskType: config.task_type,
});
}
getConfig(): StoredConfig {
return {
api_key_env_var: this.api_key_env_var,
model_name: this.model,
task_type: this.taskType,View on GitHub (pinned to aecdd12c8a)
Solutions
- npm install @google/generative-ai (the legacy package this function expects, not @google/genai)
- If it is installed, reproduce the swallowed error: node -e "import('@google/generative-ai').then(m=>console.log('ok'),e=>console.error(e))"
- Clean reinstall from the lockfile: rm -rf node_modules && npm ci
- Use a different embedding function if you do not want the dependency
Example fix
// before: install message despite presence in package.json
// after: expose the real import error the helper swallows
// $ node -e "import('@google/generative-ai').then(m=>console.log('ok'), e=>console.error(e))" Defensive patterns
Strategy: validation
Validate before calling
async function canImport(pkg: string): Promise<boolean> {
try {
await import(pkg);
return true;
} catch {
return false;
}
}
if (!(await canImport("@google/generative-ai"))) {
// choose another embedding function or fail with instructions
} Try / catch
try {
await ef.generate(texts);
} catch (e) {
if (e instanceof Error && /@google\/generative-ai/.test(e.message)) {
// probe the import to distinguish missing vs broken install
}
throw e;
} Prevention
- Pin the Google SDK version in package.json rather than relying on hoisting
- CI smoke-import each optional provider SDK
- Prefer explicit embedding functions over lazy-loaded providers in bundled deployments
When it happens
Trigger: Any rejection of import("@google/generative-ai") via GoogleGenerativeAiEmbeddingFunction.import(): package absent, half-installed, or unresolvable by the bundler/runtime.
Common situations: node_modules desync after branch switches; teams migrating to the newer @google/genai SDK and assuming the old one is present; bundler exports-map failures in Lambda/edge builds; optional deps stripped by minimal install stages.
Related errors
- Please install chromadb-default-embed as a dependency with,
- Please install the @google/generative-ai package to use the
- Please install Ollama as a dependency with, e.g. `npm instal
- Please install the cohere-ai package to use the CohereEmbedd
- Please install the chromadb-default-embed package to use the
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/54550ad26c87a89f.
Report an issue: GitHub.