feat: tool mode for all vector store components (#5348)

* feat: tool mode for all vector store components

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* Update elasticsearch.py

* Update test_vector_store_rag.py

* Update vector_store_rag.py

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Eric Hare 2024-12-19 08:49:09 -08:00 • committed by GitHub
commit 22877ae920
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 412 additions and 572 deletions

View file

@ -2,12 +2,10 @@ from abc import abstractmethod
from functools import wraps from functools import wraps
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from loguru import logger
from langflow.custom import Component from langflow.custom import Component
from langflow.field_typing import Text, VectorStore from langflow.field_typing import Text, VectorStore
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import Output from langflow.io import DataInput, MultilineInput, Output
from langflow.schema import Data from langflow.schema import Data
if TYPE_CHECKING: if TYPE_CHECKING:
@ -53,6 +51,19 @@ class LCVectorStoreComponent(Component):
raise TypeError(msg) raise TypeError(msg)
trace_type = "retriever" trace_type = "retriever"
inputs = [
MultilineInput(
name="search_query",
display_name="Search Query",
tool_mode=True,
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
),
]
outputs = [ outputs = [
Output( Output(
display_name="Search Results", display_name="Search Results",
@ -122,9 +133,9 @@ class LCVectorStoreComponent(Component):
vector_store = self.build_vector_store() vector_store = self.build_vector_store()
self._cached_vector_store = vector_store self._cached_vector_store = vector_store
logger.debug(f"Search input: {search_query}") self.log(f"Search input: {search_query}")
logger.debug(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
search_results = self.search_with_vector_store( search_results = self.search_with_vector_store(
search_query, self.search_type, vector_store, k=self.number_of_results search_query, self.search_type, vector_store, k=self.number_of_results

View file

@ -1,7 +1,7 @@
import os import os
from collections import defaultdict from collections import defaultdict
from astrapy import DataAPIClient from astrapy import AstraDBAdmin, DataAPIClient
from astrapy.admin import parse_api_endpoint from astrapy.admin import parse_api_endpoint
from langchain_astradb import AstraDBVectorStore from langchain_astradb import AstraDBVectorStore
@ -14,7 +14,6 @@ from langflow.io import (
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -24,52 +23,29 @@ from langflow.utils.version import get_version_info
class AstraDBVectorStoreComponent(LCVectorStoreComponent): class AstraDBVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Astra DB" display_name: str = "Astra DB"
description: str = "Implementation of Vector Store using Astra DB with search capabilities" description: str = "Ingest and search documents in Astra DB"
documentation: str = "https://docs.langflow.org/starter-projects-vector-store-rag" documentation: str = "https://docs.datastax.com/en/langflow/astra-components.html"
name = "AstraDB" name = "AstraDB"
icon: str = "AstraDB" icon: str = "AstraDB"
_cached_vector_store: AstraDBVectorStore | None = None _cached_vector_store: AstraDBVectorStore | None = None
VECTORIZE_PROVIDERS_MAPPING = defaultdict( base_inputs = LCVectorStoreComponent.inputs
list, if "search_query" not in [input_.name for input_ in base_inputs]:
{ base_inputs.append(
"Azure OpenAI": [ MessageTextInput(
"azureOpenAI", name="search_query",
["text-embedding-3-small", "text-embedding-3-large", "text-embedding-ada-002"], display_name="Search Query",
], tool_mode=True,
"Hugging Face - Dedicated": ["huggingfaceDedicated", ["endpoint-defined-model"]], )
"Hugging Face - Serverless": [ )
"huggingface", if "ingest_data" not in [input_.name for input_ in base_inputs]:
[ base_inputs.append(
"sentence-transformers/all-MiniLM-L6-v2", DataInput(
"intfloat/multilingual-e5-large", name="ingest_data",
"intfloat/multilingual-e5-large-instruct", display_name="Ingest Data",
"BAAI/bge-small-en-v1.5", )
"BAAI/bge-base-en-v1.5", )
"BAAI/bge-large-en-v1.5",
],
],
"Jina AI": [
"jinaAI",
[
"jina-embeddings-v2-base-en",
"jina-embeddings-v2-base-de",
"jina-embeddings-v2-base-es",
"jina-embeddings-v2-base-code",
"jina-embeddings-v2-base-zh",
],
],
"Mistral AI": ["mistral", ["mistral-embed"]],
"Nvidia": ["nvidia", ["NV-Embed-QA"]],
"OpenAI": ["openai", ["text-embedding-3-small", "text-embedding-3-large", "text-embedding-ada-002"]],
"Upstage": ["upstageAI", ["solar-embedding-1-large"]],
"Voyage AI": [
"voyageAI",
["voyage-large-2-instruct", "voyage-law-2", "voyage-code-2", "voyage-large-2", "voyage-2"],
],
},
)
inputs = [ inputs = [
SecretStrInput( SecretStrInput(
@ -81,13 +57,15 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
advanced=os.getenv("ASTRA_ENHANCED", "false").lower() == "true", advanced=os.getenv("ASTRA_ENHANCED", "false").lower() == "true",
real_time_refresh=True, real_time_refresh=True,
), ),
SecretStrInput( DropdownInput(
name="api_endpoint", name="api_endpoint",
display_name="Database" if os.getenv("ASTRA_ENHANCED", "false").lower() == "true" else "API Endpoint", display_name="Database",
info="API endpoint URL for the Astra DB service.", info="The Astra DB Database to use.",
value="ASTRA_DB_API_ENDPOINT",
required=True, required=True,
refresh_button=True,
real_time_refresh=True, real_time_refresh=True,
options=["Default database"],
value="Default database",
), ),
DropdownInput( DropdownInput(
name="collection_name", name="collection_name",
@ -126,15 +104,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
input_types=["Embeddings"], input_types=["Embeddings"],
info="Allows an embedding model configuration.", info="Allows an embedding model configuration.",
), ),
DataInput( *base_inputs,
name="ingest_data",
display_name="Ingest Data",
),
MultilineInput(
name="search_input",
display_name="Search Query",
tool_mode=True,
),
IntInput( IntInput(
name="number_of_results", name="number_of_results",
display_name="Number of Search Results", display_name="Number of Search Results",
@ -212,26 +182,18 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
return build_config return build_config
def update_providers_mapping(self): def get_vectorize_providers(self):
# If we don't have token or api_endpoint, we can't fetch the list of providers
if not self.token or not self.api_endpoint:
self.log("Astra DB token and API endpoint are required to fetch the list of Vectorize providers.")
return self.VECTORIZE_PROVIDERS_MAPPING
try: try:
self.log("Dynamically updating list of Vectorize providers.") self.log("Dynamically updating list of Vectorize providers.")
# Get the admin object # Get the admin object
client = DataAPIClient(token=self.token) admin = AstraDBAdmin(token=self.token)
admin = client.get_admin() db_admin = admin.get_database_admin(self.get_api_endpoint())
# Get the embedding providers # Get the list of embedding providers
db_admin = admin.get_database_admin(self.api_endpoint)
embedding_providers = db_admin.find_embedding_providers().as_dict() embedding_providers = db_admin.find_embedding_providers().as_dict()
vectorize_providers_mapping = {} vectorize_providers_mapping = {}
# Map the provider display name to the provider key and models # Map the provider display name to the provider key and models
for provider_key, provider_data in embedding_providers["embeddingProviders"].items(): for provider_key, provider_data in embedding_providers["embeddingProviders"].items():
display_name = provider_data["displayName"] display_name = provider_data["displayName"]
@ -244,14 +206,37 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
except Exception as e: # noqa: BLE001 except Exception as e: # noqa: BLE001
self.log(f"Error fetching Vectorize providers: {e}") self.log(f"Error fetching Vectorize providers: {e}")
return self.VECTORIZE_PROVIDERS_MAPPING return {}
def get_database_list(self):
# Get the admin object
db_admin = AstraDBAdmin(token=self.token)
db_list = list(db_admin.list_databases())
# Generate the api endpoint for each database
return {db.info.name: f"https://{db.info.id}-{db.info.region}.apps.astra.datastax.com" for db in db_list}
def get_api_endpoint(self):
# Get the database name (or endpoint)
database = self.api_endpoint
# If the database is not set, get the first database in the list
if not database or database == "Default database":
database, _ = next(iter(self.get_database_list().items()))
# If the database is a URL, return it
if database.startswith("https://"):
return database
# Otherwise, get the URL from the database list
return self.get_database_list().get(database)
def get_database(self): def get_database(self):
try: try:
client = DataAPIClient(token=self.token) client = DataAPIClient(token=self.token)
return client.get_database( return client.get_database(
self.api_endpoint, api_endpoint=self.get_api_endpoint(),
token=self.token, token=self.token,
) )
except Exception as e: # noqa: BLE001 except Exception as e: # noqa: BLE001
@ -259,13 +244,25 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
return None return None
def _initialize_database_options(self):
if not self.token:
return ["Default database"]
try:
databases = ["Default database", *list(self.get_database_list().keys())]
except Exception as e: # noqa: BLE001
self.log(f"Error fetching databases: {e}")
return ["Default database"]
return databases
def _initialize_collection_options(self): def _initialize_collection_options(self):
database = self.get_database() database = self.get_database()
if database is None: if database is None:
return ["+ Create new collection"] return ["+ Create new collection"]
try: try:
collections = [collection.name for collection in database.list_collections()] collections = [collection.name for collection in database.list_collections(keyspace=self.keyspace or None)]
except Exception as e: # noqa: BLE001 except Exception as e: # noqa: BLE001
self.log(f"Error fetching collections: {e}") self.log(f"Error fetching collections: {e}")
@ -289,7 +286,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
collection_name = self.get_collection_choice() collection_name = self.get_collection_choice()
try: try:
collection = database.get_collection(collection_name) collection = database.get_collection(collection_name, keyspace=self.keyspace or None)
collection_options = collection.options() collection_options = collection.options()
except Exception as _: # noqa: BLE001 except Exception as _: # noqa: BLE001
return None return None
@ -297,8 +294,17 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
return collection_options.vector return collection_options.vector
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None): def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):
# Refresh the collection name options # Always attempt to update the database list
build_config["collection_name"]["options"] = self._initialize_collection_options() if field_name in ["token", "api_endpoint", "collection_name"]:
# Update the database selector
build_config["api_endpoint"]["options"] = self._initialize_database_options()
# Set the default API endpoint if not set
if build_config["api_endpoint"]["value"] == "Default database":
build_config["api_endpoint"]["value"] = build_config["api_endpoint"]["options"][0]
# Update the collection selector
build_config["collection_name"]["options"] = self._initialize_collection_options()
# Update the choice of embedding model based on collection name # Update the choice of embedding model based on collection name
if field_name == "collection_name": if field_name == "collection_name":
@ -368,7 +374,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
build_config["embedding_model"]["advanced"] = True build_config["embedding_model"]["advanced"] = True
# Update the providers mapping # Update the providers mapping
vectorize_providers = self.update_providers_mapping() vectorize_providers = self.get_vectorize_providers()
new_parameter = DropdownInput( new_parameter = DropdownInput(
name="embedding_provider", name="embedding_provider",
@ -402,7 +408,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
) )
# Update the providers mapping # Update the providers mapping
vectorize_providers = self.update_providers_mapping() vectorize_providers = self.get_vectorize_providers()
model_options = vectorize_providers[field_value][1] model_options = vectorize_providers[field_value][1]
new_parameter = DropdownInput( new_parameter = DropdownInput(
@ -481,7 +487,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
setattr(self, attribute, None) setattr(self, attribute, None)
# Fetch values from kwargs if any self.* attributes are None # Fetch values from kwargs if any self.* attributes are None
provider_mapping = self.update_providers_mapping() provider_mapping = self.get_vectorize_providers()
provider_value = provider_mapping.get(self.embedding_provider, [None])[0] or kwargs.get("embedding_provider") provider_value = provider_mapping.get(self.embedding_provider, [None])[0] or kwargs.get("embedding_provider")
model_name = self.model or kwargs.get("model") model_name = self.model or kwargs.get("model")
authentication = {**(self.z_04_authentication or {}), **kwargs.get("z_04_authentication", {})} authentication = {**(self.z_04_authentication or {}), **kwargs.get("z_04_authentication", {})}
@ -525,7 +531,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
raise ImportError(msg) from e raise ImportError(msg) from e
# Initialize parameters based on the collection name # Initialize parameters based on the collection name
is_new_collection = self.collection_name == "+ Create new collection" is_new_collection = self.get_collection_options() is None
# Get the embedding model # Get the embedding model
embedding_params = {"embedding": self.embedding_model} if self.embedding_choice == "Embedding Model" else {} embedding_params = {"embedding": self.embedding_model} if self.embedding_choice == "Embedding Model" else {}
@ -553,11 +559,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
} }
# Get the running environment for Langflow # Get the running environment for Langflow
environment = ( environment = parse_api_endpoint(self.get_api_endpoint()).environment if self.get_api_endpoint() else None
parse_api_endpoint(getattr(self, "api_endpoint", None)).environment
if getattr(self, "api_endpoint", None)
else None
)
# Get Langflow version and platform information # Get Langflow version and platform information
__version__ = get_version_info()["version"] __version__ = get_version_info()["version"]
@ -577,16 +579,16 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
vector_store = AstraDBVectorStore( vector_store = AstraDBVectorStore(
# Astra DB Authentication Parameters # Astra DB Authentication Parameters
token=self.token, token=self.token,
api_endpoint=self.api_endpoint, api_endpoint=self.get_api_endpoint(),
namespace=self.keyspace or None, namespace=self.keyspace or None,
collection_name=self.get_collection_choice(), collection_name=self.get_collection_choice(),
environment=environment, environment=environment,
# Astra DB Usage Tracking Parameters # Astra DB Usage Tracking Parameters
ext_callers=[(f"{langflow_prefix}langflow", __version__)], ext_callers=[(f"{langflow_prefix}langflow", __version__)],
# Astra DB Vector Store Parameters # Astra DB Vector Store Parameters
**autodetect_params, **autodetect_params or {},
**embedding_params, **embedding_params or {},
**self.astradb_vectorstore_kwargs, **self.astradb_vectorstore_kwargs or {},
) )
except Exception as e: except Exception as e:
msg = f"Error initializing AstraDBVectorStore: {e}" msg = f"Error initializing AstraDBVectorStore: {e}"
@ -623,7 +625,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
return "similarity" return "similarity"
def _build_search_args(self): def _build_search_args(self):
query = self.search_input if isinstance(self.search_input, str) and self.search_input.strip() else None query = self.search_query if isinstance(self.search_query, str) and self.search_query.strip() else None
if query: if query:
args = { args = {
@ -648,7 +650,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
def search_documents(self, vector_store=None) -> list[Data]: def search_documents(self, vector_store=None) -> list[Data]:
vector_store = vector_store or self.build_vector_store() vector_store = vector_store or self.build_vector_store()
self.log(f"Search input: {self.search_input}") self.log(f"Search input: {self.search_query}")
self.log(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
self.log(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")

View file

@ -2,19 +2,16 @@ import os
import orjson import orjson
from astrapy.admin import parse_api_endpoint from astrapy.admin import parse_api_endpoint
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers import docs_to_data from langflow.helpers import docs_to_data
from langflow.inputs import ( from langflow.inputs import (
BoolInput, BoolInput,
DataInput,
DictInput, DictInput,
DropdownInput, DropdownInput,
FloatInput, FloatInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -24,7 +21,6 @@ from langflow.schema import Data
class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent): class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Astra DB Graph" display_name: str = "Astra DB Graph"
description: str = "Implementation of Graph Vector Store using Astra DB" description: str = "Implementation of Graph Vector Store using Astra DB"
documentation: str = "https://python.langchain.com/api_reference/astradb/graph_vectorstores/langchain_astradb.graph_vectorstores.AstraDBGraphVectorStore.html"
name = "AstraDBGraph" name = "AstraDBGraph"
icon: str = "AstraDB" icon: str = "AstraDB"
@ -56,15 +52,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
info="Metadata key used for incoming links.", info="Metadata key used for incoming links.",
advanced=True, advanced=True,
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_input",
display_name="Search Input",
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
StrInput( StrInput(
name="keyspace", name="keyspace",
display_name="Keyspace", display_name="Keyspace",
@ -129,14 +117,14 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
display_name="Metadata Indexing Include", display_name="Metadata Indexing Include",
info="Optional list of metadata fields to include in the indexing.", info="Optional list of metadata fields to include in the indexing.",
advanced=True, advanced=True,
is_list=True, list=True,
), ),
StrInput( StrInput(
name="metadata_indexing_exclude", name="metadata_indexing_exclude",
display_name="Metadata Indexing Exclude", display_name="Metadata Indexing Exclude",
info="Optional list of metadata fields to exclude from the indexing.", info="Optional list of metadata fields to exclude from the indexing.",
advanced=True, advanced=True,
is_list=True, list=True,
), ),
StrInput( StrInput(
name="collection_indexing_policy", name="collection_indexing_policy",
@ -205,7 +193,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
raise ValueError(msg) from e raise ValueError(msg) from e
try: try:
logger.debug(f"Initializing Graph Vector Store {self.collection_name}") self.log(f"Initializing Graph Vector Store {self.collection_name}")
vector_store = AstraDBGraphVectorStore( vector_store = AstraDBGraphVectorStore(
embedding=self.embedding_model, embedding=self.embedding_model,
@ -232,7 +220,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
msg = f"Error initializing AstraDBGraphVectorStore: {e}" msg = f"Error initializing AstraDBGraphVectorStore: {e}"
raise ValueError(msg) from e raise ValueError(msg) from e
logger.debug(f"Vector Store initialized: {vector_store.astra_env.collection_name}") self.log(f"Vector Store initialized: {vector_store.astra_env.collection_name}")
self._add_documents_to_vector_store(vector_store) self._add_documents_to_vector_store(vector_store)
return vector_store return vector_store
@ -247,14 +235,14 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
raise TypeError(msg) raise TypeError(msg)
if documents: if documents:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
try: try:
vector_store.add_documents(documents) vector_store.add_documents(documents)
except Exception as e: except Exception as e:
msg = f"Error adding documents to AstraDBGraphVectorStore: {e}" msg = f"Error adding documents to AstraDBGraphVectorStore: {e}"
raise ValueError(msg) from e raise ValueError(msg) from e
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
def _map_search_type(self) -> str: def _map_search_type(self) -> str:
match self.search_type: match self.search_type:
@ -287,21 +275,21 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
if not vector_store: if not vector_store:
vector_store = self.build_vector_store() vector_store = self.build_vector_store()
logger.debug("Searching for documents in AstraDBGraphVectorStore.") self.log("Searching for documents in AstraDBGraphVectorStore.")
logger.debug(f"Search input: {self.search_input}") self.log(f"Search query: {self.search_query}")
logger.debug(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
if self.search_input and isinstance(self.search_input, str) and self.search_input.strip(): if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
try: try:
search_type = self._map_search_type() search_type = self._map_search_type()
search_args = self._build_search_args() search_args = self._build_search_args()
docs = vector_store.search(query=self.search_input, search_type=search_type, **search_args) docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args)
# Drop links from the metadata. At this point the links don't add any value for building the # Drop links from the metadata. At this point the links don't add any value for building the
# context and haven't been restored to json which causes the conversion to fail. # context and haven't been restored to json which causes the conversion to fail.
logger.debug("Removing links from metadata.") self.log("Removing links from metadata.")
for doc in docs: for doc in docs:
if "links" in doc.metadata: if "links" in doc.metadata:
doc.metadata.pop("links") doc.metadata.pop("links")
@ -310,15 +298,15 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
msg = f"Error performing search in AstraDBGraphVectorStore: {e}" msg = f"Error performing search in AstraDBGraphVectorStore: {e}"
raise ValueError(msg) from e raise ValueError(msg) from e
logger.debug(f"Retrieved documents: {len(docs)}") self.log(f"Retrieved documents: {len(docs)}")
data = docs_to_data(docs) data = docs_to_data(docs)
logger.debug(f"Converted documents to data: {len(data)}") self.log(f"Converted documents to data: {len(data)}")
self.status = data self.status = data
return data return data
logger.debug("No search input provided. Skipping search.") self.log("No search input provided. Skipping search.")
return [] return []
def get_retriever_kwargs(self): def get_retriever_kwargs(self):

View file

@ -1,16 +1,13 @@
from langchain_community.vectorstores import Cassandra from langchain_community.vectorstores import Cassandra
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.inputs import BoolInput, DictInput, FloatInput from langflow.inputs import BoolInput, DictInput, FloatInput
from langflow.io import ( from langflow.io import (
DataInput,
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
MessageTextInput, MessageTextInput,
MultilineInput,
SecretStrInput, SecretStrInput,
) )
from langflow.schema import Data from langflow.schema import Data
@ -77,14 +74,9 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
display_name="Cluster arguments", display_name="Cluster arguments",
info="Optional dictionary of additional keyword arguments for the Cassandra cluster.", info="Optional dictionary of additional keyword arguments for the Cassandra cluster.",
advanced=True, advanced=True,
is_list=True, list=True,
),
MultilineInput(name="search_query", display_name="Search Query"),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
), ),
*LCVectorStoreComponent.inputs,
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",
@ -114,7 +106,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
display_name="Search Metadata Filter", display_name="Search Metadata Filter",
info="Optional dictionary of filters to apply to the search query.", info="Optional dictionary of filters to apply to the search query.",
advanced=True, advanced=True,
is_list=True, list=True,
), ),
MessageTextInput( MessageTextInput(
name="body_search", name="body_search",
@ -184,7 +176,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
setup_mode = SetupMode.ASYNC setup_mode = SetupMode.ASYNC
if documents: if documents:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
table = Cassandra.from_documents( table = Cassandra.from_documents(
documents=documents, documents=documents,
embedding=self.embedding, embedding=self.embedding,
@ -195,7 +187,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
body_index_options=body_index_options, body_index_options=body_index_options,
) )
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
table = Cassandra( table = Cassandra(
embedding=self.embedding, embedding=self.embedding,
table_name=self.table_name, table_name=self.table_name,
@ -216,16 +208,16 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
def search_documents(self) -> list[Data]: def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store() vector_store = self.build_vector_store()
logger.debug(f"Search input: {self.search_query}") self.log(f"Search input: {self.search_query}")
logger.debug(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
if self.search_query and isinstance(self.search_query, str) and self.search_query.strip(): if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
try: try:
search_type = self._map_search_type() search_type = self._map_search_type()
search_args = self._build_search_args() search_args = self._build_search_args()
logger.debug(f"Search args: {search_args}") self.log(f"Search args: {search_args}")
docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args) docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args)
except KeyError as e: except KeyError as e:
@ -237,7 +229,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
raise ValueError(msg) from e raise ValueError(msg) from e
raise raise
logger.debug(f"Retrieved documents: {len(docs)}") self.log(f"Retrieved documents: {len(docs)}")
data = docs_to_data(docs) data = docs_to_data(docs)
self.status = data self.status = data

View file

@ -1,18 +1,15 @@
from uuid import UUID from uuid import UUID
from langchain_community.graph_vectorstores import CassandraGraphVectorStore from langchain_community.graph_vectorstores import CassandraGraphVectorStore
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.inputs import DictInput, FloatInput from langflow.inputs import DictInput, FloatInput
from langflow.io import ( from langflow.io import (
DataInput,
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
MessageTextInput, MessageTextInput,
MultilineInput,
SecretStrInput, SecretStrInput,
) )
from langflow.schema import Data from langflow.schema import Data
@ -21,7 +18,6 @@ from langflow.schema import Data
class CassandraGraphVectorStoreComponent(LCVectorStoreComponent): class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
display_name = "Cassandra Graph" display_name = "Cassandra Graph"
description = "Cassandra Graph Vector Store" description = "Cassandra Graph Vector Store"
documentation = "https://python.langchain.com/v0.2/api_reference/community/graph_vectorstores.html"
name = "CassandraGraph" name = "CassandraGraph"
icon = "Cassandra" icon = "Cassandra"
@ -66,14 +62,9 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
display_name="Cluster arguments", display_name="Cluster arguments",
info="Optional dictionary of additional keyword arguments for the Cassandra cluster.", info="Optional dictionary of additional keyword arguments for the Cassandra cluster.",
advanced=True, advanced=True,
is_list=True, list=True,
),
MultilineInput(name="search_query", display_name="Search Query"),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
), ),
*LCVectorStoreComponent.inputs,
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",
@ -116,7 +107,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
display_name="Search Metadata Filter", display_name="Search Metadata Filter",
info="Optional dictionary of filters to apply to the search query.", info="Optional dictionary of filters to apply to the search query.",
advanced=True, advanced=True,
is_list=True, list=True,
), ),
] ]
@ -164,7 +155,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
setup_mode = SetupMode.OFF if self.setup_mode == "Off" else SetupMode.SYNC setup_mode = SetupMode.OFF if self.setup_mode == "Off" else SetupMode.SYNC
if documents: if documents:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
store = CassandraGraphVectorStore.from_documents( store = CassandraGraphVectorStore.from_documents(
documents=documents, documents=documents,
embedding=self.embedding, embedding=self.embedding,
@ -172,7 +163,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
keyspace=self.keyspace, keyspace=self.keyspace,
) )
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
store = CassandraGraphVectorStore( store = CassandraGraphVectorStore(
embedding=self.embedding, embedding=self.embedding,
node_table=self.table_name, node_table=self.table_name,
@ -195,16 +186,16 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
def search_documents(self) -> list[Data]: def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store() vector_store = self.build_vector_store()
logger.debug(f"Search input: {self.search_query}") self.log(f"Search input: {self.search_query}")
logger.debug(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
if self.search_query and isinstance(self.search_query, str) and self.search_query.strip(): if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
try: try:
search_type = self._map_search_type() search_type = self._map_search_type()
search_args = self._build_search_args() search_args = self._build_search_args()
logger.debug(f"Search args: {search_args}") self.log(f"Search args: {search_args}")
docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args) docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args)
except KeyError as e: except KeyError as e:
@ -216,7 +207,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
raise ValueError(msg) from e raise ValueError(msg) from e
raise raise
logger.debug(f"Retrieved documents: {len(docs)}") self.log(f"Retrieved documents: {len(docs)}")
data = docs_to_data(docs) data = docs_to_data(docs)
self.status = data self.status = data

View file

@ -2,11 +2,10 @@ from copy import deepcopy
from chromadb.config import Settings from chromadb.config import Settings
from langchain_chroma import Chroma from langchain_chroma import Chroma
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.base.vectorstores.utils import chroma_collection_to_data from langflow.base.vectorstores.utils import chroma_collection_to_data
from langflow.io import BoolInput, DataInput, DropdownInput, HandleInput, IntInput, MultilineInput, StrInput from langflow.io import BoolInput, DropdownInput, HandleInput, IntInput, StrInput
from langflow.schema import Data from langflow.schema import Data
@ -15,7 +14,6 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Chroma DB" display_name: str = "Chroma DB"
description: str = "Chroma Vector Store with search capabilities" description: str = "Chroma Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/integrations/vectorstores/chroma"
name = "Chroma" name = "Chroma"
icon = "Chroma" icon = "Chroma"
@ -29,15 +27,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
name="persist_directory", name="persist_directory",
display_name="Persist Directory", display_name="Persist Directory",
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_query",
display_name="Search Query",
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
StrInput( StrInput(
name="chroma_server_cors_allow_origins", name="chroma_server_cors_allow_origins",
@ -153,7 +143,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
raise TypeError(msg) raise TypeError(msg)
if documents and self.embedding is not None: if documents and self.embedding is not None:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
vector_store.add_documents(documents) vector_store.add_documents(documents)
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")

View file

@ -4,12 +4,10 @@ from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cache
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.inputs import BoolInput, FloatInput from langflow.inputs import BoolInput, FloatInput
from langflow.io import ( from langflow.io import (
DataInput,
DictInput, DictInput,
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -19,7 +17,6 @@ from langflow.schema import Data
class ClickhouseVectorStoreComponent(LCVectorStoreComponent): class ClickhouseVectorStoreComponent(LCVectorStoreComponent):
display_name = "Clickhouse" display_name = "Clickhouse"
description = "Clickhouse Vector Store with search capabilities" description = "Clickhouse Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/clickhouse/"
name = "Clickhouse" name = "Clickhouse"
icon = "Clickhouse" icon = "Clickhouse"
@ -54,8 +51,7 @@ class ClickhouseVectorStoreComponent(LCVectorStoreComponent):
), ),
StrInput(name="index_param", display_name="Param of the index", value="'L2Distance',100", advanced=True), StrInput(name="index_param", display_name="Param of the index", value="'L2Distance',100", advanced=True),
DictInput(name="index_query_params", display_name="index query params", advanced=True), DictInput(name="index_query_params", display_name="index query params", advanced=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(name="ingest_data", display_name="Ingest Data", is_list=True),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -4,14 +4,13 @@ from langchain_community.vectorstores import CouchbaseVectorStore
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
class CouchbaseVectorStoreComponent(LCVectorStoreComponent): class CouchbaseVectorStoreComponent(LCVectorStoreComponent):
display_name = "Couchbase" display_name = "Couchbase"
description = "Couchbase Vector Store with search capabilities" description = "Couchbase Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.1/docs/integrations/document_loaders/couchbase/"
name = "Couchbase" name = "Couchbase"
icon = "Couchbase" icon = "Couchbase"
@ -25,12 +24,7 @@ class CouchbaseVectorStoreComponent(LCVectorStoreComponent):
StrInput(name="scope_name", display_name="Scope Name", required=True), StrInput(name="scope_name", display_name="Scope Name", required=True),
StrInput(name="collection_name", display_name="Collection Name", required=True), StrInput(name="collection_name", display_name="Collection Name", required=True),
StrInput(name="index_name", display_name="Index Name", required=True), StrInput(name="index_name", display_name="Index Name", required=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -2,16 +2,13 @@ from typing import Any
from langchain.schema import Document from langchain.schema import Document
from langchain_elasticsearch import ElasticsearchStore from langchain_elasticsearch import ElasticsearchStore
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.io import ( from langflow.io import (
DataInput,
DropdownInput, DropdownInput,
FloatInput, FloatInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -23,7 +20,6 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Elasticsearch" display_name: str = "Elasticsearch"
description: str = "Elasticsearch Vector Store with with advanced, customizable search capabilities." description: str = "Elasticsearch Vector Store with with advanced, customizable search capabilities."
documentation = "https://python.langchain.com/docs/integrations/vectorstores/elasticsearch"
name = "Elasticsearch" name = "Elasticsearch"
icon = "ElasticsearchStore" icon = "ElasticsearchStore"
@ -47,11 +43,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
value="langflow", value="langflow",
info="The index name where the vectors will be stored in Elasticsearch cluster.", info="The index name where the vectors will be stored in Elasticsearch cluster.",
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_input",
display_name="Search Input",
info="Enter a search query. Leave empty to retrieve all documents.",
),
StrInput( StrInput(
name="username", name="username",
display_name="Username", display_name="Username",
@ -72,11 +64,6 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
"Required for both local and Elastic Cloud setups unless API keys are used." "Required for both local and Elastic Cloud setups unless API keys are used."
), ),
), ),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput( HandleInput(
name="embedding", name="embedding",
display_name="Embedding", display_name="Embedding",
@ -155,7 +142,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
documents.append(data.to_lc_document()) documents.append(data.to_lc_document())
else: else:
error_message = "Vector Store Inputs must be Data objects." error_message = "Vector Store Inputs must be Data objects."
logger.error(error_message) self.log(error_message)
raise TypeError(error_message) raise TypeError(error_message)
return documents return documents
@ -163,10 +150,10 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
"""Adds documents to the Vector Store.""" """Adds documents to the Vector Store."""
documents = self._prepare_documents() documents = self._prepare_documents()
if documents and self.embedding: if documents and self.embedding:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
vector_store.add_documents(documents) vector_store.add_documents(documents)
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
def search(self, query: str | None = None) -> list[dict[str, Any]]: def search(self, query: str | None = None) -> list[dict[str, Any]]:
"""Search for similar documents in the vector store or retrieve all documents if no query is provided.""" """Search for similar documents in the vector store or retrieve all documents if no query is provided."""
@ -180,7 +167,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
search_type = self.search_type.lower() search_type = self.search_type.lower()
if search_type not in {"similarity", "mmr"}: if search_type not in {"similarity", "mmr"}:
msg = f"Invalid search type: {self.search_type}" msg = f"Invalid search type: {self.search_type}"
logger.error(msg) self.log(msg)
raise ValueError(msg) raise ValueError(msg)
try: try:
if search_type == "similarity": if search_type == "similarity":
@ -192,7 +179,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
"Error occurred while querying the Elasticsearch VectorStore," "Error occurred while querying the Elasticsearch VectorStore,"
" there is no Data into the VectorStore." " there is no Data into the VectorStore."
) )
logger.exception(msg) self.log(msg)
raise ValueError(msg) from e raise ValueError(msg) from e
return [ return [
{"page_content": doc.page_content, "metadata": doc.metadata, "score": score} for doc, score in results {"page_content": doc.page_content, "metadata": doc.metadata, "score": score} for doc, score in results
@ -228,7 +215,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
If no search input is provided, retrieve all documents. If no search input is provided, retrieve all documents.
""" """
results = self.search(self.search_input) results = self.search(self.search_query)
retrieved_data = [ retrieved_data = [
Data( Data(
text=result["page_content"], text=result["page_content"],

View file

@ -1,9 +1,8 @@
from langchain_community.vectorstores import FAISS from langchain_community.vectorstores import FAISS
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import BoolInput, DataInput, HandleInput, IntInput, MultilineInput, StrInput from langflow.io import BoolInput, HandleInput, IntInput, StrInput
from langflow.schema import Data from langflow.schema import Data
@ -12,7 +11,6 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "FAISS" display_name: str = "FAISS"
description: str = "FAISS Vector Store with search capabilities" description: str = "FAISS Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss"
name = "FAISS" name = "FAISS"
icon = "FAISS" icon = "FAISS"
@ -27,15 +25,7 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
display_name="Persist Directory", display_name="Persist Directory",
info="Path to save the FAISS index. It will be relative to where Langflow is running.", info="Path to save the FAISS index. It will be relative to where Langflow is running.",
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_query",
display_name="Search Query",
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
BoolInput( BoolInput(
name="allow_dangerous_deserialization", name="allow_dangerous_deserialization",
display_name="Allow Dangerous Deserialization", display_name="Allow Dangerous Deserialization",
@ -93,8 +83,8 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
msg = "Failed to load the FAISS index." msg = "Failed to load the FAISS index."
raise ValueError(msg) raise ValueError(msg)
logger.debug(f"Search input: {self.search_query}") self.log(f"Search input: {self.search_query}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
if self.search_query and isinstance(self.search_query, str) and self.search_query.strip(): if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
docs = vector_store.similarity_search( docs = vector_store.similarity_search(
@ -102,11 +92,11 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
k=self.number_of_results, k=self.number_of_results,
) )
logger.debug(f"Retrieved documents: {len(docs)}") self.log(f"Retrieved documents: {len(docs)}")
data = docs_to_data(docs) data = docs_to_data(docs)
logger.debug(f"Converted documents to data: {len(data)}") self.log(f"Converted documents to data: {len(data)}")
logger.debug(data) self.log(data)
return data # Return the search results data return data # Return the search results data
logger.debug("No search input provided. Skipping search.") self.log("No search input provided. Skipping search.")
return [] return []

View file

@ -1,11 +1,8 @@
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers import docs_to_data from langflow.helpers import docs_to_data
from langflow.inputs import DictInput, FloatInput from langflow.inputs import DictInput, FloatInput
from langflow.io import ( from langflow.io import (
BoolInput, BoolInput,
DataInput,
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
@ -19,7 +16,6 @@ from langflow.schema import Data
class HCDVectorStoreComponent(LCVectorStoreComponent): class HCDVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Hyper-Converged Database" display_name: str = "Hyper-Converged Database"
description: str = "Implementation of Vector Store using Hyper-Converged Database (HCD) with search capabilities" description: str = "Implementation of Vector Store using Hyper-Converged Database (HCD) with search capabilities"
documentation: str = "https://python.langchain.com/docs/integrations/vectorstores/astradb"
name = "HCD" name = "HCD"
icon: str = "HCD" icon: str = "HCD"
@ -51,15 +47,7 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
value="HCD_API_ENDPOINT", value="HCD_API_ENDPOINT",
required=True, required=True,
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_input",
display_name="Search Input",
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
StrInput( StrInput(
name="namespace", name="namespace",
display_name="Namespace", display_name="Namespace",
@ -263,14 +251,14 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
raise TypeError(msg) raise TypeError(msg)
if documents: if documents:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
try: try:
vector_store.add_documents(documents) vector_store.add_documents(documents)
except Exception as e: except Exception as e:
msg = f"Error adding documents to AstraDBVectorStore: {e}" msg = f"Error adding documents to AstraDBVectorStore: {e}"
raise ValueError(msg) from e raise ValueError(msg) from e
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
def _map_search_type(self) -> str: def _map_search_type(self) -> str:
if self.search_type == "Similarity with score threshold": if self.search_type == "Similarity with score threshold":
@ -294,27 +282,27 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
def search_documents(self) -> list[Data]: def search_documents(self) -> list[Data]:
vector_store = self.build_vector_store() vector_store = self.build_vector_store()
logger.debug(f"Search input: {self.search_input}") self.log(f"Search query: {self.search_query}")
logger.debug(f"Search type: {self.search_type}") self.log(f"Search type: {self.search_type}")
logger.debug(f"Number of results: {self.number_of_results}") self.log(f"Number of results: {self.number_of_results}")
if self.search_input and isinstance(self.search_input, str) and self.search_input.strip(): if self.search_query and isinstance(self.search_query, str) and self.search_query.strip():
try: try:
search_type = self._map_search_type() search_type = self._map_search_type()
search_args = self._build_search_args() search_args = self._build_search_args()
docs = vector_store.search(query=self.search_input, search_type=search_type, **search_args) docs = vector_store.search(query=self.search_query, search_type=search_type, **search_args)
except Exception as e: except Exception as e:
msg = f"Error performing search in AstraDBVectorStore: {e}" msg = f"Error performing search in AstraDBVectorStore: {e}"
raise ValueError(msg) from e raise ValueError(msg) from e
logger.debug(f"Retrieved documents: {len(docs)}") self.log(f"Retrieved documents: {len(docs)}")
data = docs_to_data(docs) data = docs_to_data(docs)
logger.debug(f"Converted documents to data: {len(data)}") self.log(f"Converted documents to data: {len(data)}")
self.status = data self.status = data
return data return data
logger.debug("No search input provided. Skipping search.") self.log("No search input provided. Skipping search.")
return [] return []
def get_retriever_kwargs(self): def get_retriever_kwargs(self):

View file

@ -2,13 +2,11 @@ from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cache
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import ( from langflow.io import (
BoolInput, BoolInput,
DataInput,
DictInput, DictInput,
DropdownInput, DropdownInput,
FloatInput, FloatInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -20,7 +18,6 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Milvus" display_name: str = "Milvus"
description: str = "Milvus vector store with search capabilities" description: str = "Milvus vector store with search capabilities"
documentation = "https://python.langchain.com/docs/integrations/vectorstores/milvus"
name = "Milvus" name = "Milvus"
icon = "Milvus" icon = "Milvus"
@ -53,12 +50,7 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent):
DictInput(name="search_params", display_name="Search Parameters", advanced=True), DictInput(name="search_params", display_name="Search Parameters", advanced=True),
BoolInput(name="drop_old", display_name="Drop Old Collection", value=False, advanced=True), BoolInput(name="drop_old", display_name="Drop Old Collection", value=False, advanced=True),
FloatInput(name="timeout", display_name="Timeout", advanced=True), FloatInput(name="timeout", display_name="Timeout", advanced=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -5,14 +5,13 @@ from langchain_community.vectorstores import MongoDBAtlasVectorSearch
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import BoolInput, DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import BoolInput, HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
class MongoVectorStoreComponent(LCVectorStoreComponent): class MongoVectorStoreComponent(LCVectorStoreComponent):
display_name = "MongoDB Atlas" display_name = "MongoDB Atlas"
description = "MongoDB Atlas Vector Store with search capabilities" description = "MongoDB Atlas Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/mongodb_atlas"
name = "MongoDBAtlasVector" name = "MongoDBAtlasVector"
icon = "MongoDB" icon = "MongoDB"
@ -30,12 +29,7 @@ class MongoVectorStoreComponent(LCVectorStoreComponent):
StrInput(name="db_name", display_name="Database Name", required=True), StrInput(name="db_name", display_name="Database Name", required=True),
StrInput(name="collection_name", display_name="Collection Name", required=True), StrInput(name="collection_name", display_name="Collection Name", required=True),
StrInput(name="index_name", display_name="Index Name", required=True), StrInput(name="index_name", display_name="Index Name", required=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -2,12 +2,10 @@ import json
from typing import Any from typing import Any
from langchain_community.vectorstores import OpenSearchVectorSearch from langchain_community.vectorstores import OpenSearchVectorSearch
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.io import ( from langflow.io import (
BoolInput, BoolInput,
DataInput,
DropdownInput, DropdownInput,
FloatInput, FloatInput,
HandleInput, HandleInput,
@ -24,7 +22,6 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "OpenSearch" display_name: str = "OpenSearch"
description: str = "OpenSearch Vector Store with advanced, customizable search capabilities." description: str = "OpenSearch Vector Store with advanced, customizable search capabilities."
documentation = "https://python.langchain.com/docs/integrations/vectorstores/opensearch"
name = "OpenSearch" name = "OpenSearch"
icon = "OpenSearch" icon = "OpenSearch"
@ -41,20 +38,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
value="langflow", value="langflow",
info="The index name where the vectors will be stored in OpenSearch cluster.", info="The index name where the vectors will be stored in OpenSearch cluster.",
), ),
MultilineInput( *LCVectorStoreComponent.inputs,
name="search_input",
display_name="Search Input",
info=(
"Enter a search query. Leave empty to retrieve all documents. "
"If you need a more advanced search consider using Hybrid Search Query instead."
),
value="",
),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
DropdownInput( DropdownInput(
name="search_type", name="search_type",
@ -120,7 +104,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
from langchain_community.vectorstores import OpenSearchVectorSearch from langchain_community.vectorstores import OpenSearchVectorSearch
except ImportError as e: except ImportError as e:
error_message = f"Failed to import required modules: {e}" error_message = f"Failed to import required modules: {e}"
logger.exception(error_message) self.log(error_message)
raise ImportError(error_message) from e raise ImportError(error_message) from e
try: try:
@ -136,7 +120,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
) )
except Exception as e: except Exception as e:
error_message = f"Failed to create OpenSearchVectorSearch instance: {e}" error_message = f"Failed to create OpenSearchVectorSearch instance: {e}"
logger.exception(error_message) self.log(error_message)
raise RuntimeError(error_message) from e raise RuntimeError(error_message) from e
if self.ingest_data: if self.ingest_data:
@ -152,19 +136,19 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
documents.append(_input.to_lc_document()) documents.append(_input.to_lc_document())
else: else:
error_message = f"Expected Data object, got {type(_input)}" error_message = f"Expected Data object, got {type(_input)}"
logger.error(error_message) self.log(error_message)
raise TypeError(error_message) raise TypeError(error_message)
if documents and self.embedding is not None: if documents and self.embedding is not None:
logger.debug(f"Adding {len(documents)} documents to the Vector Store.") self.log(f"Adding {len(documents)} documents to the Vector Store.")
try: try:
vector_store.add_documents(documents) vector_store.add_documents(documents)
except Exception as e: except Exception as e:
error_message = f"Error adding documents to Vector Store: {e}" error_message = f"Error adding documents to Vector Store: {e}"
logger.exception(error_message) self.log(error_message)
raise RuntimeError(error_message) from e raise RuntimeError(error_message) from e
else: else:
logger.debug("No documents to add to the Vector Store.") self.log("No documents to add to the Vector Store.")
def search(self, query: str | None = None) -> list[dict[str, Any]]: def search(self, query: str | None = None) -> list[dict[str, Any]]:
"""Search for similar documents in the vector store or retrieve all documents if no query is provided.""" """Search for similar documents in the vector store or retrieve all documents if no query is provided."""
@ -178,7 +162,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
hybrid_query = json.loads(self.hybrid_search_query) hybrid_query = json.loads(self.hybrid_search_query)
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
error_message = f"Invalid hybrid search query JSON: {e}" error_message = f"Invalid hybrid search query JSON: {e}"
logger.exception(error_message) self.log(error_message)
raise ValueError(error_message) from e raise ValueError(error_message) from e
results = vector_store.client.search(index=self.index_name, body=hybrid_query) results = vector_store.client.search(index=self.index_name, body=hybrid_query)
@ -223,11 +207,11 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
except Exception as e: except Exception as e:
error_message = f"Error during search: {e}" error_message = f"Error during search: {e}"
logger.exception(error_message) self.log(error_message)
raise RuntimeError(error_message) from e raise RuntimeError(error_message) from e
error_message = f"Error during search. Invalid search type: {self.search_type}" error_message = f"Error during search. Invalid search type: {self.search_type}"
logger.error(error_message) self.log(error_message)
raise ValueError(error_message) raise ValueError(error_message)
def search_documents(self) -> list[Data]: def search_documents(self) -> list[Data]:
@ -236,7 +220,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
If no search input is provided, retrieve all documents. If no search input is provided, retrieve all documents.
""" """
try: try:
query = self.search_input.strip() if self.search_input else None query = self.search_query.strip() if self.search_query else None
results = self.search(query) results = self.search(query)
retrieved_data = [ retrieved_data = [
Data( Data(
@ -247,7 +231,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
] ]
except Exception as e: except Exception as e:
error_message = f"Error during document search: {e}" error_message = f"Error during document search: {e}"
logger.exception(error_message) self.log(error_message)
raise RuntimeError(error_message) from e raise RuntimeError(error_message) from e
self.status = retrieved_data self.status = retrieved_data

View file

@ -2,7 +2,7 @@ from langchain_community.vectorstores import PGVector
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
from langflow.utils.connection_string_parser import transform_connection_string from langflow.utils.connection_string_parser import transform_connection_string
@ -10,19 +10,13 @@ from langflow.utils.connection_string_parser import transform_connection_string
class PGVectorStoreComponent(LCVectorStoreComponent): class PGVectorStoreComponent(LCVectorStoreComponent):
display_name = "PGVector" display_name = "PGVector"
description = "PGVector Vector Store with search capabilities" description = "PGVector Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/pgvector/"
name = "pgvector" name = "pgvector"
icon = "cpu" icon = "cpu"
inputs = [ inputs = [
SecretStrInput(name="pg_server_url", display_name="PostgreSQL Server Connection String", required=True), SecretStrInput(name="pg_server_url", display_name="PostgreSQL Server Connection String", required=True),
StrInput(name="collection_name", display_name="Table", required=True), StrInput(name="collection_name", display_name="Table", required=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingestion Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -3,14 +3,13 @@ from langchain_pinecone import Pinecone
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import DataInput, DropdownInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import DropdownInput, HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
class PineconeVectorStoreComponent(LCVectorStoreComponent): class PineconeVectorStoreComponent(LCVectorStoreComponent):
display_name = "Pinecone" display_name = "Pinecone"
description = "Pinecone Vector Store with search capabilities" description = "Pinecone Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/pinecone/"
name = "Pinecone" name = "Pinecone"
icon = "Pinecone" icon = "Pinecone"
inputs = [ inputs = [
@ -31,12 +30,7 @@ class PineconeVectorStoreComponent(LCVectorStoreComponent):
value="text", value="text",
advanced=True, advanced=True,
), ),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -4,11 +4,9 @@ from langchain_community.vectorstores import Qdrant
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import ( from langflow.io import (
DataInput,
DropdownInput, DropdownInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput,
SecretStrInput, SecretStrInput,
StrInput, StrInput,
) )
@ -18,7 +16,6 @@ from langflow.schema import Data
class QdrantVectorStoreComponent(LCVectorStoreComponent): class QdrantVectorStoreComponent(LCVectorStoreComponent):
display_name = "Qdrant" display_name = "Qdrant"
description = "Qdrant Vector Store with search capabilities" description = "Qdrant Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/qdrant"
icon = "Qdrant" icon = "Qdrant"
inputs = [ inputs = [
@ -40,12 +37,7 @@ class QdrantVectorStoreComponent(LCVectorStoreComponent):
), ),
StrInput(name="content_payload_key", display_name="Content Payload Key", value="page_content", advanced=True), StrInput(name="content_payload_key", display_name="Content Payload Key", value="page_content", advanced=True),
StrInput(name="metadata_payload_key", display_name="Metadata Payload Key", value="metadata", advanced=True), StrInput(name="metadata_payload_key", display_name="Metadata Payload Key", value="metadata", advanced=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -5,7 +5,7 @@ from langchain_community.vectorstores.redis import Redis
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
@ -14,7 +14,6 @@ class RedisVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Redis" display_name: str = "Redis"
description: str = "Implementation of Vector Store using Redis" description: str = "Implementation of Vector Store using Redis"
documentation = "https://python.langchain.com/docs/integrations/vectorstores/redis"
name = "Redis" name = "Redis"
icon = "Redis" icon = "Redis"
@ -29,12 +28,7 @@ class RedisVectorStoreComponent(LCVectorStoreComponent):
name="schema", name="schema",
display_name="Schema", display_name="Schema",
), ),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
IntInput( IntInput(
name="number_of_results", name="number_of_results",
display_name="Number of Results", display_name="Number of Results",

View file

@ -3,14 +3,13 @@ from supabase.client import Client, create_client
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
class SupabaseVectorStoreComponent(LCVectorStoreComponent): class SupabaseVectorStoreComponent(LCVectorStoreComponent):
display_name = "Supabase" display_name = "Supabase"
description = "Supabase Vector Store with search capabilities" description = "Supabase Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/supabase/"
name = "SupabaseVectorStore" name = "SupabaseVectorStore"
icon = "Supabase" icon = "Supabase"
@ -19,12 +18,7 @@ class SupabaseVectorStoreComponent(LCVectorStoreComponent):
SecretStrInput(name="supabase_service_key", display_name="Supabase Service Key", required=True), SecretStrInput(name="supabase_service_key", display_name="Supabase Service Key", required=True),
StrInput(name="table_name", display_name="Table Name", advanced=True), StrInput(name="table_name", display_name="Table Name", advanced=True),
StrInput(name="query_name", display_name="Query Name"), StrInput(name="query_name", display_name="Query Name"),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

View file

@ -3,7 +3,6 @@ from langchain_community.vectorstores import UpstashVectorStore
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import ( from langflow.io import (
DataInput,
HandleInput, HandleInput,
IntInput, IntInput,
MultilineInput, MultilineInput,
@ -16,7 +15,6 @@ from langflow.schema import Data
class UpstashVectorStoreComponent(LCVectorStoreComponent): class UpstashVectorStoreComponent(LCVectorStoreComponent):
display_name = "Upstash" display_name = "Upstash"
description = "Upstash Vector Store with search capabilities" description = "Upstash Vector Store with search capabilities"
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/upstash/"
name = "Upstash" name = "Upstash"
icon = "Upstash" icon = "Upstash"
@ -45,17 +43,12 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
display_name="Namespace", display_name="Namespace",
info="Leave empty for default namespace.", info="Leave empty for default namespace.",
), ),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
MultilineInput( MultilineInput(
name="metadata_filter", name="metadata_filter",
display_name="Metadata Filter", display_name="Metadata Filter",
info="Filters documents by metadata. Look at the documentation for more information.", info="Filters documents by metadata. Look at the documentation for more information.",
), ),
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput( HandleInput(
name="embedding", name="embedding",
display_name="Embedding", display_name="Embedding",

View file

@ -1,11 +1,10 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from langchain_community.vectorstores import Vectara from langchain_community.vectorstores import Vectara
from loguru import logger
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import HandleInput, IntInput, MessageTextInput, SecretStrInput, StrInput from langflow.io import HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
if TYPE_CHECKING: if TYPE_CHECKING:
@ -17,7 +16,6 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
display_name: str = "Vectara" display_name: str = "Vectara"
description: str = "Vectara Vector Store with search capabilities" description: str = "Vectara Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/vectara"
name = "Vectara" name = "Vectara"
icon = "Vectara" icon = "Vectara"
@ -30,16 +28,7 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
display_name="Embedding", display_name="Embedding",
input_types=["Embeddings"], input_types=["Embeddings"],
), ),
HandleInput( *LCVectorStoreComponent.inputs,
name="ingest_data",
display_name="Ingest Data",
input_types=["Document", "Data"],
is_list=True,
),
MessageTextInput(
name="search_query",
display_name="Search Query",
),
IntInput( IntInput(
name="number_of_results", name="number_of_results",
display_name="Number of Results", display_name="Number of Results",
@ -81,11 +70,11 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
documents.append(_input) documents.append(_input)
if documents: if documents:
logger.debug(f"Adding {len(documents)} documents to Vectara.") self.log(f"Adding {len(documents)} documents to Vectara.")
vector_store.add_documents(documents) vector_store.add_documents(documents)
self.status = f"Added {len(documents)} documents to Vectara" self.status = f"Added {len(documents)} documents to Vectara"
else: else:
logger.debug("No documents to add to Vectara.") self.log("No documents to add to Vectara.")
self.status = "No valid documents to add to Vectara" self.status = "No valid documents to add to Vectara"
def search_documents(self) -> list[Data]: def search_documents(self) -> list[Data]:

View file

@ -58,7 +58,12 @@ class VectaraRagComponent(Component):
StrInput(name="vectara_customer_id", display_name="Vectara Customer ID", required=True), StrInput(name="vectara_customer_id", display_name="Vectara Customer ID", required=True),
StrInput(name="vectara_corpus_id", display_name="Vectara Corpus ID", required=True), StrInput(name="vectara_corpus_id", display_name="Vectara Corpus ID", required=True),
SecretStrInput(name="vectara_api_key", display_name="Vectara API Key", required=True), SecretStrInput(name="vectara_api_key", display_name="Vectara API Key", required=True),
MessageTextInput(name="search_query", display_name="Search Query", info="The query to receive an answer on."), MessageTextInput(
name="search_query",
display_name="Search Query",
info="The query to receive an answer on.",
tool_mode=True,
),
FloatInput( FloatInput(
name="lexical_interpolation", name="lexical_interpolation",
display_name="Hybrid Search Factor", display_name="Hybrid Search Factor",

View file

@ -15,7 +15,6 @@ class VectaraSelfQueryRetriverComponent(CustomComponent):
display_name: str = "Vectara Self Query Retriever for Vectara Vector Store" display_name: str = "Vectara Self Query Retriever for Vectara Vector Store"
description: str = "Implementation of Vectara Self Query Retriever" description: str = "Implementation of Vectara Self Query Retriever"
documentation = "https://python.langchain.com/docs/integrations/retrievers/self_query/vectara_self_query"
name = "VectaraSelfQueryRetriver" name = "VectaraSelfQueryRetriver"
icon = "Vectara" icon = "Vectara"
legacy = True legacy = True

View file

@ -3,14 +3,13 @@ from langchain_community.vectorstores import Weaviate
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
from langflow.helpers.data import docs_to_data from langflow.helpers.data import docs_to_data
from langflow.io import BoolInput, DataInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput from langflow.io import BoolInput, HandleInput, IntInput, SecretStrInput, StrInput
from langflow.schema import Data from langflow.schema import Data
class WeaviateVectorStoreComponent(LCVectorStoreComponent): class WeaviateVectorStoreComponent(LCVectorStoreComponent):
display_name = "Weaviate" display_name = "Weaviate"
description = "Weaviate Vector Store with search capabilities" description = "Weaviate Vector Store with search capabilities"
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/weaviate"
name = "Weaviate" name = "Weaviate"
icon = "Weaviate" icon = "Weaviate"
@ -24,12 +23,7 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent):
info="Requires capitalized index name.", info="Requires capitalized index name.",
), ),
StrInput(name="text_key", display_name="Text Key", value="text", advanced=True), StrInput(name="text_key", display_name="Text Key", value="text", advanced=True),
MultilineInput(name="search_query", display_name="Search Query"), *LCVectorStoreComponent.inputs,
DataInput(
name="ingest_data",
display_name="Ingest Data",
is_list=True,
),
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]), HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
IntInput( IntInput(
name="number_of_results", name="number_of_results",

File diff suppressed because one or more lines are too long

View file

@ -33,7 +33,7 @@ def rag_graph():
chat_input = ChatInput() chat_input = ChatInput()
rag_vector_store = AstraDBVectorStoreComponent() rag_vector_store = AstraDBVectorStoreComponent()
rag_vector_store.set( rag_vector_store.set(
search_input=chat_input.message_response, search_query=chat_input.message_response,
embedding_model=openai_embeddings.build_embeddings, embedding_model=openai_embeddings.build_embeddings,
) )

View file

@ -56,7 +56,6 @@ async def test_base(astradb_client: AstraDB):
}, },
) )
assert results["vector_store"] is not None
assert results["search_results"] == [] assert results["search_results"] == []
assert astradb_client.collection(BASIC_COLLECTION) assert astradb_client.collection(BASIC_COLLECTION)
@ -73,7 +72,7 @@ async def test_astra_embeds_and_search():
"api_endpoint": api_endpoint, "api_endpoint": api_endpoint,
"collection_name": BASIC_COLLECTION, "collection_name": BASIC_COLLECTION,
"number_of_results": 1, "number_of_results": 1,
"search_input": "test1", "search_query": "test1",
"ingest_data": ComponentInputHandle( "ingest_data": ComponentInputHandle(
clazz=TextToData, inputs={"text_data": ["test1", "test2"]}, output_name="from_text" clazz=TextToData, inputs={"text_data": ["test1", "test2"]}, output_name="from_text"
), ),
@ -117,7 +116,7 @@ def test_astra_vectorize():
api_endpoint=api_endpoint, api_endpoint=api_endpoint,
collection_name=VECTORIZE_COLLECTION, collection_name=VECTORIZE_COLLECTION,
ingest_data=records, ingest_data=records,
search_input="test", search_query="test",
number_of_results=2, number_of_results=2,
pre_delete_collection=True, pre_delete_collection=True,
) )
@ -173,7 +172,7 @@ def test_astra_vectorize_with_provider_api_key():
api_endpoint=api_endpoint, api_endpoint=api_endpoint,
collection_name=VECTORIZE_COLLECTION_OPENAI, collection_name=VECTORIZE_COLLECTION_OPENAI,
ingest_data=records, ingest_data=records,
search_input="test", search_query="test",
number_of_results=2, number_of_results=2,
pre_delete_collection=True, pre_delete_collection=True,
) )
@ -228,7 +227,7 @@ def test_astra_vectorize_passes_authentication():
api_endpoint=api_endpoint, api_endpoint=api_endpoint,
collection_name=VECTORIZE_COLLECTION_OPENAI_WITH_AUTH, collection_name=VECTORIZE_COLLECTION_OPENAI_WITH_AUTH,
ingest_data=records, ingest_data=records,
search_input="test", search_query="test",
number_of_results=2, number_of_results=2,
pre_delete_collection=True, pre_delete_collection=True,
) )

View file

@ -49,7 +49,7 @@ def rag_graph():
chat_input.get_output("message").value = "What is the meaning of life?" chat_input.get_output("message").value = "What is the meaning of life?"
rag_vector_store = AstraDBVectorStoreComponent(_id="rag-vector-store-123") rag_vector_store = AstraDBVectorStoreComponent(_id="rag-vector-store-123")
rag_vector_store.set( rag_vector_store.set(
search_input=chat_input.message_response, search_query=chat_input.message_response,
api_endpoint="https://astra.example.com", api_endpoint="https://astra.example.com",
token="token", # noqa: S106 token="token", # noqa: S106
embedding_model=openai_embeddings.build_embeddings, embedding_model=openai_embeddings.build_embeddings,