mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 08:57:31 +08:00
fix(chroma): replace deprecated Client(settings=) with HttpClient for chromadb >=1.0 (#12900)
* fix(chroma): replace deprecated Client(settings=) with HttpClient for chromadb >=1.0 On chromadb 1.0+, `chromadb.Client(settings=Settings(chroma_server_host=...))` silently creates a local in-memory ephemeral database instead of connecting to the configured remote server. This caused the Chroma DB component to always return empty results (`dataframe: []`) when pointing at a remote ChromaDB server. Replace the deprecated `Client(settings=...)` call with `chromadb.HttpClient()` which is the correct API for connecting to a remote ChromaDB HTTP server. Also update component_index.json with the fixed component code and recomputed sha256. Fixes #12665 Co-Authored-By: Octopus <liyuan851277048@icloud.com> * Update component_index.json * Update test_chroma_vector_store_component.py * [autofix.ci] apply automated fixes --------- Co-authored-by: octo-patch <octo-patch@github.com> Co-authored-by: Octopus <liyuan851277048@icloud.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,5 +1,6 @@
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from lfx.components.chroma import ChromaVectorStoreComponent
|
||||
@ -8,6 +9,37 @@ from lfx.schema.data import Data
|
||||
from tests.base import ComponentTestBaseWithoutClient, VersionComponentMapping
|
||||
|
||||
|
||||
def test_remote_chroma_server_uses_http_client() -> None:
|
||||
mock_client = MagicMock()
|
||||
mock_chroma = MagicMock()
|
||||
mock_chroma.get.return_value = {"ids": [], "documents": [], "metadatas": []}
|
||||
|
||||
with (
|
||||
patch("chromadb.HttpClient", return_value=mock_client) as mock_http_client,
|
||||
patch("langchain_chroma.Chroma", return_value=mock_chroma) as mock_chroma_class,
|
||||
):
|
||||
component = ChromaVectorStoreComponent().set(
|
||||
collection_name="remote_collection",
|
||||
persist_directory=None,
|
||||
embedding=None,
|
||||
chroma_server_host="chroma.example.com",
|
||||
chroma_server_http_port=8100,
|
||||
chroma_server_ssl_enabled=True,
|
||||
ingest_data=[],
|
||||
limit=None,
|
||||
)
|
||||
|
||||
assert component.build_vector_store() is mock_chroma
|
||||
|
||||
mock_http_client.assert_called_once_with(host="chroma.example.com", port=8100, ssl=True)
|
||||
mock_chroma_class.assert_called_once_with(
|
||||
persist_directory=None,
|
||||
client=mock_client,
|
||||
embedding_function=None,
|
||||
collection_name="remote_collection",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.api_key_required
|
||||
class TestChromaVectorStoreComponent(ComponentTestBaseWithoutClient):
|
||||
@pytest.fixture
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -1,7 +1,6 @@
|
||||
from copy import deepcopy
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from chromadb.config import Settings
|
||||
from langchain_chroma import Chroma
|
||||
from typing_extensions import override
|
||||
|
||||
@ -92,23 +91,22 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
|
||||
def build_vector_store(self) -> Chroma:
|
||||
"""Builds the Chroma object."""
|
||||
try:
|
||||
from chromadb import Client
|
||||
from langchain_chroma import Chroma
|
||||
except ImportError as e:
|
||||
msg = "Could not import Chroma integration package. Please install it with `pip install langchain-chroma`."
|
||||
raise ImportError(msg) from e
|
||||
# Chroma settings
|
||||
chroma_settings = None
|
||||
client = None
|
||||
if self.chroma_server_host:
|
||||
chroma_settings = Settings(
|
||||
chroma_server_cors_allow_origins=self.chroma_server_cors_allow_origins or [],
|
||||
chroma_server_host=self.chroma_server_host,
|
||||
chroma_server_http_port=self.chroma_server_http_port or None,
|
||||
chroma_server_grpc_port=self.chroma_server_grpc_port or None,
|
||||
chroma_server_ssl_enabled=self.chroma_server_ssl_enabled,
|
||||
try:
|
||||
from chromadb import HttpClient
|
||||
except ImportError as e:
|
||||
msg = "Could not import chromadb. Please install it with `pip install chromadb`."
|
||||
raise ImportError(msg) from e
|
||||
client = HttpClient(
|
||||
host=self.chroma_server_host,
|
||||
port=self.chroma_server_http_port or 8000,
|
||||
ssl=bool(self.chroma_server_ssl_enabled),
|
||||
)
|
||||
client = Client(settings=chroma_settings)
|
||||
|
||||
# Check persist_directory and expand it if it is a relative path
|
||||
persist_directory = self.resolve_path(self.persist_directory) if self.persist_directory is not None else None
|
||||
|
||||
Reference in New Issue
Block a user