Add vector search components and vector store search components
This commit is contained in:
parent
a61bb83bff
commit
a3924d657c
16 changed files with 33 additions and 23 deletions
|
|
@ -0,0 +1,112 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langflow.components.vectorstores.AstraDB import AstraDBVectorStoreComponent
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.field_typing import Embeddings, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class AstraDBSearchComponent(LCVectorStoreComponent):
|
||||
display_name = "AstraDB Search"
|
||||
description = "Searches an existing AstraDB Vector Store"
|
||||
icon = "AstraDB"
|
||||
field_order = ["token", "api_endpoint", "collection_name", "input_value", "embedding"]
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {
|
||||
"display_name": "Input Value",
|
||||
"info": "Input value to search",
|
||||
},
|
||||
"embedding": {"display_name": "Embedding", "info": "Embedding to use"},
|
||||
"collection_name": {"display_name": "Collection Name", "info": "Collection name"},
|
||||
"token": {"display_name": "Token", "info": "Token to use", "password": True},
|
||||
"api_endpoint": {"display_name": "API Endpoint", "info": "API Endpoint to use"},
|
||||
"namespace": {"display_name": "Namespace", "info": "Namespace to use", "advanced": True},
|
||||
"metric": {"display_name": "Metric", "info": "Metric to use", "advanced": True},
|
||||
"batch_size": {"display_name": "Batch Size", "info": "Batch size to use", "advanced": True},
|
||||
"bulk_insert_batch_concurrency": {
|
||||
"display_name": "Bulk Insert Batch Concurrency",
|
||||
"info": "Bulk Insert Batch Concurrency to use",
|
||||
"advanced": True,
|
||||
},
|
||||
"bulk_insert_overwrite_concurrency": {
|
||||
"display_name": "Bulk Insert Overwrite Concurrency",
|
||||
"info": "Bulk Insert Overwrite Concurrency to use",
|
||||
"advanced": True,
|
||||
},
|
||||
"bulk_delete_concurrency": {
|
||||
"display_name": "Bulk Delete Concurrency",
|
||||
"info": "Bulk Delete Concurrency to use",
|
||||
"advanced": True,
|
||||
},
|
||||
"setup_mode": {
|
||||
"display_name": "Setup Mode",
|
||||
"info": "Setup mode for the vector store",
|
||||
"options": ["Sync", "Async", "Off"],
|
||||
"advanced": True,
|
||||
},
|
||||
"pre_delete_collection": {
|
||||
"display_name": "Pre Delete Collection",
|
||||
"info": "Pre delete collection",
|
||||
"advanced": True,
|
||||
},
|
||||
"metadata_indexing_include": {
|
||||
"display_name": "Metadata Indexing Include",
|
||||
"info": "Metadata Indexing Include",
|
||||
"advanced": True,
|
||||
},
|
||||
"metadata_indexing_exclude": {
|
||||
"display_name": "Metadata Indexing Exclude",
|
||||
"info": "Metadata Indexing Exclude",
|
||||
"advanced": True,
|
||||
},
|
||||
"collection_indexing_policy": {
|
||||
"display_name": "Collection Indexing Policy",
|
||||
"info": "Collection Indexing Policy",
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
embedding: Embeddings,
|
||||
collection_name: str,
|
||||
input_value: Text,
|
||||
search_type: str = "Similarity",
|
||||
token: Optional[str] = None,
|
||||
api_endpoint: Optional[str] = None,
|
||||
namespace: Optional[str] = None,
|
||||
metric: Optional[str] = None,
|
||||
batch_size: Optional[int] = None,
|
||||
bulk_insert_batch_concurrency: Optional[int] = None,
|
||||
bulk_insert_overwrite_concurrency: Optional[int] = None,
|
||||
bulk_delete_concurrency: Optional[int] = None,
|
||||
setup_mode: str = "Sync",
|
||||
pre_delete_collection: bool = False,
|
||||
metadata_indexing_include: Optional[List[str]] = None,
|
||||
metadata_indexing_exclude: Optional[List[str]] = None,
|
||||
collection_indexing_policy: Optional[dict] = None,
|
||||
) -> List[Record]:
|
||||
vector_store = AstraDBVectorStoreComponent().build(
|
||||
embedding=embedding,
|
||||
collection_name=collection_name,
|
||||
token=token,
|
||||
api_endpoint=api_endpoint,
|
||||
namespace=namespace,
|
||||
metric=metric,
|
||||
batch_size=batch_size,
|
||||
bulk_insert_batch_concurrency=bulk_insert_batch_concurrency,
|
||||
bulk_insert_overwrite_concurrency=bulk_insert_overwrite_concurrency,
|
||||
bulk_delete_concurrency=bulk_delete_concurrency,
|
||||
setup_mode=setup_mode,
|
||||
pre_delete_collection=pre_delete_collection,
|
||||
metadata_indexing_include=metadata_indexing_include,
|
||||
metadata_indexing_exclude=metadata_indexing_exclude,
|
||||
collection_indexing_policy=collection_indexing_policy,
|
||||
)
|
||||
return self.search_with_vector_store(input_value, search_type, vector_store)
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
from typing import List, Optional
|
||||
|
||||
import chromadb # type: ignore
|
||||
from langchain_community.vectorstores.chroma import Chroma
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.field_typing import Embeddings, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class ChromaSearchComponent(LCVectorStoreComponent):
|
||||
"""
|
||||
A custom component for implementing a Vector Store using Chroma.
|
||||
"""
|
||||
|
||||
display_name: str = "Chroma Search"
|
||||
description: str = "Search a Chroma collection for similar documents."
|
||||
icon = "Chroma"
|
||||
|
||||
def build_config(self):
|
||||
"""
|
||||
Builds the configuration for the component.
|
||||
|
||||
Returns:
|
||||
- dict: A dictionary containing the configuration options for the component.
|
||||
"""
|
||||
return {
|
||||
"input_value": {"display_name": "Input"},
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"collection_name": {"display_name": "Collection Name", "value": "langflow"},
|
||||
# "persist": {"display_name": "Persist"},
|
||||
"index_directory": {"display_name": "Index Directory"},
|
||||
"code": {"show": False, "display_name": "Code"},
|
||||
"embedding": {
|
||||
"display_name": "Embedding",
|
||||
"info": "Embedding model to vectorize inputs (make sure to use same as index)",
|
||||
},
|
||||
"chroma_server_cors_allow_origins": {
|
||||
"display_name": "Server CORS Allow Origins",
|
||||
"advanced": True,
|
||||
},
|
||||
"chroma_server_host": {"display_name": "Server Host", "advanced": True},
|
||||
"chroma_server_port": {"display_name": "Server Port", "advanced": True},
|
||||
"chroma_server_grpc_port": {
|
||||
"display_name": "Server gRPC Port",
|
||||
"advanced": True,
|
||||
},
|
||||
"chroma_server_ssl_enabled": {
|
||||
"display_name": "Server SSL Enabled",
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
collection_name: str,
|
||||
embedding: Embeddings,
|
||||
chroma_server_ssl_enabled: bool,
|
||||
index_directory: Optional[str] = None,
|
||||
chroma_server_cors_allow_origins: Optional[str] = None,
|
||||
chroma_server_host: Optional[str] = None,
|
||||
chroma_server_port: Optional[int] = None,
|
||||
chroma_server_grpc_port: Optional[int] = None,
|
||||
) -> List[Record]:
|
||||
"""
|
||||
Builds the Vector Store or BaseRetriever object.
|
||||
|
||||
Args:
|
||||
- collection_name (str): The name of the collection.
|
||||
- persist_directory (Optional[str]): The directory to persist the Vector Store to.
|
||||
- chroma_server_ssl_enabled (bool): Whether to enable SSL for the Chroma server.
|
||||
- persist (bool): Whether to persist the Vector Store or not.
|
||||
- embedding (Optional[Embeddings]): The embeddings to use for the Vector Store.
|
||||
- documents (Optional[Document]): The documents to use for the Vector Store.
|
||||
- chroma_server_cors_allow_origins (Optional[str]): The CORS allow origins for the Chroma server.
|
||||
- chroma_server_host (Optional[str]): The host for the Chroma server.
|
||||
- chroma_server_port (Optional[int]): The port for the Chroma server.
|
||||
- chroma_server_grpc_port (Optional[int]): The gRPC port for the Chroma server.
|
||||
|
||||
Returns:
|
||||
- Union[VectorStore, BaseRetriever]: The Vector Store or BaseRetriever object.
|
||||
"""
|
||||
|
||||
# Chroma settings
|
||||
chroma_settings = None
|
||||
|
||||
if chroma_server_host is not None:
|
||||
chroma_settings = chromadb.config.Settings(
|
||||
chroma_server_cors_allow_origins=chroma_server_cors_allow_origins or None,
|
||||
chroma_server_host=chroma_server_host,
|
||||
chroma_server_port=chroma_server_port or None,
|
||||
chroma_server_grpc_port=chroma_server_grpc_port or None,
|
||||
chroma_server_ssl_enabled=chroma_server_ssl_enabled,
|
||||
)
|
||||
if index_directory:
|
||||
index_directory = self.resolve_path(index_directory)
|
||||
vector_store = Chroma(
|
||||
embedding_function=embedding,
|
||||
collection_name=collection_name,
|
||||
persist_directory=index_directory,
|
||||
client_settings=chroma_settings,
|
||||
)
|
||||
|
||||
return self.search_with_vector_store(input_value, search_type, vector_store)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
from typing import List
|
||||
|
||||
from langchain_community.vectorstores.faiss import FAISS
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.field_typing import Embeddings, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class FAISSSearchComponent(LCVectorStoreComponent):
|
||||
display_name = "FAISS Search"
|
||||
description = "Search a FAISS Vector Store for similar documents."
|
||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/faiss"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"folder_path": {
|
||||
"display_name": "Folder Path",
|
||||
"info": "Path to save the FAISS index. It will be relative to where Langflow is running.",
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"index_name": {"display_name": "Index Name"},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
input_value: Text,
|
||||
embedding: Embeddings,
|
||||
folder_path: str,
|
||||
index_name: str = "langflow_index",
|
||||
) -> List[Record]:
|
||||
if not folder_path:
|
||||
raise ValueError("Folder path is required to save the FAISS index.")
|
||||
path = self.resolve_path(folder_path)
|
||||
vector_store = FAISS.load_local(folder_path=Text(path), embeddings=embedding, index_name=index_name)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to load the FAISS index.")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type="similarity"
|
||||
)
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.MongoDBAtlasVector import MongoDBAtlasComponent
|
||||
from langflow.field_typing import Embeddings, NestedDict, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class MongoDBAtlasSearchComponent(LCVectorStoreComponent):
|
||||
display_name = "MongoDB Atlas Search"
|
||||
description = "Search a MongoDB Atlas Vector Store for similar documents."
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"collection_name": {"display_name": "Collection Name"},
|
||||
"db_name": {"display_name": "Database Name"},
|
||||
"index_name": {"display_name": "Index Name"},
|
||||
"mongodb_atlas_cluster_uri": {"display_name": "MongoDB Atlas Cluster URI"},
|
||||
"search_kwargs": {"display_name": "Search Kwargs", "advanced": True},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
embedding: Embeddings,
|
||||
collection_name: str = "",
|
||||
db_name: str = "",
|
||||
index_name: str = "",
|
||||
mongodb_atlas_cluster_uri: str = "",
|
||||
search_kwargs: Optional[NestedDict] = None,
|
||||
) -> List[Record]:
|
||||
search_kwargs = search_kwargs or {}
|
||||
vector_store = MongoDBAtlasComponent().build(
|
||||
mongodb_atlas_cluster_uri=mongodb_atlas_cluster_uri,
|
||||
collection_name=collection_name,
|
||||
db_name=db_name,
|
||||
embedding=embedding,
|
||||
index_name=index_name,
|
||||
)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to create MongoDB Atlas Vector Store")
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type=search_type
|
||||
)
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.Pinecone import PineconeComponent
|
||||
from langflow.field_typing import Embeddings, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class PineconeSearchComponent(PineconeComponent, LCVectorStoreComponent):
|
||||
display_name = "Pinecone Search"
|
||||
description = "Search a Pinecone Vector Store for similar documents."
|
||||
icon = "Pinecone"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"index_name": {"display_name": "Index Name"},
|
||||
"namespace": {"display_name": "Namespace"},
|
||||
"pinecone_api_key": {
|
||||
"display_name": "Pinecone API Key",
|
||||
"default": "",
|
||||
"password": True,
|
||||
"required": True,
|
||||
},
|
||||
"pinecone_env": {
|
||||
"display_name": "Pinecone Environment",
|
||||
"default": "",
|
||||
"required": True,
|
||||
},
|
||||
"search_kwargs": {"display_name": "Search Kwargs", "default": "{}"},
|
||||
"pool_threads": {
|
||||
"display_name": "Pool Threads",
|
||||
"default": 1,
|
||||
"advanced": True,
|
||||
},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
embedding: Embeddings,
|
||||
pinecone_env: str,
|
||||
text_key: str = "text",
|
||||
pool_threads: int = 4,
|
||||
index_name: Optional[str] = None,
|
||||
pinecone_api_key: Optional[str] = None,
|
||||
namespace: Optional[str] = "default",
|
||||
search_type: str = "similarity",
|
||||
) -> List[Record]: # type: ignore[override]
|
||||
vector_store = super().build(
|
||||
embedding=embedding,
|
||||
pinecone_env=pinecone_env,
|
||||
inputs=[],
|
||||
text_key=text_key,
|
||||
pool_threads=pool_threads,
|
||||
index_name=index_name,
|
||||
pinecone_api_key=pinecone_api_key,
|
||||
namespace=namespace,
|
||||
)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to load the Pinecone index.")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type=search_type
|
||||
)
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.Qdrant import QdrantComponent
|
||||
from langflow.field_typing import Embeddings, NestedDict, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class QdrantSearchComponent(QdrantComponent, LCVectorStoreComponent):
|
||||
display_name = "Qdrant Search"
|
||||
description = "Construct Qdrant wrapper from a list of texts."
|
||||
icon = "Qdrant"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"api_key": {"display_name": "API Key", "password": True, "advanced": True},
|
||||
"collection_name": {"display_name": "Collection Name"},
|
||||
"content_payload_key": {
|
||||
"display_name": "Content Payload Key",
|
||||
"advanced": True,
|
||||
},
|
||||
"distance_func": {"display_name": "Distance Function", "advanced": True},
|
||||
"grpc_port": {"display_name": "gRPC Port", "advanced": True},
|
||||
"host": {"display_name": "Host", "advanced": True},
|
||||
"https": {"display_name": "HTTPS", "advanced": True},
|
||||
"location": {"display_name": "Location", "advanced": True},
|
||||
"metadata_payload_key": {
|
||||
"display_name": "Metadata Payload Key",
|
||||
"advanced": True,
|
||||
},
|
||||
"path": {"display_name": "Path", "advanced": True},
|
||||
"port": {"display_name": "Port", "advanced": True},
|
||||
"prefer_grpc": {"display_name": "Prefer gRPC", "advanced": True},
|
||||
"prefix": {"display_name": "Prefix", "advanced": True},
|
||||
"search_kwargs": {"display_name": "Search Kwargs", "advanced": True},
|
||||
"timeout": {"display_name": "Timeout", "advanced": True},
|
||||
"url": {"display_name": "URL", "advanced": True},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
embedding: Embeddings,
|
||||
collection_name: str,
|
||||
search_type: str = "similarity",
|
||||
api_key: Optional[str] = None,
|
||||
content_payload_key: str = "page_content",
|
||||
distance_func: str = "Cosine",
|
||||
grpc_port: int = 6334,
|
||||
https: bool = False,
|
||||
host: Optional[str] = None,
|
||||
location: Optional[str] = None,
|
||||
metadata_payload_key: str = "metadata",
|
||||
path: Optional[str] = None,
|
||||
port: Optional[int] = 6333,
|
||||
prefer_grpc: bool = False,
|
||||
prefix: Optional[str] = None,
|
||||
search_kwargs: Optional[NestedDict] = None,
|
||||
timeout: Optional[int] = None,
|
||||
url: Optional[str] = None,
|
||||
) -> List[Record]: # type: ignore[override]
|
||||
vector_store = super().build(
|
||||
embedding=embedding,
|
||||
collection_name=collection_name,
|
||||
api_key=api_key,
|
||||
content_payload_key=content_payload_key,
|
||||
distance_func=distance_func,
|
||||
grpc_port=grpc_port,
|
||||
https=https,
|
||||
host=host,
|
||||
location=location,
|
||||
metadata_payload_key=metadata_payload_key,
|
||||
path=path,
|
||||
port=port,
|
||||
prefer_grpc=prefer_grpc,
|
||||
prefix=prefix,
|
||||
search_kwargs=search_kwargs,
|
||||
timeout=timeout,
|
||||
url=url,
|
||||
)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to load the Qdrant index.")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type=search_type
|
||||
)
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langchain.embeddings.base import Embeddings
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.Redis import RedisComponent
|
||||
from langflow.field_typing import Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class RedisSearchComponent(RedisComponent, LCVectorStoreComponent):
|
||||
"""
|
||||
A custom component for implementing a Vector Store using Redis.
|
||||
"""
|
||||
|
||||
display_name: str = "Redis Search"
|
||||
description: str = "Search a Redis Vector Store for similar documents."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/redis"
|
||||
|
||||
def build_config(self):
|
||||
"""
|
||||
Builds the configuration for the component.
|
||||
|
||||
Returns:
|
||||
- dict: A dictionary containing the configuration options for the component.
|
||||
"""
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"index_name": {"display_name": "Index Name", "value": "your_index"},
|
||||
"code": {"show": False, "display_name": "Code"},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"schema": {"display_name": "Schema", "file_types": [".yaml"]},
|
||||
"redis_server_url": {
|
||||
"display_name": "Redis Server Connection String",
|
||||
"advanced": False,
|
||||
},
|
||||
"redis_index_name": {"display_name": "Redis Index", "advanced": False},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
embedding: Embeddings,
|
||||
redis_server_url: str,
|
||||
redis_index_name: str,
|
||||
schema: Optional[str] = None,
|
||||
) -> List[Record]:
|
||||
"""
|
||||
Builds the Vector Store or BaseRetriever object.
|
||||
|
||||
Args:
|
||||
- embedding (Embeddings): The embeddings to use for the Vector Store.
|
||||
- documents (Optional[Document]): The documents to use for the Vector Store.
|
||||
- redis_index_name (str): The name of the Redis index.
|
||||
- redis_server_url (str): The URL for the Redis server.
|
||||
|
||||
Returns:
|
||||
- VectorStore: The Vector Store object.
|
||||
"""
|
||||
vector_store = super().build(
|
||||
embedding=embedding,
|
||||
redis_server_url=redis_server_url,
|
||||
redis_index_name=redis_index_name,
|
||||
schema=schema,
|
||||
)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to load the Redis index.")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
input_value=input_value, search_type=search_type, vector_store=vector_store
|
||||
)
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
from typing import List
|
||||
|
||||
from langchain_community.vectorstores.supabase import SupabaseVectorStore
|
||||
from supabase.client import Client, create_client
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.field_typing import Embeddings, Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class SupabaseSearchComponent(LCVectorStoreComponent):
|
||||
display_name = "Supabase Search"
|
||||
description = "Search a Supabase Vector Store for similar documents."
|
||||
icon = "Supabase"
|
||||
|
||||
def build_config(self):
|
||||
return {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"query_name": {"display_name": "Query Name"},
|
||||
"search_kwargs": {"display_name": "Search Kwargs", "advanced": True},
|
||||
"supabase_service_key": {"display_name": "Supabase Service Key"},
|
||||
"supabase_url": {"display_name": "Supabase URL"},
|
||||
"table_name": {"display_name": "Table Name", "advanced": True},
|
||||
}
|
||||
|
||||
def build(
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
embedding: Embeddings,
|
||||
query_name: str = "",
|
||||
supabase_service_key: str = "",
|
||||
supabase_url: str = "",
|
||||
table_name: str = "",
|
||||
) -> List[Record]:
|
||||
supabase: Client = create_client(supabase_url, supabase_key=supabase_service_key)
|
||||
vector_store = SupabaseVectorStore(
|
||||
client=supabase,
|
||||
embedding=embedding,
|
||||
table_name=table_name,
|
||||
query_name=query_name,
|
||||
)
|
||||
return self.search_with_vector_store(input_value, search_type, vector_store)
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
from typing import List
|
||||
|
||||
from langchain_community.vectorstores.vectara import Vectara
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.Vectara import VectaraComponent
|
||||
from langflow.field_typing import Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class VectaraSearchComponent(VectaraComponent, LCVectorStoreComponent):
|
||||
display_name: str = "Vectara Search"
|
||||
description: str = "Search a Vectara Vector Store for similar documents."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/vectara"
|
||||
icon = "Vectara"
|
||||
|
||||
field_config = {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"vectara_customer_id": {
|
||||
"display_name": "Vectara Customer ID",
|
||||
},
|
||||
"vectara_corpus_id": {
|
||||
"display_name": "Vectara Corpus ID",
|
||||
},
|
||||
"vectara_api_key": {
|
||||
"display_name": "Vectara API Key",
|
||||
"password": True,
|
||||
},
|
||||
"files_url": {
|
||||
"display_name": "Files Url",
|
||||
"info": "Make vectara object using url of files (optional)",
|
||||
},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
vectara_customer_id: str,
|
||||
vectara_corpus_id: str,
|
||||
vectara_api_key: str,
|
||||
) -> List[Record]:
|
||||
source = "Langflow"
|
||||
vector_store = Vectara(
|
||||
vectara_customer_id=vectara_customer_id,
|
||||
vectara_corpus_id=vectara_corpus_id,
|
||||
vectara_api_key=vectara_api_key,
|
||||
source=source,
|
||||
)
|
||||
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to create Vectara Vector Store")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type=search_type
|
||||
)
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
from typing import List, Optional
|
||||
|
||||
from langchain.embeddings.base import Embeddings
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.Weaviate import WeaviateVectorStoreComponent
|
||||
from langflow.field_typing import Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class WeaviateSearchVectorStore(WeaviateVectorStoreComponent, LCVectorStoreComponent):
|
||||
display_name: str = "Weaviate Search"
|
||||
description: str = "Search a Weaviate Vector Store for similar documents."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/weaviate"
|
||||
icon = "Weaviate"
|
||||
|
||||
field_config = {
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"input_value": {"display_name": "Input"},
|
||||
"url": {"display_name": "Weaviate URL", "value": "http://localhost:8080"},
|
||||
"api_key": {
|
||||
"display_name": "API Key",
|
||||
"password": True,
|
||||
"required": False,
|
||||
},
|
||||
"index_name": {
|
||||
"display_name": "Index name",
|
||||
"required": False,
|
||||
},
|
||||
"text_key": {
|
||||
"display_name": "Text Key",
|
||||
"required": False,
|
||||
"advanced": True,
|
||||
"value": "text",
|
||||
},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"attributes": {
|
||||
"display_name": "Attributes",
|
||||
"required": False,
|
||||
"is_list": True,
|
||||
"field_type": "str",
|
||||
"advanced": True,
|
||||
},
|
||||
"search_by_text": {
|
||||
"display_name": "Search By Text",
|
||||
"field_type": "bool",
|
||||
"advanced": True,
|
||||
},
|
||||
"code": {"show": False},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
search_type: str,
|
||||
url: str,
|
||||
search_by_text: bool = False,
|
||||
api_key: Optional[str] = None,
|
||||
index_name: Optional[str] = None,
|
||||
text_key: str = "text",
|
||||
embedding: Optional[Embeddings] = None,
|
||||
attributes: Optional[list] = None,
|
||||
) -> List[Record]:
|
||||
vector_store = super().build(
|
||||
url=url,
|
||||
api_key=api_key,
|
||||
index_name=index_name,
|
||||
text_key=text_key,
|
||||
embedding=embedding,
|
||||
attributes=attributes,
|
||||
search_by_text=search_by_text,
|
||||
)
|
||||
if not vector_store:
|
||||
raise ValueError("Failed to load the Weaviate index.")
|
||||
|
||||
return self.search_with_vector_store(
|
||||
vector_store=vector_store, input_value=input_value, search_type=search_type
|
||||
)
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
from .AstraDBSearch import AstraDBSearchComponent
|
||||
from .ChromaSearch import ChromaSearchComponent
|
||||
from .FAISSSearch import FAISSSearchComponent
|
||||
from .MongoDBAtlasVectorSearch import MongoDBAtlasSearchComponent
|
||||
from .PineconeSearch import PineconeSearchComponent
|
||||
from .QdrantSearch import QdrantSearchComponent
|
||||
from .RedisSearch import RedisSearchComponent
|
||||
from .SupabaseVectorStoreSearch import SupabaseSearchComponent
|
||||
from .VectaraSearch import VectaraSearchComponent
|
||||
from .WeaviateSearch import WeaviateSearchVectorStore
|
||||
from .pgvectorSearch import PGVectorSearchComponent
|
||||
|
||||
__all__ = [
|
||||
"AstraDBSearchComponent",
|
||||
"ChromaSearchComponent",
|
||||
"FAISSSearchComponent",
|
||||
"MongoDBAtlasSearchComponent",
|
||||
"PineconeSearchComponent",
|
||||
"QdrantSearchComponent",
|
||||
"RedisSearchComponent",
|
||||
"SupabaseSearchComponent",
|
||||
"VectaraSearchComponent",
|
||||
"WeaviateSearchVectorStore",
|
||||
"PGVectorSearchComponent",
|
||||
]
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
from typing import List
|
||||
|
||||
from langchain.embeddings.base import Embeddings
|
||||
|
||||
from langflow.components.vectorstores.base.model import LCVectorStoreComponent
|
||||
from langflow.components.vectorstores.pgvector import PGVectorComponent
|
||||
from langflow.field_typing import Text
|
||||
from langflow.schema import Record
|
||||
|
||||
|
||||
class PGVectorSearchComponent(PGVectorComponent, LCVectorStoreComponent):
|
||||
"""
|
||||
A custom component for implementing a Vector Store using PostgreSQL.
|
||||
"""
|
||||
|
||||
display_name: str = "PGVector Search"
|
||||
description: str = "Search a PGVector Store for similar documents."
|
||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/pgvector"
|
||||
|
||||
def build_config(self):
|
||||
"""
|
||||
Builds the configuration for the component.
|
||||
|
||||
Returns:
|
||||
- dict: A dictionary containing the configuration options for the component.
|
||||
"""
|
||||
return {
|
||||
"code": {"show": False},
|
||||
"embedding": {"display_name": "Embedding"},
|
||||
"search_type": {
|
||||
"display_name": "Search Type",
|
||||
"options": ["Similarity", "MMR"],
|
||||
},
|
||||
"pg_server_url": {
|
||||
"display_name": "PostgreSQL Server Connection String",
|
||||
"advanced": False,
|
||||
},
|
||||
"collection_name": {"display_name": "Table", "advanced": False},
|
||||
"input_value": {"display_name": "Input"},
|
||||
}
|
||||
|
||||
def build( # type: ignore[override]
|
||||
self,
|
||||
input_value: Text,
|
||||
embedding: Embeddings,
|
||||
search_type: str,
|
||||
pg_server_url: str,
|
||||
collection_name: str,
|
||||
) -> List[Record]:
|
||||
"""
|
||||
Builds the Vector Store or BaseRetriever object.
|
||||
|
||||
Args:
|
||||
- input_value (str): The input value to search for.
|
||||
- embedding (Embeddings): The embeddings to use for the Vector Store.
|
||||
- collection_name (str): The name of the PG table.
|
||||
- pg_server_url (str): The URL for the PG server.
|
||||
|
||||
Returns:
|
||||
- VectorStore: The Vector Store object.
|
||||
"""
|
||||
try:
|
||||
vector_store = super().build(
|
||||
embedding=embedding,
|
||||
pg_server_url=pg_server_url,
|
||||
collection_name=collection_name,
|
||||
)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to build PGVector: {e}")
|
||||
return self.search_with_vector_store(
|
||||
input_value=input_value, search_type=search_type, vector_store=vector_store
|
||||
)
|
||||
|
|
@ -1,44 +1,26 @@
|
|||
from .AstraDB import AstraDBVectorStoreComponent
|
||||
from .Chroma import ChromaComponent
|
||||
from .ChromaSearch import ChromaSearchComponent
|
||||
from .FAISS import FAISSComponent
|
||||
from .FAISSSearch import FAISSSearchComponent
|
||||
from .MongoDBAtlasVector import MongoDBAtlasComponent
|
||||
from .MongoDBAtlasVectorSearch import MongoDBAtlasSearchComponent
|
||||
from .Pinecone import PineconeComponent
|
||||
from .PineconeSearch import PineconeSearchComponent
|
||||
from .Qdrant import QdrantComponent
|
||||
from .QdrantSearch import QdrantSearchComponent
|
||||
from .Redis import RedisComponent
|
||||
from .RedisSearch import RedisSearchComponent
|
||||
from .SupabaseVectorStore import SupabaseComponent
|
||||
from .SupabaseVectorStoreSearch import SupabaseSearchComponent
|
||||
from .Vectara import VectaraComponent
|
||||
from .VectaraSearch import VectaraSearchComponent
|
||||
from .Weaviate import WeaviateVectorStoreComponent
|
||||
from .WeaviateSearch import WeaviateSearchVectorStore
|
||||
from .pgvector import PGVectorComponent
|
||||
from .pgvectorSearch import PGVectorSearchComponent
|
||||
|
||||
__all__ = [
|
||||
"AstraDBVectorStoreComponent",
|
||||
"ChromaComponent",
|
||||
"ChromaSearchComponent",
|
||||
"FAISSComponent",
|
||||
"FAISSSearchComponent",
|
||||
"MongoDBAtlasComponent",
|
||||
"MongoDBAtlasSearchComponent",
|
||||
"PineconeComponent",
|
||||
"PineconeSearchComponent",
|
||||
"QdrantComponent",
|
||||
"QdrantSearchComponent",
|
||||
"RedisComponent",
|
||||
"RedisSearchComponent",
|
||||
"SupabaseComponent",
|
||||
"SupabaseSearchComponent",
|
||||
"VectaraComponent",
|
||||
"VectaraSearchComponent",
|
||||
"WeaviateVectorStoreComponent",
|
||||
"WeaviateSearchVectorStore",
|
||||
"base",
|
||||
"PGVectorComponent",
|
||||
"PGVectorSearchComponent",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -128,4 +128,4 @@
|
|||
"ua-parser-js": "^1.0.37",
|
||||
"vite": "^4.5.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -732,12 +732,12 @@ export const PRIORITY_SIDEBAR_ORDER = [
|
|||
"saved_components",
|
||||
"inputs",
|
||||
"outputs",
|
||||
"prompts",
|
||||
"data",
|
||||
"prompt",
|
||||
"models",
|
||||
"vectorstores",
|
||||
"vectorsearch",
|
||||
"helpers",
|
||||
"experimental",
|
||||
];
|
||||
export const NATIVE_CATEGORIES = [
|
||||
"inputs",
|
||||
|
|
|
|||
|
|
@ -236,6 +236,7 @@ export const nodeColors: { [char: string]: string } = {
|
|||
embeddings: "#42BAA7",
|
||||
documentloaders: "#7AAE42",
|
||||
vectorstores: "#AA8742",
|
||||
vectorsearch: "#AA8742",
|
||||
textsplitters: "#B47CB5",
|
||||
toolkits: "#DB2C2C",
|
||||
wrappers: "#E6277A",
|
||||
|
|
@ -267,6 +268,7 @@ export const nodeNames: { [char: string]: string } = {
|
|||
embeddings: "Embeddings",
|
||||
documentloaders: "Loaders",
|
||||
vectorstores: "Vector Stores",
|
||||
vectorsearch: "Vector Search",
|
||||
toolkits: "Toolkits",
|
||||
wrappers: "Wrappers",
|
||||
textsplitters: "Text Splitters",
|
||||
|
|
@ -369,6 +371,7 @@ export const nodeIconsLucide: iconsType = {
|
|||
saved_components: GradientSave,
|
||||
documentloaders: Paperclip,
|
||||
vectorstores: Layers,
|
||||
vectorsearch: Search,
|
||||
toolkits: Package2,
|
||||
textsplitters: Scissors,
|
||||
wrappers: Gift,
|
||||
|
|
|
|||
Loading…
Reference in a new issue