# Dial tcp 127.0.0.1:11434: connect: connection refused (Local Ollama)

**URL:** <https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525>\
**Category:** Support\
**Tags:** bug, python\
**Created:** [May 28, 2024, 3:16pm UTC](https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525 "2024-05-28T15:16:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![suprateembanerjee](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/suprateembanerjee/32/1617_2.png) [@suprateembanerjee](https://forum.weaviate.io/u/suprateembanerjee)\
**Post date:** [May 28, 2024, 3:16pm UTC](https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525/1 "2024-05-28T15:16:41Z")

</div>

### Description

I am facing issues setting up a weaviate client with vectorizer and generative configurations. I am running Ollama Llama3 for my tasks. I am using Weaviate 1.25.

docker\_compose.yml (The local weaviate server I am running):

```---
version: '3.4'
services:
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8080'
    - --scheme
    - http
    image: cr.weaviate.io/semitechnologies/weaviate:1.25.1
    ports:
    - 8080:8080
    - 50051:50051
    - 11434:11434
    volumes:
    - weaviate_data:/var/lib/weaviate
    restart: on-failure:0
    environment:
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'none'
      ENABLE_MODULES: 'text2vec-ollama,generative-ollama,ref2vec-centroid,reranker-cohere,qna-openai'
      CLUSTER_HOSTNAME: 'node1'
volumes:
  weaviate_data:

```

Code (As mentioned in Quickstart, modified to use Ollama instead of OpenAI):

```auto
import weaviate
import weaviate.classes as wvc
from weaviate.classes.config import Property, DataType
from weaviate.connect import ConnectionParams
import ollama
import os
import requests
import json

client = weaviate.connect_to_local()

if client.collections.exists('Jeopardy'):
    print('Dropping pre-exisiting collection')
    client.collections.delete('Jeopardy')
    
jeopardy_collection = client.collections.create(name='Jeopardy',
                                                vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_ollama(),
                                                generative_config=wvc.config.Configure.Generative.ollama())

resp = requests.get('https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json')
jeopardy_data = json.loads(resp.text) 

question_objs = []

for i, data in enumerate(jeopardy_data):
    question_objs.append({
        "answer": data["Answer"],
        "question": data["Question"],
        "category": data["Category"],
    })

```

It runs well till here, then fails on insertion / update attempts:  
`jeopardy_collection.data.insert(jeopardy_data[0]) `  
with an error

```UnexpectedStatusCodeError
Cell In[27], line 1
----> 1 jeopardy_collection.data.insert(jeopardy_data[0])

File ~/miniforge3/envs/weaviate/lib/python3.11/site-packages/weaviate/collections/data.py:388, in _DataCollection.insert(self, properties, references, uuid, vector)
    385 if vector is not None:
    386 weaviate_obj = self.__parse_vector(weaviate_obj, vector)
--> 388 return self._insert(weaviate_obj)

File ~/miniforge3/envs/weaviate/lib/python3.11/site-packages/weaviate/collections/data.py:82, in _Data._insert(self, weaviate_obj)
     79 path = "/objects"
     81 params, weaviate_obj = self.__apply_context_to_params_and_object({}, weaviate_obj)
---> 82 self._connection.post(
     83 path=path,
     84 weaviate_object=weaviate_obj,
     85 params=params,
     86 error_msg="Object was not added",
     87 status_codes=_ExpectedStatusCodes(ok_in=200, error="insert object"),
     88 )
     89 return uuid_package.UUID(weaviate_obj["id"])

File ~/miniforge3/envs/weaviate/lib/python3.11/site-packages/weaviate/connect/v4.py:500, in _Connection.post(self, path, weaviate_object, params, error_msg, status_codes)
    492 def post(
    493 self,
    494 path: str,
   (...)
    498 status_codes: Optional[_ExpectedStatusCodes] = None,
    499 ) -> Response:
--> 500 return self.__send(
    501 "POST",
    502 url=self.url + self._api_version_path + path,
    503 weaviate_object=weaviate_object,
    504 params=params,
    505 error_msg=error_msg,
    506 status_codes=status_codes,
    507 )

File ~/miniforge3/envs/weaviate/lib/python3.11/site-packages/weaviate/connect/v4.py:451, in _Connection.__send(self, method, url, error_msg, status_codes, weaviate_object, params)
    449 res = self._client.send(req)
    450 if status_codes is not None and res.status_code not in status_codes.ok:
--> 451 raise UnexpectedStatusCodeError(error_msg, response=res)
    452 return cast(Response, res)
    453 except RuntimeError as e:

UnexpectedStatusCodeError: Object was not added! Unexpected status code: 500, with response body: {'error': [{'message': 'update vector: send POST request: Post "http://localhost:11434/api/embeddings": dial tcp 127.0.0.1:11434: connect: connection refused'}]}.

```

The server shows an error:

```auto
weaviate-1 | {"action":"requests_total","api":"rest","class_name":"Jeopardy","error":"update vector: send POST request: Post \"http://localhost:11434/api/embeddings\": dial tcp 127.0.0.1:11434: connect: connection refused","level":"error","msg":"unexpected error","query_type":"objects","time":"2024-05-28T14:42:25Z"}

```

To give some context, this code runs well (which does not use Ollama connectors from Weaviate itself):

```auto
client = weaviate.connect_to_local()
documents = [
  "Llamas are members of the camelid family meaning they're pretty closely related to vicuñas and camels",
  "Llamas were first domesticated and used as pack animals 4,000 to 5,000 years ago in the Peruvian highlands",
  "Llamas can grow as much as 6 feet tall though the average llama between 5 feet 6 inches and 5 feet 9 inches tall",
  "Llamas weigh between 280 and 450 pounds and can carry 25 to 30 percent of their body weight",
  "Llamas are vegetarians and have very efficient digestive systems",
  "Llamas live to be about 20 years old, though some only live for 15 years and others live to be 30 years old",
]

# Create a new data collection
if client.collections.exists('docs'):
    client.collections.delete('docs')
collection = client.collections.create(
    name = "docs", # Name of the data collection
    properties=[
        Property(name="text", data_type=DataType.TEXT), # Name and data type of the property
    ])

# Store each document in a vector embedding database
with collection.batch.dynamic() as batch:
  for i, document in enumerate(documents):
    # Generate embeddings
    response = ollama.embeddings(model = "llama3",
                                 prompt = document)

    # Add data object with text and embedding
    batch.add_object(
        properties = {"text" : document},
        vector = response["embedding"],
    )

# An example prompt
prompt = "What animals are llamas related to?"

# Generate an embedding for the prompt and retrieve the most relevant doc
response = ollama.embeddings(
  model = "llama3",
  prompt = prompt,
)

results = collection.query.near_vector(near_vector = response["embedding"],
                                       limit = 1)

data = results.objects[0].properties['text']

prompt_template = f"Using this data: {data}. Respond to this prompt: {prompt}"

# Generate a response combining the prompt and data we retrieved in step 2
output = ollama.generate(
  model = "llama3",
  prompt = prompt_template,
)

print(output['response'])

```

I need help fixing the connection issue with the weaviate server.

---

<div class="post-metadata">

**Author:** ![switch](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@switch](https://forum.weaviate.io/u/switch)\
**Post date:** [May 29, 2024, 2:48pm UTC](https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525/2 "2024-05-29T14:48:28Z")

</div>

I also have the same issue so I used [http://ollama:11424](http://ollama:11424) as vectorizer url with ollama refering to my ollama container

---

<div class="post-metadata">

**Author:** ![jphwang](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/jphwang/32/38_2.png) [@jphwang](https://forum.weaviate.io/u/jphwang)\
**Post date:** [May 29, 2024, 4:29pm UTC](https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525/3 "2024-05-29T16:29:50Z")

</div>

Hi @suprateembanerjee and @switch 👋

If you are using Docker, could you try setting the endpoint like this:

```python
client.collections.create(
    name="SomeCollection",
    vectorizer_config=Configure.Vectorizer.text2vec_ollama(
        api_endpoint="http://host.docker.internal:11434",
        model="snowflake-arctic-embed"
    )
)

```

As shown here? [text2vec-ollama | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-ollama#example-1)

Please let us know if that works for you. Thanks!

---

<div class="post-metadata">

**Author:** ![suprateembanerjee](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/suprateembanerjee/32/1617_2.png) [@suprateembanerjee](https://forum.weaviate.io/u/suprateembanerjee)\
**Post date:** [May 29, 2024, 6:41pm UTC](https://forum.weaviate.io/t/dial-tcp-127-0-0-1-connect-connection-refused-local-ollama/2525/4 "2024-05-29T18:41:16Z")

</div>

It does! Thanks!

Ollama can also be run in a docker container in which case @switch’s address is more applicable over a docker network.
