Ollama dial tcp [::1]:11434: connect: connection refused

Description

I am trying to set up a RAG system with dockerized Weaviate and Ollama using a node JS backend, but am having trouble with the Ollama modules. When Weaviate tries to make a call to Ollama, it gives this error: WeaviateQueryError: Query call with protocol gRPC failed with message: /weaviate.v1.Weaviate/Search UNKNOWN: explorer: get class: concurrentTargetVectorSearch): explorer: get class: vectorize search vector: vectorize params: vectorize params: vectorize keywords: remote client vectorize: send POST request: Post "http://localhost:11434/api/embeddings": dial tcp [::1]:11434: connect: connection refused. This happens in both the vectorizer and generator, and both while loading data or searching it.

I have set up both Weaviate and Ollama to start in the same docker-compose. In my collections configuration, I have tried several different api endpoints - http://ollama:11434, http://localhost:11434, and http://host.docker.internal:11434. I have confirmed that Ollama is accessible at localhost:11434 and that I can use the models through both http and the js ollama library.

I’m assuming I’ve just made some mistake in the configuration here, but I’ve spent the better part of 2 days on this problem and no solution I’ve found works. Does anyone have any insights here?

Collection configuration

  async createCollection(collectionName, properties) {
    const exists = this.client.collections.exists(collectionName)
    if (!exists) {
      await this.client.collections.create({
        name: collectionName,
        properties: properties,
        vectorizers: vectorizer.text2VecOllama({
          apiEndpoint: 'http://ollama:11434',
          model: 'nomic-embed-text',
        }),
        generative: generative.ollama({
          apiEndpoint: 'http://ollama:11434',
          model: 'llama3.1:8b',
        }),
      })
    }
  }

docker-compose.yml (I’m pretty sure OLLAMA_URL, OLLAMA_MODEL, and OLLAMA_EMBED_MODEL are for Verba which I am not using, but I included them just in case)

services:
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8765'
    - --scheme
    - http
    image: cr.weaviate.io/semitechnologies/weaviate:1.26.4
    ports:
    - 8765:8765
    - 50051:50051
    volumes:
    - weaviate_data:/var/lib/weaviate
    container_name: weaviate
    restart: on-failure:0
    environment:
      OLLAMA_URL: http://ollama:11434
      OLLAMA_MODEL: llama3.1:8b
      OLLAMA_EMBED_MODEL: nomic-embed-text:latest
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'text2vec-ollama'
      ENABLE_MODULES: 'text2vec-ollama,generative-ollama'
      CLUSTER_HOSTNAME: 'node1'

  ollama:
    image: ollama/ollama
    ports:
      - 11434:11434
    volumes:
      - ollama_data:/root/.ollama
      - ./entrypoint.sh:/entrypoint.sh
    container_name: ollama
    pull_policy: always
    tty: true
    restart: always
    entrypoint: ["/bin/bash", "/entrypoint.sh"]

volumes:
  weaviate_data:
  ollama_data:

entrypoint.sh is just a script to pull my ollama models once the container starts.

Server Setup Information

  • Weaviate Server Version: 1.26.4
  • Deployment Method:
  • Multi Node? Number of Running Nodes: no
  • Client Language and Version: JS API v3
  • Multitenancy?: no

Any additional Information

In case it matters, I originally had it set up with text2vec-transformers and that part worked fine, which is how I know what happens when there is data in the db. I can upload a version of the dockerfile I used for that if it would be relevant.

I did also briefly run Verba to see if it was able to use the ollama integration, and I confirmed at least that it could see the models I had installed. I didn’t test further than that though.

Side note, I have also had trouble with deleting collections. When I try, it seems to partially but not fully delete it, and puts it into a weird state where I can’t recreate the collection because it think one still exists, but I can’t fully delete them either unless I clear the volume. I haven’t thoroughly tested this yet though because I’ve been focused on the Ollama problem.

hi!

One way to make sure that your Weaviate can connect to Ollama is doing like this:

docker compose exec -ti weaviate sh -c "wget --header=\"Content-Type: application/x-www-form-urlencoded\" --post-data=\$'{\\n  \"model\": \"llama3.1:8b\",\\n  \"prompt\": \"Why is the sky blue?\"\\n}' --output-document - http://ollama:11434/api/generate"

This command will run a ollama test query, using wget from within Weaviate container.

I believe there is some docker connectivity issue going on :thinking:

I was able to spin up a working container. starting with your docker-compose, I have removed the entrypoint part, and called:

docker compose exec -ti ollama ollama pull llama3.1:8b
docker compose exec -ti ollama ollama pull nomic-embed-text

I have run a quick python code that worked:

from weaviate import classes as wvc
client.collections.delete("Test")
collection = client.collections.create(
    name="Test",
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_ollama(
        api_endpoint="http://ollama:11434",
        model="nomic-embed-text"
    ),
    generative_config=wvc.config.Configure.Generative.ollama(
        api_endpoint="http://ollama:11434",
        model="llama3.1:8b"
    )
)
collection.data.insert({"text": "Something about dogs"})

object = collection.query.fetch_objects(include_vector=True).objects[0]
generate = collection.generate.fetch_objects(limit=1, single_prompt="Translate to Spanish: {text}")
print(object.properties)
print(object.vector)
print(generate.objects[0].generated)

Let me know what is the output of the docker compose exec command so we can start from there.

Thanks!

1 Like

Thanks for your reply @DudaNogueira!

I was able to successfully run both the command and the python script. I also converted the script to js and ran it successfully*, so it seems that the issue is with how I’ve implemented it. I’ll just have to hunt that down. I’ll update here if I figure out exactly what was causing it.

* In js, everything worked except client.collections.delete("Test"), which does not fully delete the collection and prevents me from re-creating it, since it appears to still be there. The python version works fine, so it’s probably something in the js client. I’ll make a separate post about that though, since it seems to be unrelated.

Thanks for your help!

*Edit: Never mind, I’m just dumb and forgot an await while deleting. It seems to be working totally fine now

1 Like

Glad to hear that @sjogden !

and that now you are no longer blocked!!

Happy coding!

And remember: we are here to help whenever needed :slight_smile:

1 Like