chroma icon indicating copy to clipboard operation
chroma copied to clipboard

[Install issue ]:SOLVED ValueError: Could not connect to a Chroma server. Are you sure it is running?

Open Solomin0 opened this issue 1 year ago • 22 comments

What happened?

I am composing a docker file to connect a python container to a chroma instance. I am using the same compose file i have in the past so im not sure what the difference is.

main.txt

docker-compose.txt

It builds both images without issue but running main.py will not work.

the main container has chromadb pip installed, I tried every connection string i could think of (localhost, chroma, publishv1-chroma-1) and i am not sure what else to do any help is appreciated.

Versions

ghcr.io/chroma-core/chroma:latest chromadb 0.4.18

Relevant log output

2023-12-01 08:05:00 running heartbeat
2023-12-01 08:05:00 Traceback (most recent call last):
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 174, in _new_conn
2023-12-01 08:05:00     conn = connection.create_connection(
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/util/connection.py", line 95, in create_connection
2023-12-01 08:05:00     raise err
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/util/connection.py", line 85, in create_connection
2023-12-01 08:05:00     sock.connect(sa)
2023-12-01 08:05:00 ConnectionRefusedError: [Errno 111] Connection refused
2023-12-01 08:05:00 
2023-12-01 08:05:00 During handling of the above exception, another exception occurred:
2023-12-01 08:05:00 
2023-12-01 08:05:00 Traceback (most recent call last):
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 715, in urlopen
2023-12-01 08:05:00     httplib_response = self._make_request(
2023-12-01 08:05:00                        ^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 416, in _make_request
2023-12-01 08:05:00     conn.request(method, url, **httplib_request_kw)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 244, in request
2023-12-01 08:05:00     super(HTTPConnection, self).request(method, url, body=body, headers=headers)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/http/client.py", line 1286, in request
2023-12-01 08:05:00     self._send_request(method, url, body, headers, encode_chunked)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/http/client.py", line 1332, in _send_request
2023-12-01 08:05:00     self.endheaders(body, encode_chunked=encode_chunked)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/http/client.py", line 1281, in endheaders
2023-12-01 08:05:00     self._send_output(message_body, encode_chunked=encode_chunked)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/http/client.py", line 1041, in _send_output
2023-12-01 08:05:00     self.send(msg)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/http/client.py", line 979, in send
2023-12-01 08:05:00     self.connect()
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 205, in connect
2023-12-01 08:05:00     conn = self._new_conn()
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connection.py", line 186, in _new_conn
2023-12-01 08:05:00     raise NewConnectionError(
2023-12-01 08:05:00 urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f6cc756f190>: Failed to establish a new connection: [Errno 111] Connection refused
2023-12-01 08:05:00 
2023-12-01 08:05:00 During handling of the above exception, another exception occurred:
2023-12-01 08:05:00 
2023-12-01 08:05:00 Traceback (most recent call last):
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
2023-12-01 08:05:00     resp = conn.urlopen(
2023-12-01 08:05:00            ^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 799, in urlopen
2023-12-01 08:05:00     retries = retries.increment(
2023-12-01 08:05:00               ^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 592, in increment
2023-12-01 08:05:00     raise MaxRetryError(_pool, url, error or ResponseError(cause))
2023-12-01 08:05:00 urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6cc756f190>: Failed to establish a new connection: [Errno 111] Connection refused'))
2023-12-01 08:05:00 
2023-12-01 08:05:00 During handling of the above exception, another exception occurred:
2023-12-01 08:05:00 
2023-12-01 08:05:00 Traceback (most recent call last):
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/api/client.py", line 427, in _validate_tenant_database
2023-12-01 08:05:00     self._admin_client.get_tenant(name=tenant)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/api/client.py", line 472, in get_tenant
2023-12-01 08:05:00     return self._server.get_tenant(name=name)
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 127, in wrapper
2023-12-01 08:05:00     return f(*args, **kwargs)
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/api/fastapi.py", line 195, in get_tenant
2023-12-01 08:05:00     resp = self._session.get(
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 602, in get
2023-12-01 08:05:00     return self.request("GET", url, **kwargs)
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
2023-12-01 08:05:00     resp = self.send(prep, **send_kwargs)
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
2023-12-01 08:05:00     r = adapter.send(request, **kwargs)
2023-12-01 08:05:00         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 519, in send
2023-12-01 08:05:00     raise ConnectionError(e, request=request)
2023-12-01 08:05:00 requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6cc756f190>: Failed to establish a new connection: [Errno 111] Connection refused'))
2023-12-01 08:05:00 
2023-12-01 08:05:00 During handling of the above exception, another exception occurred:
2023-12-01 08:05:00 
2023-12-01 08:05:00 Traceback (most recent call last):
2023-12-01 08:05:00   File "/workspace/main.py", line 9, in <module>
2023-12-01 08:05:00     chroma_client = chromadb.HttpClient(host="localhost", port = 8001, settings=Settings(allow_reset=True, anonymized_telemetry=False))
2023-12-01 08:05:00                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/__init__.py", line 181, in HttpClient
2023-12-01 08:05:00     return ClientCreator(tenant=tenant, database=database, settings=settings)
2023-12-01 08:05:00            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/api/client.py", line 143, in __init__
2023-12-01 08:05:00     self._validate_tenant_database(tenant=tenant, database=database)
2023-12-01 08:05:00   File "/usr/local/lib/python3.11/site-packages/chromadb/api/client.py", line 429, in _validate_tenant_database
2023-12-01 08:05:00     raise ValueError(
2023-12-01 08:05:00 ValueError: Could not connect to a Chroma server. Are you sure it is running?

Solomin0 avatar Dec 01 '23 13:12 Solomin0

@Solomin0, in your main change your HttpClient to the following:

chroma_client = chromadb.HttpClient(host="chromaDB", port = 8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

tazarov avatar Dec 01 '23 14:12 tazarov

Same error, could it be a container issue where theyre starting out of order? I followed this demo and it still would not work. https://abhishektatachar.medium.com/run-chroma-db-on-a-local-machine-and-as-a-docker-container-a9d4b91d2a97

Solomin0 avatar Dec 01 '23 18:12 Solomin0

It could the execution order yes, you can use https://docs.docker.com/compose/startup-order/ in order to control this.

HammadB avatar Dec 04 '23 19:12 HammadB

@HammadB I have a similar problem with the official Docker image for ChromaDB 0.4.18. The containerized service is running before I try to connect to it.

docker run -d chromadb/chroma:0.4.18 
...
WARNING:  [07-12-2023 23:37:53] chroma_server_nofile is set to 65535, but this is less than current soft limit of 1048576. chroma_server_nofile will not be set.
INFO:     [07-12-2023 23:37:54] Anonymized telemetry enabled. See                     https://docs.trychroma.com/telemetry for more information.
DEBUG:    [07-12-2023 23:37:54] Starting component System
DEBUG:    [07-12-2023 23:37:54] Starting component OpenTelemetryClient
DEBUG:    [07-12-2023 23:37:54] Starting component SimpleAssignmentPolicy
DEBUG:    [07-12-2023 23:37:54] Starting component SqliteDB
DEBUG:    [07-12-2023 23:37:54] Starting component Posthog
DEBUG:    [07-12-2023 23:37:54] Starting component LocalSegmentManager
DEBUG:    [07-12-2023 23:37:54] Starting component SegmentAPI
INFO:     [07-12-2023 23:37:54] Started server process [12]
INFO:     [07-12-2023 23:37:54] Waiting for application startup.
INFO:     [07-12-2023 23:37:54] Application startup complete.
INFO:     [07-12-2023 23:37:54] Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

Then I try to execute this test code snippet:

import chromadb
from chromadb.config import Settings

client = chromadb.HttpClient(host='0.0.0.0', port=8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

print(client.heartbeat())

It then leaves me with the following error:



Traceback (most recent call last):
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/fastapi.py", line 628, in raise_chroma_error
    resp.raise_for_status()
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 503 Server Error: Service Unavailable for url: http://0.0.0.0:8000/api/v1/tenants/default_tenant

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/client.py", line 427, in _validate_tenant_database
    self._admin_client.get_tenant(name=tenant)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/client.py", line 472, in get_tenant
    return self._server.get_tenant(name=name)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 127, in wrapper
    return f(*args, **kwargs)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/fastapi.py", line 198, in get_tenant
    raise_chroma_error(resp)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/fastapi.py", line 630, in raise_chroma_error
    raise (Exception(resp.text))
Exception: <!doctype html>
<html>
<head>
<meta http-equiv="refresh" content="0;url=https://7rx90003.ibosscloud.com/ibreports/ibp/bp.html?bu=http://0.0.0.0:8000/api/v1/tenants/default_tenant&bc=Failed+to+retrieve+requested+URL.&ip=10.3.91.149&er=ERR_CONNECT_FAIL&amp;user=%2a10.3.91.149&amp;fn=Office+Users+%28Port+912%29&amp;fp=2&amp;cn="/>
</head>
<body>
</body>
</html>


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/code/intel-innersource/applications/ai/vision-platform/core/test.py", line 18, in <module>
    client = chromadb.HttpClient(host='0.0.0.0', port=8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/__init__.py", line 185, in HttpClient
    return ClientCreator(tenant=tenant, database=database, settings=settings)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/client.py", line 143, in __init__
    self._validate_tenant_database(tenant=tenant, database=database)
  File "/home/user/.venv/chromadb/lib/python3.10/site-packages/chromadb/api/client.py", line 433, in _validate_tenant_database
    raise ValueError(
ValueError: Could not connect to tenant default_tenant. Are you sure it exists?

asutic avatar Dec 07 '23 23:12 asutic

@asutic, it seems your error has to do with some proxy or firewall, judging by the HTML in your response. There may be a heartbeat operation that needs to succeed at least several times before Chroma is considered up and running.

tazarov avatar Dec 08 '23 06:12 tazarov

I have the same error. It was working on Python 3.9 until I migrated to python 3.10 and moved from sqlalchemy 1.4.x to latest

!Update! I solved the issue by rolling back the chromadb-client to v.0.4.15.dev0

uabbas avatar Dec 10 '23 16:12 uabbas

@tazarov thanks. After revisiting the issue, I'm able to establish connection with the ChromaDB service. It could be that in my case, I didn't start the service correctly when it comes to port mapping. But, once I run the container like below, the hearbeat operation succeeds.

docker run --name vector-db -d --rm -p 8000:8000 chromadb/chroma:0.4.18

asutic avatar Dec 12 '23 02:12 asutic

I had the same error with @asutic . My old project still running fine. After checking the version of library, my new project used chromadb version 0.4.20. I downgraded the version to 0.4.9 (like the version in my old project) and it ran fine.

tienmanh2208 avatar Dec 18 '23 04:12 tienmanh2208

@tienmanh2208, @asutic, there are some logging messages in the new code that did not make for nice developer experience especially when it comes to client/server compatibility. We are addressing this in #1494

tazarov avatar Dec 18 '23 15:12 tazarov

SOLVED

Not sure if anyone needs help but I was able to get around the startup issue by making sure my ChromaDB container pings its health and having my python container wait for it.

chromadb:
      image: chroma_server
      build: ./chroma
      healthcheck: 
        test: curl localhost:8000/api/v1/heartbeat || exit 1
        interval: 10s
        retries: 2
        start_period: 5s
        timeout: 10s


dev:
    image: dev
    build: nvcr.io/nvidia/pytorch:23.10-py3
    depends_on: 
        chromadb:
            condition: service_healthy

**The important part is installing curl in your docker image

Heres my chroma dockerfile. To ping the health check you do need to install curl.

FROM ghcr.io/chroma-core/chroma:latest RUN apt-get update -y && apt-get upgrade -y && apt install curl -y

Solomin0 avatar Dec 18 '23 18:12 Solomin0

Also getting this error:

ValueError: Could not connect to a Chroma server. Are you sure it is running?

I have two services: a Chroma service exposed on port 8000 and a Streamlit app exposing port 443. Was able to populate the Chroma database with a script once the container was running, however the Streamlit script returns errors when trying to connect with the server.

Things I tried:

  • Setting up a network and connecting both containers
  • Various configurations of settings in the HttpClient() class

Any luck with solving this problem in the past?

ccmilne avatar Feb 22 '24 18:02 ccmilne

In my case

client = chromadb.HttpClient(host='127.0.0.1', port=8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

print(client.heartbeat())

did work while this

client = chromadb.HttpClient(host='localhost', port=8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

print(client.heartbeat())

did not. Hope that helps

cgjedrem avatar Mar 13 '24 12:03 cgjedrem

@cgjedrem, some systems are configured with dual-stack, which makes localhost resolve to ::1 (ipv6) instead of the 127.0.0.1 (ipv4).

tazarov avatar Mar 15 '24 16:03 tazarov

@Solomin0, in your main change your HttpClient to the following:

chroma_client = chromadb.HttpClient(host="chromaDB", port = 8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

for me, this solution work, in docker-compose file of the author, chromadb service is named chromaDB, so when using python client to connect to server, the field host should be chromaDB

chroma_client = chromadb.HttpClient(host="chromaDB", port = 8000, settings=Settings(allow_reset=True, anonymized_telemetry=False))

Tamminhdiep97 avatar Mar 23 '24 14:03 Tamminhdiep97

Hi @Tamminhdiep97 , can I take a look at your docker-compose file? I still got this error, the only solution work for me is to pin down the chromadb and chromadb-client version and the docker chromadb as well.

cin-kay avatar Apr 01 '24 18:04 cin-kay

hi, @cin-kay here are my docker-compose file:

version: '3.5'
services:
  
  chatbot_engine:
    container_name: chatbot_engine
      # restart: always
    build:
      context: ../chatbot_util
      dockerfile: ../chatbot_util/Dockerfile
    image: chatbot_engine:dev
    environment:
      - PYTHONUNBUFFERED=1
      - TRANSFORMERS_CACHE=./cache/
    volumes:
      - ../document_data/:/document_data/
      - ../chatbot_util/:/chatbot_util/
      - ~/.cache/huggingface/hub:/cache/huggingface/hub
    command: python chatbot_util/gradio_ui.py
        # command: streamlit run streamlit_ui.py --server.port 7860
        # command: python chatbot_util/function_wrapper.py
    ports:
      - ${engine_port}:${engine_port}
    networks:
      - net
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]


  chatbot_PDFs_db:
    container_name: chatbot_document_db
    image: ghcr.io/chroma-core/chroma:latest
    volumes:
      - document_data:/chroma/.chroma/index
    ports:
      - ${chroma_port}
    networks:
      - net

volumes:
  document_data:
    driver: local
  backups:
    driver: local

networks:
  net:
    driver: bridge

Here are my code to connect to chromadb

chroma_client = chromadb.HttpClient(
                host='chatbot_PDFs_db',
                port=8000,
                settings=Settings(
                    allow_reset=True,
                    anonymized_telemetry=False
                )
            )

The Chroma db client in python code is version 0.4.24 Hope this help

Tamminhdiep97 avatar Apr 02 '24 08:04 Tamminhdiep97

SOLVED

  1. Chroma Deployment commands

       docker pull chromadb/chroma
       docker run -d -p 8000:8000 chromadb/chroma
    
  2. Access using the below snippet

       import chromadb
       chroma_client = chromadb.HttpClient(
           host=os.getenv("DB_HOST"),
           port=8000,
           settings=Settings(allow_reset=True, anonymized_telemetry=False),
       )
    

swapnilwagh2204 avatar May 04 '24 10:05 swapnilwagh2204

Hi, I am having a similar issue, despite having tried the different solutions proposed here I still get the following error:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 203, in _new_conn sock = connection.create_connection( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 60, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -3] Temporary failure in name resolution

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 496, in _make_request conn.request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 395, in request self.endheaders() File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output self.send(msg) File "/usr/lib/python3.10/http/client.py", line 976, in send self.connect() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 243, in connect self.sock = self._new_conn() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 210, in _new_conn raise NameResolutionError(self.host, self, e) from e urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='chromadb', port=8000): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 438, in _validate_tenant_database self._admin_client.get_tenant(name=tenant) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 486, in get_tenant return self._server.get_tenant(name=name) File "/usr/local/lib/python3.10/dist-packages/chromadb/telemetry/opentelemetry/init.py", line 143, in wrapper return f(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/fastapi.py", line 182, in get_tenant resp = self._session.get( File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 602, in get return self.request("GET", url, **kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='chromadb', port=8000): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/home/backend/server/main.py", line 77, in chroma_client = create_chroma_client() File "/root/home/backend/server/main.py", line 44, in create_chroma_client client = chromadb.HttpClient( File "/usr/local/lib/python3.10/dist-packages/chromadb/init.py", line 197, in HttpClient return ClientCreator(tenant=tenant, database=database, settings=settings) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 144, in init self._validate_tenant_database(tenant=tenant, database=database) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 440, in _validate_tenant_database raise ValueError( ValueError: Could not connect to a Chroma server. Are you sure it is running?

The docker compose file looks like this:

services:
  backend:
    build:
      context: .
      dockerfile: ./backend/Dockerfile
      target: development
    env_file:
      - .env
    ports:
      - "6000:6000" # Backend is accessible on localhost:8100
    stdin_open: true
    tty: true
    entrypoint: /bin/bash
    links:
      - chromadb
    depends_on:
      chromadb:
        condition: service_healthy
    volumes:
      - ${LOCAL_PATH}/backend:${CONTAINER_PATH}/backend
      - ${LOCAL_PATH}/data:${CONTAINER_PATH}/data

  chromadb:
    image: ghcr.io/chroma-core/chroma:latest
    container_name: chromadb
    ports:
      - "8000:8000"
    volumes:
      - ./data/chroma_data/:/chroma/chroma
    restart: always
    healthcheck:
      test: curl http://localhost:8000/api/v1/heartbeat || exit 1
      interval: 30s
      timeout: 30s
      retries: 2
      start_period: 5s
    networks:
      - llm_network

networks:
  llm_network:
    driver: bridge

and the python code I used is the following: client = chromadb.HttpClient( host='chromadb', port=8000, settings=Settings( allow_reset=True, anonymized_telemetry=False ) )

Do you have nay suggestions on how to solve the issue?

albert-queralto avatar May 30 '24 14:05 albert-queralto

@albert-queralto the config for chromadb seems to be a bit redundant to me, you can remove all the healthcheck and restart stuffs and it still can work btw, could you try to add the llm_network to the backend service to ensure both services are on the same network?

cin-kay avatar May 30 '24 14:05 cin-kay

Hi, I am having a similar issue, despite having tried the different solutions proposed here I still get the following error:

Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 203, in _new_conn sock = connection.create_connection( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/connection.py", line 60, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -3] Temporary failure in name resolution The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 496, in _make_request conn.request( File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 395, in request self.endheaders() File "/usr/lib/python3.10/http/client.py", line 1278, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.10/http/client.py", line 1038, in _send_output self.send(msg) File "/usr/lib/python3.10/http/client.py", line 976, in send self.connect() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 243, in connect self.sock = self._new_conn() File "/usr/local/lib/python3.10/dist-packages/urllib3/connection.py", line 210, in _new_conn raise NameResolutionError(self.host, self, e) from e urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( File "/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/usr/local/lib/python3.10/dist-packages/urllib3/util/retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='chromadb', port=8000): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution)")) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 438, in _validate_tenant_database self._admin_client.get_tenant(name=tenant) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 486, in get_tenant return self._server.get_tenant(name=name) File "/usr/local/lib/python3.10/dist-packages/chromadb/telemetry/opentelemetry/init.py", line 143, in wrapper return f(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/fastapi.py", line 182, in get_tenant resp = self._session.get( File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 602, in get return self.request("GET", url, **kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.10/dist-packages/requests/adapters.py", line 519, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPConnectionPool(host='chromadb', port=8000): Max retries exceeded with url: /api/v1/tenants/default_tenant (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f237a3c9e10>: Failed to resolve 'chromadb' ([Errno -3] Temporary failure in name resolution)")) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/home/backend/server/main.py", line 77, in chroma_client = create_chroma_client() File "/root/home/backend/server/main.py", line 44, in create_chroma_client client = chromadb.HttpClient( File "/usr/local/lib/python3.10/dist-packages/chromadb/init.py", line 197, in HttpClient return ClientCreator(tenant=tenant, database=database, settings=settings) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 144, in init self._validate_tenant_database(tenant=tenant, database=database) File "/usr/local/lib/python3.10/dist-packages/chromadb/api/client.py", line 440, in _validate_tenant_database raise ValueError( ValueError: Could not connect to a Chroma server. Are you sure it is running?

The docker compose file looks like this:

services:
  backend:
    build:
      context: .
      dockerfile: ./backend/Dockerfile
      target: development
    env_file:
      - .env
    ports:
      - "6000:6000" # Backend is accessible on localhost:8100
    stdin_open: true
    tty: true
    entrypoint: /bin/bash
    links:
      - chromadb
    depends_on:
      chromadb:
        condition: service_healthy
    volumes:
      - ${LOCAL_PATH}/backend:${CONTAINER_PATH}/backend
      - ${LOCAL_PATH}/data:${CONTAINER_PATH}/data

  chromadb:
    image: ghcr.io/chroma-core/chroma:latest
    container_name: chromadb
    ports:
      - "8000:8000"
    volumes:
      - ./data/chroma_data/:/chroma/chroma
    restart: always
    healthcheck:
      test: curl http://localhost:8000/api/v1/heartbeat || exit 1
      interval: 30s
      timeout: 30s
      retries: 2
      start_period: 5s
    networks:
      - llm_network

networks:
  llm_network:
    driver: bridge

and the python code I used is the following: client = chromadb.HttpClient( host='chromadb', port=8000, settings=Settings( allow_reset=True, anonymized_telemetry=False ) )

Do you have nay suggestions on how to solve the issue?

hi @albert-queralto, could you add a field network to your backend services and restart your container?

something like this:

    networks:
      - llm_network
    

Tamminhdiep97 avatar May 30 '24 14:05 Tamminhdiep97

Thanks a lot to both @cin-kay and @Tamminhdiep97, the problem was exactly the missing networks in the backend service.

albert-queralto avatar May 31 '24 06:05 albert-queralto

For Gosh sake, it works locally, but not remotely, it is bipolar over here

aspirina765 avatar Aug 09 '24 20:08 aspirina765

I was able to solve it by using the links parameter, using chromadb==0.5.5 and by adding a healthcheck. For reference my compose file looks like this """ version: '3.9'

services: cdb: image: ghcr.io/chroma-core/chroma:latest container_name: CDB ports: - "8000:8000" volumes: - /app/chroma_data:/chroma/.chroma/index networks: - ai_net healthcheck: test: curl http://localhost:8000/api/v1/heartbeat || exit 1 interval: 30s timeout: 30s retries: 2 start_period: 5s

pps: build: context: /app/pps dockerfile: Dockerfile image: pps:dev container_name: PPS ports: - "5002:5002" volumes: - /app/logs/pps:/app/logs environment: - PYTHONUNBUFFERED=1 env_file: - /app/pps/.env networks: - ai_net

ppa: build: context: /app/ppa dockerfile: Dockerfile image: ppa:dev container_name: PPA ports: - "5003:5003" volumes: - /app/logs/ppa:/app/logs - /app/chroma_data:/app/chroma_data environment: - PYTHONUNBUFFERED=1 env_file: - /app/ppa/.env links: - cdb depends_on: cdb: condition: service_healthy networks: - ai_net

networks: ai_net: driver: bridge """ and my command in the python code is as follows: """ import os from dotenv import load_dotenv import chromadb from chromadb.config import Settings load_dotenv(override = True)

chroma_host = os.getenv('CHROMA_HOST', 'localhost') # Default to 'localhost' if not set chroma_client = chromadb.HttpClient(host=chroma_host, port = 8000, settings=Settings(allow_reset=True, anonymized_telemetry=False)) """ and finally add this variable to the .env file and it should work """ CHROMA_HOST=cdb """

I used the service name as cdb which acts like a DNS in docker network, also adding the healthcheck added a delay in creating my ppa service which depends on the chromadb. Hope it helps someone!

faizan-certainti avatar Aug 21 '24 12:08 faizan-certainti