{"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":null,"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/ollama/index.js#L63-L99","documentation":"Before embedding, embedChunks() calls the private #isAlive(), which does a plain fetch() against EMBEDDING_BASE_PATH and requires an ok (2xx) response. The error is thrown when that fetch rejects (connection refused, DNS failure, timeout) or returns a non-2xx status (e.g. 401 from an auth gateway). This is a pre-flight health-check failure, not a failure of the embed API itself.","triggerScenarios":"Ollama is not running (serve crashed or was never started); EMBEDDING_BASE_PATH is malformed or wrong (missing http://, wrong port, typo); AnythingLLM runs in docker and localhost resolves to the container, not the host; OLLAMA_AUTH_TOKEN is missing/wrong and a proxy in front of Ollama returns 401/403; a reverse proxy answering the root path with 502/504.","commonSituations":"Docker AnythingLLM with EMBEDDING_BASE_PATH=http://localhost:11434 instead of http://host.docker.internal:11434; Ollama bound to 127.0.0.1 while AnythingLLM runs on another machine; macOS Ollama desktop app not launched; systemd Ollama unit stopped after a reboot.","solutions":["Start Ollama (`ollama serve` or the desktop app) and verify with `curl -i http://localhost:11434` that it returns 200.","Fix EMBEDDING_BASE_PATH — inside docker use http://host.docker.internal:11434 (or the host IP), not localhost.","If Ollama sits behind an auth proxy, set OLLAMA_AUTH_TOKEN to the bearer token the proxy expects.","When Ollama runs on another host, start it with OLLAMA_HOST=0.0.0.0 so it accepts remote connections."],"exampleFix":"# .env — before (localhost inside a container points at the container itself)\nEMBEDDING_BASE_PATH=http://localhost:11434\n\n# .env — after\nEMBEDDING_BASE_PATH=http://host.docker.internal:11434","handlingStrategy":"validation","validationCode":"async function ollamaAlive(basePath, token) {\n  try {\n    const res = await fetch(basePath, {\n      headers: token ? { Authorization: `Bearer ${token}` } : {},\n    });\n    return res.ok;\n  } catch {\n    return false;\n  }\n}\nif (\n  !(await ollamaAlive(\n    process.env.EMBEDDING_BASE_PATH,\n    process.env.OLLAMA_AUTH_TOKEN\n  ))\n) {\n  throw new Error(\"Ollama is not reachable — start it or fix EMBEDDING_BASE_PATH before embedding.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  const vectors = await embedder.embedChunks(chunks);\n} catch (err) {\n  if (err.message.includes(\"could not be reached\")) {\n    // connectivity/config problem, not a data problem:\n    // surface 'start Ollama / check EMBEDDING_BASE_PATH' guidance to the user\n  } else {\n    throw err;\n  }\n}","preventionTips":["In docker, always address host services via host.docker.internal or the host IP, never localhost.","Run a readiness probe against the Ollama base path before starting embedding jobs.","Pin OLLAMA_HOST when Ollama must serve remote clients."],"tags":["ollama","embeddings","network","connectivity","health-check"],"backgroundTag":"service-unreachable","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}