Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions libs/partners/chroma/langchain_chroma/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from __future__ import annotations

import base64
import inspect
import logging
import uuid
from collections.abc import Callable, Iterable, Sequence
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions libs/partners/chroma/tests/unit_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import chromadb
import pytest
from langchain_core.embeddings.fake import (
FakeEmbeddings,
)
Expand Down Expand Up @@ -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()
Loading