Fix vectorstores/PGVector missing output issue. (#1296)
In previous version, the output disappeared. I've fixed it and made it support the output component "Chains" as well. Before:  After: 
This commit is contained in:
commit
f670ba50ac
1 changed files with 10 additions and 9 deletions
|
|
@ -1,13 +1,15 @@
|
||||||
|
from typing import Optional, Union
|
||||||
|
from langflow import CustomComponent
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from langchain.embeddings.base import Embeddings
|
from langchain.embeddings.base import Embeddings
|
||||||
|
from langchain.schema import BaseRetriever
|
||||||
from langchain.schema import Document
|
from langchain.schema import Document
|
||||||
from langchain_community.vectorstores import VectorStore
|
from langchain_community.vectorstores import VectorStore
|
||||||
from langchain_community.vectorstores.pgvector import PGVector
|
from langchain_community.vectorstores.pgvector import PGVector
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
|
|
||||||
|
class PGVectorComponent(CustomComponent):
|
||||||
class PostgresqlVectorComponent(CustomComponent):
|
|
||||||
"""
|
"""
|
||||||
A custom component for implementing a Vector Store using PostgreSQL.
|
A custom component for implementing a Vector Store using PostgreSQL.
|
||||||
"""
|
"""
|
||||||
|
|
@ -15,7 +17,6 @@ class PostgresqlVectorComponent(CustomComponent):
|
||||||
display_name: str = "PGVector"
|
display_name: str = "PGVector"
|
||||||
description: str = "Implementation of Vector Store using PostgreSQL"
|
description: str = "Implementation of Vector Store using PostgreSQL"
|
||||||
documentation = "https://python.langchain.com/docs/integrations/vectorstores/pgvector"
|
documentation = "https://python.langchain.com/docs/integrations/vectorstores/pgvector"
|
||||||
beta = True
|
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -25,8 +26,7 @@ class PostgresqlVectorComponent(CustomComponent):
|
||||||
- dict: A dictionary containing the configuration options for the component.
|
- dict: A dictionary containing the configuration options for the component.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"index_name": {"display_name": "Index Name", "value": "your_index"},
|
"code": {"show": False},
|
||||||
"code": {"show": True, "display_name": "Code"},
|
|
||||||
"documents": {"display_name": "Documents", "is_list": True},
|
"documents": {"display_name": "Documents", "is_list": True},
|
||||||
"embedding": {"display_name": "Embedding"},
|
"embedding": {"display_name": "Embedding"},
|
||||||
"pg_server_url": {
|
"pg_server_url": {
|
||||||
|
|
@ -41,8 +41,8 @@ class PostgresqlVectorComponent(CustomComponent):
|
||||||
embedding: Embeddings,
|
embedding: Embeddings,
|
||||||
pg_server_url: str,
|
pg_server_url: str,
|
||||||
collection_name: str,
|
collection_name: str,
|
||||||
documents: Optional[List[Document]] = None,
|
documents: Optional[Document] = None,
|
||||||
) -> VectorStore:
|
) -> Union[VectorStore, BaseRetriever]:
|
||||||
"""
|
"""
|
||||||
Builds the Vector Store or BaseRetriever object.
|
Builds the Vector Store or BaseRetriever object.
|
||||||
|
|
||||||
|
|
@ -58,13 +58,13 @@ class PostgresqlVectorComponent(CustomComponent):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if documents is None:
|
if documents is None:
|
||||||
return PGVector.from_existing_index(
|
vector_store = PGVector.from_existing_index(
|
||||||
embedding=embedding,
|
embedding=embedding,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
connection_string=pg_server_url,
|
connection_string=pg_server_url,
|
||||||
)
|
)
|
||||||
|
|
||||||
return PGVector.from_documents(
|
vector_store = PGVector.from_documents(
|
||||||
embedding=embedding,
|
embedding=embedding,
|
||||||
documents=documents,
|
documents=documents,
|
||||||
collection_name=collection_name,
|
collection_name=collection_name,
|
||||||
|
|
@ -72,3 +72,4 @@ class PostgresqlVectorComponent(CustomComponent):
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(f"Failed to build PGVector: {e}")
|
raise RuntimeError(f"Failed to build PGVector: {e}")
|
||||||
|
return vector_store
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue