diff --git a/src/backend/langflow/components/vectorstores/Vectara.py b/src/backend/langflow/components/vectorstores/Vectara.py index 1f0d10179..e3555e6f1 100644 --- a/src/backend/langflow/components/vectorstores/Vectara.py +++ b/src/backend/langflow/components/vectorstores/Vectara.py @@ -1,10 +1,14 @@ -from typing import Optional, Union - -from langchain.schema import BaseRetriever, Document -from langchain.vectorstores import Vectara -from langchain.vectorstores.base import VectorStore - +from typing import Optional, Union, List from langflow import CustomComponent +import tempfile +import urllib.request +import urllib + +from langchain.vectorstores import Vectara +from langchain.schema import Document +from langchain.vectorstores.base import VectorStore +from langchain.schema import BaseRetriever +from langchain.embeddings import FakeEmbeddings class VectaraComponent(CustomComponent): @@ -12,13 +16,29 @@ class VectaraComponent(CustomComponent): description: str = "Implementation of Vector Store using Vectara" documentation = "https://python.langchain.com/docs/integrations/vectorstores/vectara" beta = True - # api key should be password = True field_config = { - "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}, + "vectara_customer_id": { + "display_name": "Vectara Customer ID", + "required": True, + }, + "vectara_corpus_id": { + "display_name": "Vectara Corpus ID", + "required": True, + }, + "vectara_api_key": { + "display_name": "Vectara API Key", + "password": True, + "required": True, + }, "code": {"show": False}, - "documents": {"display_name": "Documents"}, + "documents": { + "display_name": "Documents", + "info": "Pass in either for Self Query Retriever or for making a Vectara Object", + }, + "files_url": { + "display_name": "Files Url", + "info": "Make vectara object using url of files(documents not needed)", + }, } def build( @@ -26,21 +46,35 @@ class VectaraComponent(CustomComponent): vectara_customer_id: str, vectara_corpus_id: str, vectara_api_key: str, + files_url: Optional[List[str]] = None, documents: Optional[Document] = None, ) -> Union[VectorStore, BaseRetriever]: - # If documents, then we need to create a Vectara instance using .from_documents if documents is not None: return Vectara.from_documents( - documents=documents, # type: ignore + documents=documents, + embedding=FakeEmbeddings(size=768), + vectara_customer_id=vectara_customer_id, + vectara_corpus_id=vectara_corpus_id, + vectara_api_key=vectara_api_key, + ) + + if files_url is not None: + files_list = [] + for url in files_url: + name = tempfile.NamedTemporaryFile().name + urllib.request.urlretrieve(url, name) + files_list.append(name) + + return Vectara.from_files( + files=files_list, + embedding=FakeEmbeddings(size=768), vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, - source="langflow", ) return Vectara( vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, - source="langflow", ) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index 338224004..2e2a65b64 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -578,4 +578,4 @@ def test_async_task_processing_vector_store(client, added_vector_store, created_ # Validate that the task completed successfully and the result is as expected assert "result" in task_status_json, task_status_json assert "output" in task_status_json["result"], task_status_json["result"] - assert "Langflow" in task_status_json["result"]["output"], task_status_json["result"] + assert "Langflow" in task_status_json["result"]["output"], task_status_json["result"] \ No newline at end of file