chore: Updating PGVector Vector Store parameters format
This commit is contained in:
parent
a97b5eee75
commit
be9539f420
1 changed files with 21 additions and 32 deletions
|
|
@ -11,24 +11,19 @@ from langflow.schema import Data
|
||||||
class PGVectorStoreComponent(LCVectorStoreComponent):
|
class PGVectorStoreComponent(LCVectorStoreComponent):
|
||||||
display_name = "PGVector"
|
display_name = "PGVector"
|
||||||
description = "PGVector Vector Store with search capabilities"
|
description = "PGVector Vector Store with search capabilities"
|
||||||
documentation = "https://python.langchain.com/docs/modules/data_connection/vectorstores/integrations/pgvector"
|
documentation = "https://python.langchain.com/v0.2/docs/integrations/vectorstores/pgvector/"
|
||||||
icon = "PGVector"
|
icon = "PGVector"
|
||||||
|
|
||||||
inputs = [
|
inputs = [
|
||||||
SecretStrInput(name="pg_server_url", display_name="PostgreSQL Server Connection String", required=True),
|
SecretStrInput(name="pg_server_url", display_name="PostgreSQL Server Connection String", required=True),
|
||||||
StrInput(name="collection_name", display_name="Table", required=True),
|
StrInput(name="collection_name", display_name="Table", required=True),
|
||||||
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
MultilineInput(name="search_query", display_name="Search Query"),
|
||||||
DataInput(
|
DataInput(
|
||||||
name="vector_store_inputs",
|
name="ingest_data",
|
||||||
display_name="Vector Store Inputs",
|
display_name="Ingestion Data",
|
||||||
is_list=True,
|
is_list=True,
|
||||||
),
|
),
|
||||||
BoolInput(
|
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||||
name="add_to_vector_store",
|
|
||||||
display_name="Add to Vector Store",
|
|
||||||
info="If true, the Vector Store Inputs will be added to the Vector Store.",
|
|
||||||
),
|
|
||||||
MultilineInput(name="search_input", display_name="Search Input"),
|
|
||||||
IntInput(
|
IntInput(
|
||||||
name="number_of_results",
|
name="number_of_results",
|
||||||
display_name="Number of Results",
|
display_name="Number of Results",
|
||||||
|
|
@ -36,33 +31,27 @@ class PGVectorStoreComponent(LCVectorStoreComponent):
|
||||||
value=4,
|
value=4,
|
||||||
advanced=True,
|
advanced=True,
|
||||||
),
|
),
|
||||||
|
HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
def build_vector_store(self) -> PGVector:
|
def build_vector_store(self) -> PGVector:
|
||||||
return self._build_pgvector()
|
return self._build_pgvector()
|
||||||
|
|
||||||
def _build_pgvector(self) -> PGVector:
|
def _build_pgvector(self) -> PGVector:
|
||||||
if self.add_to_vector_store:
|
documents = []
|
||||||
documents = []
|
for _input in self.ingest_data or []:
|
||||||
for _input in self.vector_store_inputs or []:
|
if isinstance(_input, Data):
|
||||||
if isinstance(_input, Data):
|
documents.append(_input.to_lc_document())
|
||||||
documents.append(_input.to_lc_document())
|
|
||||||
else:
|
|
||||||
documents.append(_input)
|
|
||||||
|
|
||||||
if documents:
|
|
||||||
pgvector = PGVector.from_documents(
|
|
||||||
embedding=self.embedding,
|
|
||||||
documents=documents,
|
|
||||||
collection_name=self.collection_name,
|
|
||||||
connection_string=self.pg_server_url,
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
pgvector = PGVector.from_existing_index(
|
documents.append(_input)
|
||||||
embedding=self.embedding,
|
|
||||||
collection_name=self.collection_name,
|
if documents:
|
||||||
connection_string=self.pg_server_url,
|
pgvector = PGVector.from_documents(
|
||||||
)
|
embedding=self.embedding,
|
||||||
|
documents=documents,
|
||||||
|
collection_name=self.collection_name,
|
||||||
|
connection_string=self.pg_server_url,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pgvector = PGVector.from_existing_index(
|
pgvector = PGVector.from_existing_index(
|
||||||
embedding=self.embedding,
|
embedding=self.embedding,
|
||||||
|
|
@ -75,9 +64,9 @@ class PGVectorStoreComponent(LCVectorStoreComponent):
|
||||||
def search_documents(self) -> List[Data]:
|
def search_documents(self) -> List[Data]:
|
||||||
vector_store = self._build_pgvector()
|
vector_store = self._build_pgvector()
|
||||||
|
|
||||||
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():
|
||||||
docs = vector_store.similarity_search(
|
docs = vector_store.similarity_search(
|
||||||
query=self.search_input,
|
query=self.search_query,
|
||||||
k=self.number_of_results,
|
k=self.number_of_results,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue