From 6e29bdd932c605ade1da007a208263c735b55b36 Mon Sep 17 00:00:00 2001 From: lakshayCogniq Date: Mon, 13 Apr 2026 00:09:00 -0400 Subject: [PATCH 1/2] Reject async Chroma clients in vectorstore --- .../chroma/langchain_chroma/vectorstores.py | 15 +++++++++++++++ .../chroma/tests/unit_tests/test_vectorstores.py | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libs/partners/chroma/langchain_chroma/vectorstores.py b/libs/partners/chroma/langchain_chroma/vectorstores.py index c6754516bb470..00e8c92044b20 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 @@ -152,6 +153,19 @@ def maximal_marginal_relevance( return idxs +def _validate_client(client: chromadb.ClientAPI | Any) -> None: + """Reject async clients with an actionable error message.""" + if inspect.isawaitable(client): + msg = ( + "`langchain_chroma.Chroma` requires a synchronous Chroma client. " + "Received an awaitable client, which usually means " + "`chromadb.AsyncHttpClient(...)` was passed in. Use " + "`chromadb.HttpClient(...)` or another synchronous `chromadb.ClientAPI` " + "instance instead." + ) + raise TypeError(msg) + + class Chroma(VectorStore): """Chroma vector store integration. @@ -367,6 +381,7 @@ def __init__( raise ValueError(msg) if client is not None: + _validate_client(client) 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..e9a0ea403b698 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="requires a synchronous Chroma client"): + Chroma(client=client) + + client.close() From 7b3dfca8f019c8c2c33c34edcaac375bc04326ad Mon Sep 17 00:00:00 2001 From: lakshayCogniq Date: Mon, 13 Apr 2026 00:12:40 -0400 Subject: [PATCH 2/2] fix(chroma): align async client validation with local style --- .../chroma/langchain_chroma/vectorstores.py | 23 ++++++++----------- .../tests/unit_tests/test_vectorstores.py | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/libs/partners/chroma/langchain_chroma/vectorstores.py b/libs/partners/chroma/langchain_chroma/vectorstores.py index 00e8c92044b20..3aa9369d30258 100644 --- a/libs/partners/chroma/langchain_chroma/vectorstores.py +++ b/libs/partners/chroma/langchain_chroma/vectorstores.py @@ -153,19 +153,6 @@ def maximal_marginal_relevance( return idxs -def _validate_client(client: chromadb.ClientAPI | Any) -> None: - """Reject async clients with an actionable error message.""" - if inspect.isawaitable(client): - msg = ( - "`langchain_chroma.Chroma` requires a synchronous Chroma client. " - "Received an awaitable client, which usually means " - "`chromadb.AsyncHttpClient(...)` was passed in. Use " - "`chromadb.HttpClient(...)` or another synchronous `chromadb.ClientAPI` " - "instance instead." - ) - raise TypeError(msg) - - class Chroma(VectorStore): """Chroma vector store integration. @@ -381,7 +368,15 @@ def __init__( raise ValueError(msg) if client is not None: - _validate_client(client) + 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 e9a0ea403b698..ec0c05de483b9 100644 --- a/libs/partners/chroma/tests/unit_tests/test_vectorstores.py +++ b/libs/partners/chroma/tests/unit_tests/test_vectorstores.py @@ -36,7 +36,7 @@ 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="requires a synchronous Chroma client"): + with pytest.raises(TypeError, match="must be a synchronous Chroma client"): Chroma(client=client) client.close()