diff --git a/libs/partners/chroma/langchain_chroma/vectorstores.py b/libs/partners/chroma/langchain_chroma/vectorstores.py index c6754516bb470..3aa9369d30258 100644 --- a/libs/partners/chroma/langchain_chroma/vectorstores.py +++ b/libs/partners/chroma/langchain_chroma/vectorstores.py @@ -6,6 +6,7 @@ from __future__ import annotations import base64 +import inspect import logging import uuid from collections.abc import Callable, Iterable, Sequence @@ -367,6 +368,15 @@ def __init__( raise ValueError(msg) if client is not None: + if inspect.isawaitable(client): + msg = ( + "`client` must be a synchronous Chroma client implementing " + "`chromadb.ClientAPI`. Got an awaitable instead, which usually " + "means `chromadb.AsyncHttpClient(...)` was passed in. Use " + "`chromadb.HttpClient(...)` or another synchronous client " + "instance instead." + ) + raise TypeError(msg) self._client = client # PersistentClient diff --git a/libs/partners/chroma/tests/unit_tests/test_vectorstores.py b/libs/partners/chroma/tests/unit_tests/test_vectorstores.py index 66ac3b0622465..ec0c05de483b9 100644 --- a/libs/partners/chroma/tests/unit_tests/test_vectorstores.py +++ b/libs/partners/chroma/tests/unit_tests/test_vectorstores.py @@ -1,3 +1,5 @@ +import chromadb +import pytest from langchain_core.embeddings.fake import ( FakeEmbeddings, ) @@ -28,3 +30,13 @@ def test_similarity_search() -> None: output = docsearch.similarity_search("foo", k=1) docsearch.delete_collection() assert len(output) == 1 + + +def test_async_http_client_rejected() -> None: + """Chroma should fail fast when given an async Chroma client.""" + client = chromadb.AsyncHttpClient(host="localhost", port=8000) + + with pytest.raises(TypeError, match="must be a synchronous Chroma client"): + Chroma(client=client) + + client.close()