{"record":{"id":"e01dbd01db259f6d","repo":"Mintplex-Labs/anything-llm","slug":"ollama-service-could-not-be-reached-is-ollama-run","errorCode":null,"errorMessage":"Ollama service could not be reached. Is Ollama running?","messagePattern":"Ollama service could not be reached\\. Is Ollama running\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/ollama/index.js","lineNumber":81,"sourceCode":"  }\n\n  /**\n   * This function takes an array of text chunks and embeds them using the Ollama API.\n   * Chunks are processed in batches based on the maxConcurrentChunks setting to balance\n   * resource usage on the Ollama endpoint.\n   *\n   * We will use the num_ctx option to set the maximum context window to the max chunk length defined by the user in the settings\n   * so that the maximum context window is used and content is not truncated.\n   *\n   * We also assume the default keep alive option. This could cause issues with models being unloaded and reloaded\n   * on low memory machines, but that is simply a user-end issue we cannot control. If the LLM and embedder are\n   * constantly being loaded and unloaded, the user should use another LLM or Embedder to avoid this issue.\n   * @param {string[]} textChunks - An array of text chunks to embed.\n   * @returns {Promise<Array<number[]>>} - A promise that resolves to an array of embeddings.\n   */\n  async embedChunks(textChunks = []) {\n    if (!(await this.#isAlive()))\n      throw new Error(\n        `Ollama service could not be reached. Is Ollama running?`\n      );\n    this.log(\n      `Embedding ${textChunks.length} chunks of text with ${this.model} in batches of ${this.maxConcurrentChunks}.`\n    );\n\n    let data = [];\n    let error = null;\n\n    // Process chunks in batches based on maxConcurrentChunks\n    const totalBatches = Math.ceil(\n      textChunks.length / this.maxConcurrentChunks\n    );\n    let currentBatch = 0;\n\n    for (let i = 0; i < textChunks.length; i += this.maxConcurrentChunks) {\n      const batch = textChunks.slice(i, i + this.maxConcurrentChunks);\n      currentBatch++;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/ollama/index.js#L63-L99","documentation":"Thrown at the start of embedChunks (line 80) when #isAlive() returns false. #isAlive does a plain fetch to this.basePath and treats any non-ok response or thrown error as dead. This preflight prevents queuing many batched embed calls against an unreachable daemon.","triggerScenarios":"embedChunks called and #isAlive resolves false: Ollama daemon not running; wrong host/port in EMBEDDING_BASE_PATH; connection refused/firewalled; OLLAMA_AUTH_TOKEN set but mismatched so the ping 401s (res.ok false); TLS/DNS failure for a remote Ollama host; fetch itself throws and the .catch returns false.","commonSituations":"Ollama not started (`ollama serve` not running); AnythingLLM in a container that cannot reach the host's 11434; remote Ollama behind a proxy requiring auth; OLLAMA_HOST changed on the Ollama side but AnythingLLM env not updated; transient network blip to a remote instance.","solutions":["Ensure Ollama is running: `ollama serve` or the app, and curl http://<host>:11434 returns 'Ollama is running'","Fix EMBEDDING_BASE_PATH to the correct reachable host/port","In Docker use host.docker.internal:11434 or --network host","If OLLAMA_AUTH_TOKEN is set, make sure it matches the daemon's expected token, or unset it for a local unauthed daemon"],"exampleFix":"// before\nEMBEDDING_BASE_PATH=http://localhost:11434\n// (in Docker, localhost != host)\n\n// after\nEMBEDDING_BASE_PATH=http://host.docker.internal:11434\n// and confirm `curl http://host.docker.internal:11434` succeeds","handlingStrategy":"retry","validationCode":"// ping the daemon exactly like #isAlive before the bulk run\nasync function ollamaAlive(basePath, token) {\n  const headers = token ? { Authorization: `Bearer ${token}` } : {};\n  try { const r = await fetch(basePath, { headers }); return r.ok; }\n  catch { return false; }\n}","typeGuard":"function isOllamaUnreachable(e) {\n  return e instanceof Error && /Ollama service could not be reached/.test(e.message);\n}","tryCatchPattern":"try {\n  return await embedder.embedChunks(chunks);\n} catch (e) {\n  if (!/could not be reached/.test(e.message)) throw e;\n  await new Promise(r => setTimeout(r, 2000));\n  return await embedder.embedChunks(chunks);\n}","preventionTips":["Run `ollama serve` / the app and keep it up for the whole ingest.","Confirm reachability from the AnythingLLM process (mind Docker networking).","Match OLLAMA_AUTH_TOKEN to the daemon, or unset for a local unauthed daemon."],"tags":["ollama","embedding","network","runtime","preflight"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}