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:
parent
be612eb6d3
commit
22877ae920
28 changed files with 412 additions and 572 deletions
|
|
@ -2,12 +2,10 @@ from abc import abstractmethod
|
|||
from functools import wraps
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from langflow.custom import Component
|
||||
from langflow.field_typing import Text, VectorStore
|
||||
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
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -53,6 +51,19 @@ class LCVectorStoreComponent(Component):
|
|||
raise TypeError(msg)
|
||||
|
||||
trace_type = "retriever"
|
||||
|
||||
inputs = [
|
||||
MultilineInput(
|
||||
name="search_query",
|
||||
display_name="Search Query",
|
||||
tool_mode=True,
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
),
|
||||
]
|
||||
|
||||
outputs = [
|
||||
Output(
|
||||
display_name="Search Results",
|
||||
|
|
@ -122,9 +133,9 @@ class LCVectorStoreComponent(Component):
|
|||
vector_store = self.build_vector_store()
|
||||
self._cached_vector_store = vector_store
|
||||
|
||||
logger.debug(f"Search input: {search_query}")
|
||||
logger.debug(f"Search type: {self.search_type}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log(f"Search input: {search_query}")
|
||||
self.log(f"Search type: {self.search_type}")
|
||||
self.log(f"Number of results: {self.number_of_results}")
|
||||
|
||||
search_results = self.search_with_vector_store(
|
||||
search_query, self.search_type, vector_store, k=self.number_of_results
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
from collections import defaultdict
|
||||
|
||||
from astrapy import DataAPIClient
|
||||
from astrapy import AstraDBAdmin, DataAPIClient
|
||||
from astrapy.admin import parse_api_endpoint
|
||||
from langchain_astradb import AstraDBVectorStore
|
||||
|
||||
|
|
@ -14,7 +14,6 @@ from langflow.io import (
|
|||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -24,52 +23,29 @@ from langflow.utils.version import get_version_info
|
|||
|
||||
class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name: str = "Astra DB"
|
||||
description: str = "Implementation of Vector Store using Astra DB with search capabilities"
|
||||
documentation: str = "https://docs.langflow.org/starter-projects-vector-store-rag"
|
||||
description: str = "Ingest and search documents in Astra DB"
|
||||
documentation: str = "https://docs.datastax.com/en/langflow/astra-components.html"
|
||||
name = "AstraDB"
|
||||
icon: str = "AstraDB"
|
||||
|
||||
_cached_vector_store: AstraDBVectorStore | None = None
|
||||
|
||||
VECTORIZE_PROVIDERS_MAPPING = defaultdict(
|
||||
list,
|
||||
{
|
||||
"Azure OpenAI": [
|
||||
"azureOpenAI",
|
||||
["text-embedding-3-small", "text-embedding-3-large", "text-embedding-ada-002"],
|
||||
],
|
||||
"Hugging Face - Dedicated": ["huggingfaceDedicated", ["endpoint-defined-model"]],
|
||||
"Hugging Face - Serverless": [
|
||||
"huggingface",
|
||||
[
|
||||
"sentence-transformers/all-MiniLM-L6-v2",
|
||||
"intfloat/multilingual-e5-large",
|
||||
"intfloat/multilingual-e5-large-instruct",
|
||||
"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"],
|
||||
],
|
||||
},
|
||||
)
|
||||
base_inputs = LCVectorStoreComponent.inputs
|
||||
if "search_query" not in [input_.name for input_ in base_inputs]:
|
||||
base_inputs.append(
|
||||
MessageTextInput(
|
||||
name="search_query",
|
||||
display_name="Search Query",
|
||||
tool_mode=True,
|
||||
)
|
||||
)
|
||||
if "ingest_data" not in [input_.name for input_ in base_inputs]:
|
||||
base_inputs.append(
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
)
|
||||
)
|
||||
|
||||
inputs = [
|
||||
SecretStrInput(
|
||||
|
|
@ -81,13 +57,15 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
advanced=os.getenv("ASTRA_ENHANCED", "false").lower() == "true",
|
||||
real_time_refresh=True,
|
||||
),
|
||||
SecretStrInput(
|
||||
DropdownInput(
|
||||
name="api_endpoint",
|
||||
display_name="Database" if os.getenv("ASTRA_ENHANCED", "false").lower() == "true" else "API Endpoint",
|
||||
info="API endpoint URL for the Astra DB service.",
|
||||
value="ASTRA_DB_API_ENDPOINT",
|
||||
display_name="Database",
|
||||
info="The Astra DB Database to use.",
|
||||
required=True,
|
||||
refresh_button=True,
|
||||
real_time_refresh=True,
|
||||
options=["Default database"],
|
||||
value="Default database",
|
||||
),
|
||||
DropdownInput(
|
||||
name="collection_name",
|
||||
|
|
@ -126,15 +104,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
input_types=["Embeddings"],
|
||||
info="Allows an embedding model configuration.",
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
),
|
||||
MultilineInput(
|
||||
name="search_input",
|
||||
display_name="Search Query",
|
||||
tool_mode=True,
|
||||
),
|
||||
*base_inputs,
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
display_name="Number of Search Results",
|
||||
|
|
@ -212,26 +182,18 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
return build_config
|
||||
|
||||
def update_providers_mapping(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
|
||||
|
||||
def get_vectorize_providers(self):
|
||||
try:
|
||||
self.log("Dynamically updating list of Vectorize providers.")
|
||||
|
||||
# Get the admin object
|
||||
client = DataAPIClient(token=self.token)
|
||||
admin = client.get_admin()
|
||||
admin = AstraDBAdmin(token=self.token)
|
||||
db_admin = admin.get_database_admin(self.get_api_endpoint())
|
||||
|
||||
# Get the embedding providers
|
||||
db_admin = admin.get_database_admin(self.api_endpoint)
|
||||
# Get the list of embedding providers
|
||||
embedding_providers = db_admin.find_embedding_providers().as_dict()
|
||||
|
||||
vectorize_providers_mapping = {}
|
||||
|
||||
# Map the provider display name to the provider key and models
|
||||
for provider_key, provider_data in embedding_providers["embeddingProviders"].items():
|
||||
display_name = provider_data["displayName"]
|
||||
|
|
@ -244,14 +206,37 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
except Exception as e: # noqa: BLE001
|
||||
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):
|
||||
try:
|
||||
client = DataAPIClient(token=self.token)
|
||||
|
||||
return client.get_database(
|
||||
self.api_endpoint,
|
||||
api_endpoint=self.get_api_endpoint(),
|
||||
token=self.token,
|
||||
)
|
||||
except Exception as e: # noqa: BLE001
|
||||
|
|
@ -259,13 +244,25 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
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):
|
||||
database = self.get_database()
|
||||
if database is None:
|
||||
return ["+ Create new collection"]
|
||||
|
||||
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
|
||||
self.log(f"Error fetching collections: {e}")
|
||||
|
||||
|
|
@ -289,7 +286,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
collection_name = self.get_collection_choice()
|
||||
|
||||
try:
|
||||
collection = database.get_collection(collection_name)
|
||||
collection = database.get_collection(collection_name, keyspace=self.keyspace or None)
|
||||
collection_options = collection.options()
|
||||
except Exception as _: # noqa: BLE001
|
||||
return None
|
||||
|
|
@ -297,8 +294,17 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
return collection_options.vector
|
||||
|
||||
def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None):
|
||||
# Refresh the collection name options
|
||||
build_config["collection_name"]["options"] = self._initialize_collection_options()
|
||||
# Always attempt to update the database list
|
||||
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
|
||||
if field_name == "collection_name":
|
||||
|
|
@ -368,7 +374,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
build_config["embedding_model"]["advanced"] = True
|
||||
|
||||
# Update the providers mapping
|
||||
vectorize_providers = self.update_providers_mapping()
|
||||
vectorize_providers = self.get_vectorize_providers()
|
||||
|
||||
new_parameter = DropdownInput(
|
||||
name="embedding_provider",
|
||||
|
|
@ -402,7 +408,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
)
|
||||
|
||||
# Update the providers mapping
|
||||
vectorize_providers = self.update_providers_mapping()
|
||||
vectorize_providers = self.get_vectorize_providers()
|
||||
model_options = vectorize_providers[field_value][1]
|
||||
|
||||
new_parameter = DropdownInput(
|
||||
|
|
@ -481,7 +487,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
setattr(self, attribute, 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")
|
||||
model_name = self.model or kwargs.get("model")
|
||||
authentication = {**(self.z_04_authentication or {}), **kwargs.get("z_04_authentication", {})}
|
||||
|
|
@ -525,7 +531,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise ImportError(msg) from e
|
||||
|
||||
# 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
|
||||
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
|
||||
environment = (
|
||||
parse_api_endpoint(getattr(self, "api_endpoint", None)).environment
|
||||
if getattr(self, "api_endpoint", None)
|
||||
else None
|
||||
)
|
||||
environment = parse_api_endpoint(self.get_api_endpoint()).environment if self.get_api_endpoint() else None
|
||||
|
||||
# Get Langflow version and platform information
|
||||
__version__ = get_version_info()["version"]
|
||||
|
|
@ -577,16 +579,16 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
vector_store = AstraDBVectorStore(
|
||||
# Astra DB Authentication Parameters
|
||||
token=self.token,
|
||||
api_endpoint=self.api_endpoint,
|
||||
api_endpoint=self.get_api_endpoint(),
|
||||
namespace=self.keyspace or None,
|
||||
collection_name=self.get_collection_choice(),
|
||||
environment=environment,
|
||||
# Astra DB Usage Tracking Parameters
|
||||
ext_callers=[(f"{langflow_prefix}langflow", __version__)],
|
||||
# Astra DB Vector Store Parameters
|
||||
**autodetect_params,
|
||||
**embedding_params,
|
||||
**self.astradb_vectorstore_kwargs,
|
||||
**autodetect_params or {},
|
||||
**embedding_params or {},
|
||||
**self.astradb_vectorstore_kwargs or {},
|
||||
)
|
||||
except Exception as e:
|
||||
msg = f"Error initializing AstraDBVectorStore: {e}"
|
||||
|
|
@ -623,7 +625,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
return "similarity"
|
||||
|
||||
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:
|
||||
args = {
|
||||
|
|
@ -648,7 +650,7 @@ class AstraDBVectorStoreComponent(LCVectorStoreComponent):
|
|||
def search_documents(self, vector_store=None) -> list[Data]:
|
||||
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"Number of results: {self.number_of_results}")
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,16 @@ import os
|
|||
|
||||
import orjson
|
||||
from astrapy.admin import parse_api_endpoint
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers import docs_to_data
|
||||
from langflow.inputs import (
|
||||
BoolInput,
|
||||
DataInput,
|
||||
DictInput,
|
||||
DropdownInput,
|
||||
FloatInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -24,7 +21,6 @@ from langflow.schema import Data
|
|||
class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name: str = "Astra DB Graph"
|
||||
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"
|
||||
icon: str = "AstraDB"
|
||||
|
||||
|
|
@ -56,15 +52,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
info="Metadata key used for incoming links.",
|
||||
advanced=True,
|
||||
),
|
||||
MultilineInput(
|
||||
name="search_input",
|
||||
display_name="Search Input",
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
StrInput(
|
||||
name="keyspace",
|
||||
display_name="Keyspace",
|
||||
|
|
@ -129,14 +117,14 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Metadata Indexing Include",
|
||||
info="Optional list of metadata fields to include in the indexing.",
|
||||
advanced=True,
|
||||
is_list=True,
|
||||
list=True,
|
||||
),
|
||||
StrInput(
|
||||
name="metadata_indexing_exclude",
|
||||
display_name="Metadata Indexing Exclude",
|
||||
info="Optional list of metadata fields to exclude from the indexing.",
|
||||
advanced=True,
|
||||
is_list=True,
|
||||
list=True,
|
||||
),
|
||||
StrInput(
|
||||
name="collection_indexing_policy",
|
||||
|
|
@ -205,7 +193,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise ValueError(msg) from e
|
||||
|
||||
try:
|
||||
logger.debug(f"Initializing Graph Vector Store {self.collection_name}")
|
||||
self.log(f"Initializing Graph Vector Store {self.collection_name}")
|
||||
|
||||
vector_store = AstraDBGraphVectorStore(
|
||||
embedding=self.embedding_model,
|
||||
|
|
@ -232,7 +220,7 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
msg = f"Error initializing AstraDBGraphVectorStore: {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)
|
||||
|
||||
return vector_store
|
||||
|
|
@ -247,14 +235,14 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise TypeError(msg)
|
||||
|
||||
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:
|
||||
vector_store.add_documents(documents)
|
||||
except Exception as e:
|
||||
msg = f"Error adding documents to AstraDBGraphVectorStore: {e}"
|
||||
raise ValueError(msg) from e
|
||||
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:
|
||||
match self.search_type:
|
||||
|
|
@ -287,21 +275,21 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
if not vector_store:
|
||||
vector_store = self.build_vector_store()
|
||||
|
||||
logger.debug("Searching for documents in AstraDBGraphVectorStore.")
|
||||
logger.debug(f"Search input: {self.search_input}")
|
||||
logger.debug(f"Search type: {self.search_type}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log("Searching for documents in AstraDBGraphVectorStore.")
|
||||
self.log(f"Search query: {self.search_query}")
|
||||
self.log(f"Search type: {self.search_type}")
|
||||
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:
|
||||
search_type = self._map_search_type()
|
||||
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
|
||||
# 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:
|
||||
if "links" in doc.metadata:
|
||||
doc.metadata.pop("links")
|
||||
|
|
@ -310,15 +298,15 @@ class AstraDBGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
msg = f"Error performing search in AstraDBGraphVectorStore: {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)
|
||||
|
||||
logger.debug(f"Converted documents to data: {len(data)}")
|
||||
self.log(f"Converted documents to data: {len(data)}")
|
||||
|
||||
self.status = data
|
||||
return data
|
||||
logger.debug("No search input provided. Skipping search.")
|
||||
self.log("No search input provided. Skipping search.")
|
||||
return []
|
||||
|
||||
def get_retriever_kwargs(self):
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
from langchain_community.vectorstores import Cassandra
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.inputs import BoolInput, DictInput, FloatInput
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MessageTextInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
)
|
||||
from langflow.schema import Data
|
||||
|
|
@ -77,14 +74,9 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Cluster arguments",
|
||||
info="Optional dictionary of additional keyword arguments for the Cassandra cluster.",
|
||||
advanced=True,
|
||||
is_list=True,
|
||||
),
|
||||
MultilineInput(name="search_query", display_name="Search Query"),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
@ -114,7 +106,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Search Metadata Filter",
|
||||
info="Optional dictionary of filters to apply to the search query.",
|
||||
advanced=True,
|
||||
is_list=True,
|
||||
list=True,
|
||||
),
|
||||
MessageTextInput(
|
||||
name="body_search",
|
||||
|
|
@ -184,7 +176,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
setup_mode = SetupMode.ASYNC
|
||||
|
||||
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(
|
||||
documents=documents,
|
||||
embedding=self.embedding,
|
||||
|
|
@ -195,7 +187,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
body_index_options=body_index_options,
|
||||
)
|
||||
else:
|
||||
logger.debug("No documents to add to the Vector Store.")
|
||||
self.log("No documents to add to the Vector Store.")
|
||||
table = Cassandra(
|
||||
embedding=self.embedding,
|
||||
table_name=self.table_name,
|
||||
|
|
@ -216,16 +208,16 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
def search_documents(self) -> list[Data]:
|
||||
vector_store = self.build_vector_store()
|
||||
|
||||
logger.debug(f"Search input: {self.search_query}")
|
||||
logger.debug(f"Search type: {self.search_type}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log(f"Search input: {self.search_query}")
|
||||
self.log(f"Search type: {self.search_type}")
|
||||
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():
|
||||
try:
|
||||
search_type = self._map_search_type()
|
||||
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)
|
||||
except KeyError as e:
|
||||
|
|
@ -237,7 +229,7 @@ class CassandraVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise ValueError(msg) from e
|
||||
raise
|
||||
|
||||
logger.debug(f"Retrieved documents: {len(docs)}")
|
||||
self.log(f"Retrieved documents: {len(docs)}")
|
||||
|
||||
data = docs_to_data(docs)
|
||||
self.status = data
|
||||
|
|
|
|||
|
|
@ -1,18 +1,15 @@
|
|||
from uuid import UUID
|
||||
|
||||
from langchain_community.graph_vectorstores import CassandraGraphVectorStore
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.inputs import DictInput, FloatInput
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MessageTextInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
)
|
||||
from langflow.schema import Data
|
||||
|
|
@ -21,7 +18,6 @@ from langflow.schema import Data
|
|||
class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Cassandra Graph"
|
||||
description = "Cassandra Graph Vector Store"
|
||||
documentation = "https://python.langchain.com/v0.2/api_reference/community/graph_vectorstores.html"
|
||||
name = "CassandraGraph"
|
||||
icon = "Cassandra"
|
||||
|
||||
|
|
@ -66,14 +62,9 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Cluster arguments",
|
||||
info="Optional dictionary of additional keyword arguments for the Cassandra cluster.",
|
||||
advanced=True,
|
||||
is_list=True,
|
||||
),
|
||||
MultilineInput(name="search_query", display_name="Search Query"),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
@ -116,7 +107,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Search Metadata Filter",
|
||||
info="Optional dictionary of filters to apply to the search query.",
|
||||
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
|
||||
|
||||
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(
|
||||
documents=documents,
|
||||
embedding=self.embedding,
|
||||
|
|
@ -172,7 +163,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
keyspace=self.keyspace,
|
||||
)
|
||||
else:
|
||||
logger.debug("No documents to add to the Vector Store.")
|
||||
self.log("No documents to add to the Vector Store.")
|
||||
store = CassandraGraphVectorStore(
|
||||
embedding=self.embedding,
|
||||
node_table=self.table_name,
|
||||
|
|
@ -195,16 +186,16 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
def search_documents(self) -> list[Data]:
|
||||
vector_store = self.build_vector_store()
|
||||
|
||||
logger.debug(f"Search input: {self.search_query}")
|
||||
logger.debug(f"Search type: {self.search_type}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log(f"Search input: {self.search_query}")
|
||||
self.log(f"Search type: {self.search_type}")
|
||||
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():
|
||||
try:
|
||||
search_type = self._map_search_type()
|
||||
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)
|
||||
except KeyError as e:
|
||||
|
|
@ -216,7 +207,7 @@ class CassandraGraphVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise ValueError(msg) from e
|
||||
raise
|
||||
|
||||
logger.debug(f"Retrieved documents: {len(docs)}")
|
||||
self.log(f"Retrieved documents: {len(docs)}")
|
||||
|
||||
data = docs_to_data(docs)
|
||||
self.status = data
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ from copy import deepcopy
|
|||
|
||||
from chromadb.config import Settings
|
||||
from langchain_chroma import Chroma
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -15,7 +14,6 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "Chroma DB"
|
||||
description: str = "Chroma Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/chroma"
|
||||
name = "Chroma"
|
||||
icon = "Chroma"
|
||||
|
||||
|
|
@ -29,15 +27,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
|
|||
name="persist_directory",
|
||||
display_name="Persist Directory",
|
||||
),
|
||||
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"]),
|
||||
StrInput(
|
||||
name="chroma_server_cors_allow_origins",
|
||||
|
|
@ -153,7 +143,7 @@ class ChromaVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise TypeError(msg)
|
||||
|
||||
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)
|
||||
else:
|
||||
logger.debug("No documents to add to the Vector Store.")
|
||||
self.log("No documents to add to the Vector Store.")
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@ from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cache
|
|||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.inputs import BoolInput, FloatInput
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
DictInput,
|
||||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -19,7 +17,6 @@ from langflow.schema import Data
|
|||
class ClickhouseVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Clickhouse"
|
||||
description = "Clickhouse Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/clickhouse/"
|
||||
name = "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),
|
||||
DictInput(name="index_query_params", display_name="index query params", advanced=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@ from langchain_community.vectorstores import CouchbaseVectorStore
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
class CouchbaseVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Couchbase"
|
||||
description = "Couchbase Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.1/docs/integrations/document_loaders/couchbase/"
|
||||
name = "Couchbase"
|
||||
icon = "Couchbase"
|
||||
|
||||
|
|
@ -25,12 +24,7 @@ class CouchbaseVectorStoreComponent(LCVectorStoreComponent):
|
|||
StrInput(name="scope_name", display_name="Scope Name", required=True),
|
||||
StrInput(name="collection_name", display_name="Collection Name", required=True),
|
||||
StrInput(name="index_name", display_name="Index Name", required=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@ from typing import Any
|
|||
|
||||
from langchain.schema import Document
|
||||
from langchain_elasticsearch import ElasticsearchStore
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
FloatInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -23,7 +20,6 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "Elasticsearch"
|
||||
description: str = "Elasticsearch Vector Store with with advanced, customizable search capabilities."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/elasticsearch"
|
||||
name = "Elasticsearch"
|
||||
icon = "ElasticsearchStore"
|
||||
|
||||
|
|
@ -47,11 +43,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
value="langflow",
|
||||
info="The index name where the vectors will be stored in Elasticsearch cluster.",
|
||||
),
|
||||
MultilineInput(
|
||||
name="search_input",
|
||||
display_name="Search Input",
|
||||
info="Enter a search query. Leave empty to retrieve all documents.",
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
StrInput(
|
||||
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."
|
||||
),
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
HandleInput(
|
||||
name="embedding",
|
||||
display_name="Embedding",
|
||||
|
|
@ -155,7 +142,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
documents.append(data.to_lc_document())
|
||||
else:
|
||||
error_message = "Vector Store Inputs must be Data objects."
|
||||
logger.error(error_message)
|
||||
self.log(error_message)
|
||||
raise TypeError(error_message)
|
||||
return documents
|
||||
|
||||
|
|
@ -163,10 +150,10 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
"""Adds documents to the Vector Store."""
|
||||
documents = self._prepare_documents()
|
||||
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)
|
||||
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]]:
|
||||
"""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()
|
||||
if search_type not in {"similarity", "mmr"}:
|
||||
msg = f"Invalid search type: {self.search_type}"
|
||||
logger.error(msg)
|
||||
self.log(msg)
|
||||
raise ValueError(msg)
|
||||
try:
|
||||
if search_type == "similarity":
|
||||
|
|
@ -192,7 +179,7 @@ class ElasticsearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
"Error occurred while querying the Elasticsearch VectorStore,"
|
||||
" there is no Data into the VectorStore."
|
||||
)
|
||||
logger.exception(msg)
|
||||
self.log(msg)
|
||||
raise ValueError(msg) from e
|
||||
return [
|
||||
{"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.
|
||||
"""
|
||||
results = self.search(self.search_input)
|
||||
results = self.search(self.search_query)
|
||||
retrieved_data = [
|
||||
Data(
|
||||
text=result["page_content"],
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
from langchain_community.vectorstores import FAISS
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -12,7 +11,6 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "FAISS"
|
||||
description: str = "FAISS Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss"
|
||||
name = "FAISS"
|
||||
icon = "FAISS"
|
||||
|
||||
|
|
@ -27,15 +25,7 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Persist Directory",
|
||||
info="Path to save the FAISS index. It will be relative to where Langflow is running.",
|
||||
),
|
||||
MultilineInput(
|
||||
name="search_query",
|
||||
display_name="Search Query",
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
BoolInput(
|
||||
name="allow_dangerous_deserialization",
|
||||
display_name="Allow Dangerous Deserialization",
|
||||
|
|
@ -93,8 +83,8 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
|||
msg = "Failed to load the FAISS index."
|
||||
raise ValueError(msg)
|
||||
|
||||
logger.debug(f"Search input: {self.search_query}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log(f"Search input: {self.search_query}")
|
||||
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():
|
||||
docs = vector_store.similarity_search(
|
||||
|
|
@ -102,11 +92,11 @@ class FaissVectorStoreComponent(LCVectorStoreComponent):
|
|||
k=self.number_of_results,
|
||||
)
|
||||
|
||||
logger.debug(f"Retrieved documents: {len(docs)}")
|
||||
self.log(f"Retrieved documents: {len(docs)}")
|
||||
|
||||
data = docs_to_data(docs)
|
||||
logger.debug(f"Converted documents to data: {len(data)}")
|
||||
logger.debug(data)
|
||||
self.log(f"Converted documents to data: {len(data)}")
|
||||
self.log(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 []
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers import docs_to_data
|
||||
from langflow.inputs import DictInput, FloatInput
|
||||
from langflow.io import (
|
||||
BoolInput,
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
|
|
@ -19,7 +16,6 @@ from langflow.schema import Data
|
|||
class HCDVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name: str = "Hyper-Converged Database"
|
||||
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"
|
||||
icon: str = "HCD"
|
||||
|
||||
|
|
@ -51,15 +47,7 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
|
|||
value="HCD_API_ENDPOINT",
|
||||
required=True,
|
||||
),
|
||||
MultilineInput(
|
||||
name="search_input",
|
||||
display_name="Search Input",
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
StrInput(
|
||||
name="namespace",
|
||||
display_name="Namespace",
|
||||
|
|
@ -263,14 +251,14 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
|
|||
raise TypeError(msg)
|
||||
|
||||
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:
|
||||
vector_store.add_documents(documents)
|
||||
except Exception as e:
|
||||
msg = f"Error adding documents to AstraDBVectorStore: {e}"
|
||||
raise ValueError(msg) from e
|
||||
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:
|
||||
if self.search_type == "Similarity with score threshold":
|
||||
|
|
@ -294,27 +282,27 @@ class HCDVectorStoreComponent(LCVectorStoreComponent):
|
|||
def search_documents(self) -> list[Data]:
|
||||
vector_store = self.build_vector_store()
|
||||
|
||||
logger.debug(f"Search input: {self.search_input}")
|
||||
logger.debug(f"Search type: {self.search_type}")
|
||||
logger.debug(f"Number of results: {self.number_of_results}")
|
||||
self.log(f"Search query: {self.search_query}")
|
||||
self.log(f"Search type: {self.search_type}")
|
||||
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:
|
||||
search_type = self._map_search_type()
|
||||
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:
|
||||
msg = f"Error performing search in AstraDBVectorStore: {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)
|
||||
logger.debug(f"Converted documents to data: {len(data)}")
|
||||
self.log(f"Converted documents to data: {len(data)}")
|
||||
self.status = data
|
||||
return data
|
||||
logger.debug("No search input provided. Skipping search.")
|
||||
self.log("No search input provided. Skipping search.")
|
||||
return []
|
||||
|
||||
def get_retriever_kwargs(self):
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@ from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cache
|
|||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.io import (
|
||||
BoolInput,
|
||||
DataInput,
|
||||
DictInput,
|
||||
DropdownInput,
|
||||
FloatInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -20,7 +18,6 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "Milvus"
|
||||
description: str = "Milvus vector store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/milvus"
|
||||
name = "Milvus"
|
||||
icon = "Milvus"
|
||||
|
||||
|
|
@ -53,12 +50,7 @@ class MilvusVectorStoreComponent(LCVectorStoreComponent):
|
|||
DictInput(name="search_params", display_name="Search Parameters", advanced=True),
|
||||
BoolInput(name="drop_old", display_name="Drop Old Collection", value=False, advanced=True),
|
||||
FloatInput(name="timeout", display_name="Timeout", advanced=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@ from langchain_community.vectorstores import MongoDBAtlasVectorSearch
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
class MongoVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "MongoDB Atlas"
|
||||
description = "MongoDB Atlas Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/mongodb_atlas"
|
||||
name = "MongoDBAtlasVector"
|
||||
icon = "MongoDB"
|
||||
|
||||
|
|
@ -30,12 +29,7 @@ class MongoVectorStoreComponent(LCVectorStoreComponent):
|
|||
StrInput(name="db_name", display_name="Database Name", required=True),
|
||||
StrInput(name="collection_name", display_name="Collection Name", required=True),
|
||||
StrInput(name="index_name", display_name="Index Name", required=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@ import json
|
|||
from typing import Any
|
||||
|
||||
from langchain_community.vectorstores import OpenSearchVectorSearch
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.io import (
|
||||
BoolInput,
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
FloatInput,
|
||||
HandleInput,
|
||||
|
|
@ -24,7 +22,6 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "OpenSearch"
|
||||
description: str = "OpenSearch Vector Store with advanced, customizable search capabilities."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/opensearch"
|
||||
name = "OpenSearch"
|
||||
icon = "OpenSearch"
|
||||
|
||||
|
|
@ -41,20 +38,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
value="langflow",
|
||||
info="The index name where the vectors will be stored in OpenSearch cluster.",
|
||||
),
|
||||
MultilineInput(
|
||||
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,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||
DropdownInput(
|
||||
name="search_type",
|
||||
|
|
@ -120,7 +104,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
from langchain_community.vectorstores import OpenSearchVectorSearch
|
||||
except ImportError as e:
|
||||
error_message = f"Failed to import required modules: {e}"
|
||||
logger.exception(error_message)
|
||||
self.log(error_message)
|
||||
raise ImportError(error_message) from e
|
||||
|
||||
try:
|
||||
|
|
@ -136,7 +120,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
)
|
||||
except Exception as e:
|
||||
error_message = f"Failed to create OpenSearchVectorSearch instance: {e}"
|
||||
logger.exception(error_message)
|
||||
self.log(error_message)
|
||||
raise RuntimeError(error_message) from e
|
||||
|
||||
if self.ingest_data:
|
||||
|
|
@ -152,19 +136,19 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
documents.append(_input.to_lc_document())
|
||||
else:
|
||||
error_message = f"Expected Data object, got {type(_input)}"
|
||||
logger.error(error_message)
|
||||
self.log(error_message)
|
||||
raise TypeError(error_message)
|
||||
|
||||
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:
|
||||
vector_store.add_documents(documents)
|
||||
except Exception as 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
|
||||
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]]:
|
||||
"""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)
|
||||
except json.JSONDecodeError as e:
|
||||
error_message = f"Invalid hybrid search query JSON: {e}"
|
||||
logger.exception(error_message)
|
||||
self.log(error_message)
|
||||
raise ValueError(error_message) from e
|
||||
|
||||
results = vector_store.client.search(index=self.index_name, body=hybrid_query)
|
||||
|
|
@ -223,11 +207,11 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
except Exception as e:
|
||||
error_message = f"Error during search: {e}"
|
||||
logger.exception(error_message)
|
||||
self.log(error_message)
|
||||
raise RuntimeError(error_message) from e
|
||||
|
||||
error_message = f"Error during search. Invalid search type: {self.search_type}"
|
||||
logger.error(error_message)
|
||||
self.log(error_message)
|
||||
raise ValueError(error_message)
|
||||
|
||||
def search_documents(self) -> list[Data]:
|
||||
|
|
@ -236,7 +220,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
If no search input is provided, retrieve all documents.
|
||||
"""
|
||||
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)
|
||||
retrieved_data = [
|
||||
Data(
|
||||
|
|
@ -247,7 +231,7 @@ class OpenSearchVectorStoreComponent(LCVectorStoreComponent):
|
|||
]
|
||||
except Exception as e:
|
||||
error_message = f"Error during document search: {e}"
|
||||
logger.exception(error_message)
|
||||
self.log(error_message)
|
||||
raise RuntimeError(error_message) from e
|
||||
|
||||
self.status = retrieved_data
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from langchain_community.vectorstores import PGVector
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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.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):
|
||||
display_name = "PGVector"
|
||||
description = "PGVector Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/pgvector/"
|
||||
name = "pgvector"
|
||||
icon = "cpu"
|
||||
|
||||
inputs = [
|
||||
SecretStrInput(name="pg_server_url", display_name="PostgreSQL Server Connection String", required=True),
|
||||
StrInput(name="collection_name", display_name="Table", required=True),
|
||||
MultilineInput(name="search_query", display_name="Search Query"),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingestion Data",
|
||||
is_list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -3,14 +3,13 @@ from langchain_pinecone import Pinecone
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
class PineconeVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Pinecone"
|
||||
description = "Pinecone Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/pinecone/"
|
||||
name = "Pinecone"
|
||||
icon = "Pinecone"
|
||||
inputs = [
|
||||
|
|
@ -31,12 +30,7 @@ class PineconeVectorStoreComponent(LCVectorStoreComponent):
|
|||
value="text",
|
||||
advanced=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -4,11 +4,9 @@ from langchain_community.vectorstores import Qdrant
|
|||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
DropdownInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
SecretStrInput,
|
||||
StrInput,
|
||||
)
|
||||
|
|
@ -18,7 +16,6 @@ from langflow.schema import Data
|
|||
class QdrantVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Qdrant"
|
||||
description = "Qdrant Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/qdrant"
|
||||
icon = "Qdrant"
|
||||
|
||||
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="metadata_payload_key", display_name="Metadata Payload Key", value="metadata", advanced=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from langchain_community.vectorstores.redis import Redis
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,6 @@ class RedisVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "Redis"
|
||||
description: str = "Implementation of Vector Store using Redis"
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/redis"
|
||||
name = "Redis"
|
||||
icon = "Redis"
|
||||
|
||||
|
|
@ -29,12 +28,7 @@ class RedisVectorStoreComponent(LCVectorStoreComponent):
|
|||
name="schema",
|
||||
display_name="Schema",
|
||||
),
|
||||
MultilineInput(name="search_query", display_name="Search Query"),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
display_name="Number of Results",
|
||||
|
|
|
|||
|
|
@ -3,14 +3,13 @@ from supabase.client import Client, create_client
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
class SupabaseVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Supabase"
|
||||
description = "Supabase Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/supabase/"
|
||||
name = "SupabaseVectorStore"
|
||||
icon = "Supabase"
|
||||
|
||||
|
|
@ -19,12 +18,7 @@ class SupabaseVectorStoreComponent(LCVectorStoreComponent):
|
|||
SecretStrInput(name="supabase_service_key", display_name="Supabase Service Key", required=True),
|
||||
StrInput(name="table_name", display_name="Table Name", advanced=True),
|
||||
StrInput(name="query_name", display_name="Query Name"),
|
||||
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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ from langchain_community.vectorstores import UpstashVectorStore
|
|||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
from langflow.helpers.data import docs_to_data
|
||||
from langflow.io import (
|
||||
DataInput,
|
||||
HandleInput,
|
||||
IntInput,
|
||||
MultilineInput,
|
||||
|
|
@ -16,7 +15,6 @@ from langflow.schema import Data
|
|||
class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Upstash"
|
||||
description = "Upstash Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/upstash/"
|
||||
name = "Upstash"
|
||||
icon = "Upstash"
|
||||
|
||||
|
|
@ -45,17 +43,12 @@ class UpstashVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Namespace",
|
||||
info="Leave empty for default namespace.",
|
||||
),
|
||||
MultilineInput(name="search_query", display_name="Search Query"),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
MultilineInput(
|
||||
name="metadata_filter",
|
||||
display_name="Metadata Filter",
|
||||
info="Filters documents by metadata. Look at the documentation for more information.",
|
||||
),
|
||||
DataInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
is_list=True,
|
||||
),
|
||||
HandleInput(
|
||||
name="embedding",
|
||||
display_name="Embedding",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from langchain_community.vectorstores import Vectara
|
||||
from loguru import logger
|
||||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -17,7 +16,6 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
|
|||
|
||||
display_name: str = "Vectara"
|
||||
description: str = "Vectara Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/vectara"
|
||||
name = "Vectara"
|
||||
icon = "Vectara"
|
||||
|
||||
|
|
@ -30,16 +28,7 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
|
|||
display_name="Embedding",
|
||||
input_types=["Embeddings"],
|
||||
),
|
||||
HandleInput(
|
||||
name="ingest_data",
|
||||
display_name="Ingest Data",
|
||||
input_types=["Document", "Data"],
|
||||
is_list=True,
|
||||
),
|
||||
MessageTextInput(
|
||||
name="search_query",
|
||||
display_name="Search Query",
|
||||
),
|
||||
*LCVectorStoreComponent.inputs,
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
display_name="Number of Results",
|
||||
|
|
@ -81,11 +70,11 @@ class VectaraVectorStoreComponent(LCVectorStoreComponent):
|
|||
documents.append(_input)
|
||||
|
||||
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)
|
||||
self.status = f"Added {len(documents)} documents to Vectara"
|
||||
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"
|
||||
|
||||
def search_documents(self) -> list[Data]:
|
||||
|
|
|
|||
|
|
@ -58,7 +58,12 @@ class VectaraRagComponent(Component):
|
|||
StrInput(name="vectara_customer_id", display_name="Vectara Customer 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),
|
||||
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(
|
||||
name="lexical_interpolation",
|
||||
display_name="Hybrid Search Factor",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ class VectaraSelfQueryRetriverComponent(CustomComponent):
|
|||
|
||||
display_name: str = "Vectara Self Query Retriever for Vectara Vector Store"
|
||||
description: str = "Implementation of Vectara Self Query Retriever"
|
||||
documentation = "https://python.langchain.com/docs/integrations/retrievers/self_query/vectara_self_query"
|
||||
name = "VectaraSelfQueryRetriver"
|
||||
icon = "Vectara"
|
||||
legacy = True
|
||||
|
|
|
|||
|
|
@ -3,14 +3,13 @@ from langchain_community.vectorstores import Weaviate
|
|||
|
||||
from langflow.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
|
||||
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
|
||||
|
||||
|
||||
class WeaviateVectorStoreComponent(LCVectorStoreComponent):
|
||||
display_name = "Weaviate"
|
||||
description = "Weaviate Vector Store with search capabilities"
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/weaviate"
|
||||
name = "Weaviate"
|
||||
icon = "Weaviate"
|
||||
|
||||
|
|
@ -24,12 +23,7 @@ class WeaviateVectorStoreComponent(LCVectorStoreComponent):
|
|||
info="Requires capitalized index name.",
|
||||
),
|
||||
StrInput(name="text_key", display_name="Text Key", value="text", advanced=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"]),
|
||||
IntInput(
|
||||
name="number_of_results",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -33,7 +33,7 @@ def rag_graph():
|
|||
chat_input = ChatInput()
|
||||
rag_vector_store = AstraDBVectorStoreComponent()
|
||||
rag_vector_store.set(
|
||||
search_input=chat_input.message_response,
|
||||
search_query=chat_input.message_response,
|
||||
embedding_model=openai_embeddings.build_embeddings,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ async def test_base(astradb_client: AstraDB):
|
|||
},
|
||||
)
|
||||
|
||||
assert results["vector_store"] is not None
|
||||
assert results["search_results"] == []
|
||||
assert astradb_client.collection(BASIC_COLLECTION)
|
||||
|
||||
|
|
@ -73,7 +72,7 @@ async def test_astra_embeds_and_search():
|
|||
"api_endpoint": api_endpoint,
|
||||
"collection_name": BASIC_COLLECTION,
|
||||
"number_of_results": 1,
|
||||
"search_input": "test1",
|
||||
"search_query": "test1",
|
||||
"ingest_data": ComponentInputHandle(
|
||||
clazz=TextToData, inputs={"text_data": ["test1", "test2"]}, output_name="from_text"
|
||||
),
|
||||
|
|
@ -117,7 +116,7 @@ def test_astra_vectorize():
|
|||
api_endpoint=api_endpoint,
|
||||
collection_name=VECTORIZE_COLLECTION,
|
||||
ingest_data=records,
|
||||
search_input="test",
|
||||
search_query="test",
|
||||
number_of_results=2,
|
||||
pre_delete_collection=True,
|
||||
)
|
||||
|
|
@ -173,7 +172,7 @@ def test_astra_vectorize_with_provider_api_key():
|
|||
api_endpoint=api_endpoint,
|
||||
collection_name=VECTORIZE_COLLECTION_OPENAI,
|
||||
ingest_data=records,
|
||||
search_input="test",
|
||||
search_query="test",
|
||||
number_of_results=2,
|
||||
pre_delete_collection=True,
|
||||
)
|
||||
|
|
@ -228,7 +227,7 @@ def test_astra_vectorize_passes_authentication():
|
|||
api_endpoint=api_endpoint,
|
||||
collection_name=VECTORIZE_COLLECTION_OPENAI_WITH_AUTH,
|
||||
ingest_data=records,
|
||||
search_input="test",
|
||||
search_query="test",
|
||||
number_of_results=2,
|
||||
pre_delete_collection=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ def rag_graph():
|
|||
chat_input.get_output("message").value = "What is the meaning of life?"
|
||||
rag_vector_store = AstraDBVectorStoreComponent(_id="rag-vector-store-123")
|
||||
rag_vector_store.set(
|
||||
search_input=chat_input.message_response,
|
||||
search_query=chat_input.message_response,
|
||||
api_endpoint="https://astra.example.com",
|
||||
token="token", # noqa: S106
|
||||
embedding_model=openai_embeddings.build_embeddings,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue