🔨 refactor(Vectara.py): reorganize function parameters for better readability and maintainability

🔧 chore(Vectara.py): add "embedding" parameter to the build function to support custom embeddings in VectaraComponent
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-09 15:47:22 -03:00
commit 9bbdd9465b

View file

@ -5,6 +5,7 @@ from langchain.vectorstores import Vectara
from langchain.schema import Document
from langchain.vectorstores.base import VectorStore
from langchain.schema import BaseRetriever
from langchain.embeddings.base import Embeddings
class VectaraComponent(CustomComponent):
@ -21,14 +22,16 @@ class VectaraComponent(CustomComponent):
"vectara_api_key": {"display_name": "Vectara API Key", "password": True},
"code": {"show": False},
"documents": {"display_name": "Documents"},
"embedding": {"display_name": "Embedding"},
}
def build(
self,
documents: Optional[Document],
vectara_customer_id: str,
vectara_corpus_id: str,
vectara_api_key: str,
embedding: Optional[Embeddings] = None,
documents: Optional[Document] = None,
) -> Union[VectorStore, BaseRetriever]:
# If documents, then we need to create a Vectara instance using .from_documents
if documents:
@ -37,6 +40,7 @@ class VectaraComponent(CustomComponent):
vectara_customer_id=vectara_customer_id,
vectara_corpus_id=vectara_corpus_id,
vectara_api_key=vectara_api_key,
embedding=embedding,
)
return Vectara(