Refactor LCVectorStoreComponent search method

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-28 22:42:17 -03:00
commit 7969849c1d

View file

@ -5,8 +5,8 @@ from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore from langchain_core.vectorstores import VectorStore
from langflow import CustomComponent from langflow import CustomComponent
from langflow.field_typing import Text, docs_to_records from langflow.field_typing import Text
from langflow.schema import Record from langflow.schema import Record, docs_to_records
class LCVectorStoreComponent(CustomComponent): class LCVectorStoreComponent(CustomComponent):
@ -36,8 +36,14 @@ class LCVectorStoreComponent(CustomComponent):
""" """
docs: List[Document] = [] docs: List[Document] = []
if input_value and isinstance(input_value, str) and hasattr(vector_store, "search"): if (
docs = vector_store.search(query=input_value, search_type=search_type.lower()) input_value
and isinstance(input_value, str)
and hasattr(vector_store, "search")
):
docs = vector_store.search(
query=input_value, search_type=search_type.lower()
)
else: else:
raise ValueError("Invalid inputs provided.") raise ValueError("Invalid inputs provided.")
return docs_to_records(docs) return docs_to_records(docs)