{"record":{"id":"6ced64895cb314be","repo":"chroma-core/chroma","slug":"please-install-the-ollama-package-to-use-the-ollam","errorCode":null,"errorMessage":"Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`","messagePattern":"Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/OllamaEmbeddingFunction.ts","lineNumber":38,"sourceCode":"    // for the openai npm package, and the constructor can not be async\n    if (url && url.endsWith(\"/api/embeddings\")) {\n      this.url = url.slice(0, -\"/api/embeddings\".length);\n    } else {\n      this.url = url;\n    }\n    this.model = model;\n  }\n\n  private async initClient() {\n    if (this.ollamaClient) return;\n    try {\n      // @ts-ignore\n      const { ollama } = await OllamaEmbeddingFunction.import();\n      this.ollamaClient = new ollama.Ollama({ host: this.url });\n    } catch (e) {\n      // @ts-ignore\n      if (e.code === \"MODULE_NOT_FOUND\") {\n        throw new Error(\n          \"Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`\",\n        );\n      }\n      throw e;\n    }\n  }\n\n  /** @ignore */\n  static async import(): Promise<{\n    // @ts-ignore\n    ollama: typeof import(\"ollama\");\n  }> {\n    try {\n      // @ts-ignore\n      const { ollama } = await import(\"ollama\").then((m) => ({ ollama: m }));\n      // @ts-ignore\n      return { ollama };\n    } catch (e) {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/OllamaEmbeddingFunction.ts#L20-L56","documentation":"OllamaEmbeddingFunction.initClient() lazily dynamic-imports the optional ollama npm package on the first generate() call and constructs new ollama.Ollama({ host: this.url }). If the import fails with MODULE_NOT_FOUND, this install-hint error is thrown; other errors are re-thrown unchanged. The package is optional so chromadb-core does not force it on users of other providers.","triggerScenarios":"Creating a collection with the Ollama embedding function and triggering the first generate()/add() in a project where the ollama npm package is not installed (the Ollama server being down is a separate, later failure).","commonSituations":"Installing chromadb without the ollama client package; monorepo hoisting dropping optional deps; bundler builds where the error lacks .code (a raw error appears instead); slim Docker images.","solutions":["npm install -S ollama in the app that runs the client, then retry","If installed but failing, test the import directly: node -e \"import('ollama').then(()=>console.log('ok'),e=>console.error(e))\"","Verify the Ollama server itself is reachable at the configured url once the package imports cleanly","Use an explicit different embedding function if you do not want the dependency"],"exampleFix":"// before\nconst ef = new OllamaEmbeddingFunction({ url: \"http://localhost:11434\", model: \"nomic-embed-text\" });\nawait ef.generate([\"ping\"]); // -> Please install the ollama package...\n\n// after\n// $ npm install -S ollama\nawait ef.generate([\"ping\"]); // ok","handlingStrategy":"validation","validationCode":"async function ollamaPkgAvailable(): Promise<boolean> {\n  try {\n    await import(\"ollama\");\n    return true;\n  } catch {\n    return false;\n  }\n}\n// before using the Ollama embedding function:\nif (!(await ollamaPkgAvailable())) throw new Error(\"Install the ollama npm package (and ensure the Ollama server is running)\");","typeGuard":null,"tryCatchPattern":"try {\n  await collection.add({ ids, documents });\n} catch (e) {\n  if (e instanceof Error && /install the ollama package/.test(e.message)) {\n    // dependency missing: install it or switch embedding function\n  }\n  throw e;\n}","preventionTips":["Add the ollama package as an explicit dependency if you use that embedding function","Smoke-test generate([\"ping\"]) at startup — it also surfaces a down Ollama server early","Keep the Ollama server URL in validated config, not ad-hoc strings"],"tags":["npm","ollama","optional-dependency","module-not-found","lazy-import","embeddings"],"backgroundTag":"module-not-found","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}