From 56fc11a99cc7af040a08c4cb0b8cc240c8688a4e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 28 May 2024 08:16:37 -0700 Subject: [PATCH] feat: Update ChromaSearch and ChromaComponent to use chromadb library (#1992) The code changes in `ChromaSearch.py` and `Chroma.py` import the `chromadb` library and use it to create a `HttpClient` object. This change enables the components to interact with a Chroma server for vector search functionality. This commit message follows the established convention of starting with a type (feat for feature) and providing a concise summary of the changes. --- .../base/langflow/components/vectorsearch/ChromaSearch.py | 6 ++++-- .../base/langflow/components/vectorstores/Chroma.py | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/components/vectorsearch/ChromaSearch.py b/src/backend/base/langflow/components/vectorsearch/ChromaSearch.py index 0046063d1..228e100e4 100644 --- a/src/backend/base/langflow/components/vectorsearch/ChromaSearch.py +++ b/src/backend/base/langflow/components/vectorsearch/ChromaSearch.py @@ -1,5 +1,6 @@ from typing import List, Optional +import chromadb from chromadb.config import Settings from langchain_chroma import Chroma @@ -91,7 +92,7 @@ class ChromaSearchComponent(LCVectorStoreComponent): # Chroma settings chroma_settings = None - + client = None if chroma_server_host is not None: chroma_settings = Settings( chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or [], @@ -100,13 +101,14 @@ class ChromaSearchComponent(LCVectorStoreComponent): chroma_server_grpc_port=chroma_server_grpc_port or None, chroma_server_ssl_enabled=chroma_server_ssl_enabled, ) + client = chromadb.HttpClient(settings=chroma_settings) if index_directory: index_directory = self.resolve_path(index_directory) vector_store = Chroma( embedding_function=embedding, collection_name=collection_name, persist_directory=index_directory, - client_settings=chroma_settings, + client=client, ) return self.search_with_vector_store(input_value, search_type, vector_store, k=number_of_results) diff --git a/src/backend/base/langflow/components/vectorstores/Chroma.py b/src/backend/base/langflow/components/vectorstores/Chroma.py index 9683d7a98..3671dbbdb 100644 --- a/src/backend/base/langflow/components/vectorstores/Chroma.py +++ b/src/backend/base/langflow/components/vectorstores/Chroma.py @@ -1,5 +1,6 @@ from typing import List, Optional, Union +import chromadb from chromadb.config import Settings from langchain_chroma import Chroma from langchain_core.embeddings import Embeddings @@ -81,7 +82,7 @@ class ChromaComponent(CustomComponent): # Chroma settings chroma_settings = None - + client = None if chroma_server_host is not None: chroma_settings = Settings( chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or [], @@ -90,6 +91,7 @@ class ChromaComponent(CustomComponent): chroma_server_grpc_port=chroma_server_grpc_port or None, chroma_server_ssl_enabled=chroma_server_ssl_enabled, ) + client = chromadb.HttpClient(settings=chroma_settings) # If documents, then we need to create a Chroma instance using .from_documents @@ -111,12 +113,12 @@ class ChromaComponent(CustomComponent): persist_directory=index_directory, collection_name=collection_name, embedding=embedding, - client_settings=chroma_settings, + client=client, ) else: chroma = Chroma( persist_directory=index_directory, - client_settings=chroma_settings, + client=client, embedding_function=embedding, ) return chroma