Skip to content

Commit

Permalink
feat: Update ChromaSearch and ChromaComponent to use chromadb library (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
ogabrielluiz authored May 28, 2024
1 parent 1a4b895 commit 56fc11a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List, Optional

import chromadb
from chromadb.config import Settings
from langchain_chroma import Chroma

Expand Down Expand Up @@ -91,7 +92,7 @@ def build(

# 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 [],
Expand All @@ -100,13 +101,14 @@ def build(
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)
8 changes: 5 additions & 3 deletions src/backend/base/langflow/components/vectorstores/Chroma.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -81,7 +82,7 @@ def build(

# 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 [],
Expand All @@ -90,6 +91,7 @@ def build(
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

Expand All @@ -111,12 +113,12 @@ def build(
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

0 comments on commit 56fc11a

Please sign in to comment.