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.
This commit is contained in:
parent
1a4b895509
commit
56fc11a99c
2 changed files with 9 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
import chromadb
|
||||||
from chromadb.config import Settings
|
from chromadb.config import Settings
|
||||||
from langchain_chroma import Chroma
|
from langchain_chroma import Chroma
|
||||||
|
|
||||||
|
|
@ -91,7 +92,7 @@ class ChromaSearchComponent(LCVectorStoreComponent):
|
||||||
|
|
||||||
# Chroma settings
|
# Chroma settings
|
||||||
chroma_settings = None
|
chroma_settings = None
|
||||||
|
client = None
|
||||||
if chroma_server_host is not None:
|
if chroma_server_host is not None:
|
||||||
chroma_settings = Settings(
|
chroma_settings = Settings(
|
||||||
chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or [],
|
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_grpc_port=chroma_server_grpc_port or None,
|
||||||
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
|
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
|
||||||
)
|
)
|
||||||
|
client = chromadb.HttpClient(settings=chroma_settings)
|
||||||
if index_directory:
|
if index_directory:
|
||||||
index_directory = self.resolve_path(index_directory)
|
index_directory = self.resolve_path(index_directory)
|
||||||
vector_store = Chroma(
|
vector_store = Chroma(
|
||||||
embedding_function=embedding,
|
embedding_function=embedding,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
persist_directory=index_directory,
|
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)
|
return self.search_with_vector_store(input_value, search_type, vector_store, k=number_of_results)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
|
import chromadb
|
||||||
from chromadb.config import Settings
|
from chromadb.config import Settings
|
||||||
from langchain_chroma import Chroma
|
from langchain_chroma import Chroma
|
||||||
from langchain_core.embeddings import Embeddings
|
from langchain_core.embeddings import Embeddings
|
||||||
|
|
@ -81,7 +82,7 @@ class ChromaComponent(CustomComponent):
|
||||||
|
|
||||||
# Chroma settings
|
# Chroma settings
|
||||||
chroma_settings = None
|
chroma_settings = None
|
||||||
|
client = None
|
||||||
if chroma_server_host is not None:
|
if chroma_server_host is not None:
|
||||||
chroma_settings = Settings(
|
chroma_settings = Settings(
|
||||||
chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or [],
|
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_grpc_port=chroma_server_grpc_port or None,
|
||||||
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
|
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
|
# If documents, then we need to create a Chroma instance using .from_documents
|
||||||
|
|
||||||
|
|
@ -111,12 +113,12 @@ class ChromaComponent(CustomComponent):
|
||||||
persist_directory=index_directory,
|
persist_directory=index_directory,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
embedding=embedding,
|
embedding=embedding,
|
||||||
client_settings=chroma_settings,
|
client=client,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
chroma = Chroma(
|
chroma = Chroma(
|
||||||
persist_directory=index_directory,
|
persist_directory=index_directory,
|
||||||
client_settings=chroma_settings,
|
client=client,
|
||||||
embedding_function=embedding,
|
embedding_function=embedding,
|
||||||
)
|
)
|
||||||
return chroma
|
return chroma
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue