{"record":{"id":"98cbc4cd49677287","repo":"chroma-core/chroma","slug":"please-install-the-google-generative-ai-package-t","errorCode":null,"errorMessage":"Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install @google/generative-ai`","messagePattern":"Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install @google/generative-ai`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts","lineNumber":59,"sourceCode":"    this.api_key = apiKey;\n    this.api_key_env_var = apiKeyEnvVar;\n    this.model = model;\n    this.taskType = taskType;\n  }\n\n  private async loadClient() {\n    if (this.googleGenAiApi) return;\n    try {\n      // eslint-disable-next-line global-require,import/no-extraneous-dependencies\n      const { googleGenAi } =\n        await GoogleGenerativeAiEmbeddingFunction.import();\n      googleGenAiApi = googleGenAi;\n      // googleGenAiApi.init(this.api_key);\n      googleGenAiApi = new googleGenAiApi(this.api_key);\n    } catch (_a) {\n      // @ts-ignore\n      if (_a.code === \"MODULE_NOT_FOUND\") {\n        throw new Error(\n          \"Please install the @google/generative-ai package to use the GoogleGenerativeAiEmbeddingFunction, `npm install @google/generative-ai`\",\n        );\n      }\n      throw _a; // Re-throw other errors\n    }\n    this.googleGenAiApi = googleGenAiApi;\n  }\n\n  public async generate(texts: string[]) {\n    await this.loadClient();\n    const model = this.googleGenAiApi.getGenerativeModel({ model: this.model });\n    const response = await model.batchEmbedContents({\n      requests: texts.map((t) => ({\n        content: { parts: [{ text: t }] },\n        taskType: this.taskType,\n      })),\n    });\n    const embeddings = response.embeddings.map((e: any) => e.values);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts#L41-L77","documentation":"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.","triggerScenarios":"Creating a collection with the Google embedding function and triggering the first generate()/add() in a project where @google/generative-ai is not installed.","commonSituations":"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.","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"],"exampleFix":"// before\nconst ef = new GoogleGenerativeAiEmbeddingFunction({ googleApiKey: KEY, model: \"embedding-001\" });\nawait ef.generate([\"ping\"]); // -> Please install the @google/generative-ai package...\n\n// after\n// $ npm install @google/generative-ai\nawait ef.generate([\"ping\"]); // ok","handlingStrategy":"validation","validationCode":"async function googleGenAiAvailable(): Promise<boolean> {\n  try {\n    await import(\"@google/generative-ai\");\n    return true;\n  } catch {\n    return false;\n  }\n}\n// before creating a collection that uses the Google embedding function:\nif (!(await googleGenAiAvailable())) throw new Error(\"Install @google/generative-ai to use Google embeddings\");","typeGuard":null,"tryCatchPattern":"try {\n  await collection.add({ ids, documents });\n} catch (e) {\n  if (e instanceof Error && /@google\\/generative-ai/.test(e.message)) {\n    // dependency missing: install the SDK or switch embedding function\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["npm","google","gemini","optional-dependency","module-not-found","lazy-import"],"backgroundTag":"module-not-found","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}