From b0619f59ffcd5c1c0b125ed080f97fa1cdda5c34 Mon Sep 17 00:00:00 2001 From: David Oplatka Date: Fri, 16 Aug 2024 13:06:16 -0700 Subject: [PATCH] fix: adds credentials fields in Vectara RAG component (#3396) * Fix Component * Final Edits * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../components/vectorstores/vectara_rag.py | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/backend/base/langflow/components/vectorstores/vectara_rag.py b/src/backend/base/langflow/components/vectorstores/vectara_rag.py index ab335afbe..c620eb669 100644 --- a/src/backend/base/langflow/components/vectorstores/vectara_rag.py +++ b/src/backend/base/langflow/components/vectorstores/vectara_rag.py @@ -1,6 +1,6 @@ from langflow.custom import Component from langflow.field_typing.range_spec import RangeSpec -from langflow.io import DropdownInput, FloatInput, IntInput, MessageTextInput, Output +from langflow.io import DropdownInput, FloatInput, IntInput, MessageTextInput, StrInput, SecretStrInput, Output from langflow.schema.message import Message @@ -20,35 +20,58 @@ class VectaraRagComponent(Component): RERANKER_TYPES = ["mmr", "rerank_multilingual_v1", "none"] + RESPONSE_LANGUAGES = [ + "auto", + "eng", + "spa", + "fra", + "zho", + "deu", + "hin", + "ara", + "por", + "ita", + "jpn", + "kor", + "rus", + "tur", + "fas", + "vie", + "tha", + "heb", + "nld", + "ind", + "pol", + "ukr", + "ron", + "swe", + "ces", + "ell", + "ben", + "msa", + "urd", + ] + field_order = ["vectara_customer_id", "vectara_corpus_id", "vectara_api_key", "search_query", "reranker"] - # return { - # "vectara_customer_id": {"display_name": "Vectara Customer ID", "field_type": "str", "required": True}, - # "vectara_corpus_id": {"display_name": "Vectara Corpus ID", "field_type": "str", "required": True}, - # "vectara_api_key": {"display_name": "Vectara API Key", "field_type": "str", "required": True}, - # "search_query": {"display_name": "Search Query", "field_type": "str", "info": "The query to receive an answer on.", "required": True}, - # "lexical_interpolation": {"display_name": "Hybrid Search Factor", "field_type": "float", "value": 0.005, "info": "How much to weigh lexical scores compared to the embedding score. 0 means lexical search is not used at all, and 1 means only lexical search is used.", "advanced": True}, - # "filter": {"display_name": "Metadata Filters", "field_type": "str", "value": '', "info": "The filter string to narrow the search to according to metadata attributes.", "advanced": True}, - # "reranker": {"display_name": "Reranker Type", "options": RERANKER_TYPES, "value": RERANKER_TYPES[0], "info": "How to rerank the retrieved search results."}, - # "reranker_k": {"display_name": "Number of Results to Rerank", "field_type": "int", "value": 50, "advanced": True}, - # "diversity_bias": {"display_name": "Diversity Bias", "field_type": "float", "value": 0.2, "info": "Ranges from 0 to 1, with higher values indicating greater diversity (only applies to MMR reranker).", "advanced": True}, - # "max_results": {"display_name": "Max Results to Summarize", "field_type": "int", "value": 7, "info": "The maximum number of search results to be available to the prompt.", "advanced": True}, - # "response_lang": {"display_name": "Response Language", "field_type": "str", "value": "eng", "info": "Use the ISO 639-1 or 639-3 language code or auto to automatically detect the language.", "advanced": True}, - # "prompt": {"display_name": "Prompt Name", "options": SUMMARIZER_PROMPTS, "value": SUMMARIZER_PROMPTS[0], "info": "Only vectara-summary-ext-24-05-sml is for Growth customers; all other prompts are for Scale customers only.", "advanced": True} - # } inputs = [ + StrInput(name="vectara_customer_id", display_name="Vectara Customer ID", required=True), + StrInput(name="vectara_corpus_id", display_name="Vectara Corpus ID", required=True), + SecretStrInput(name="vectara_api_key", display_name="Vectara API Key", required=True), MessageTextInput(name="search_query", display_name="Search Query", info="The query to receive an answer on."), FloatInput( name="lexical_interpolation", display_name="Hybrid Search Factor", range_spec=RangeSpec(min=0.005, max=0.1, step=0.005), value=0.005, + advanced=True, info="How much to weigh lexical scores compared to the embedding score. 0 means lexical search is not used at all, and 1 means only lexical search is used.", ), MessageTextInput( name="filter", display_name="Metadata Filters", value="", + advanced=True, info="The filter string to narrow the search to according to metadata attributes.", ), DropdownInput( @@ -63,12 +86,14 @@ class VectaraRagComponent(Component): display_name="Number of Results to Rerank", value=50, range_spec=RangeSpec(min=1, max=100, step=1), + advanced=True, ), FloatInput( name="diversity_bias", display_name="Diversity Bias", value=0.2, range_spec=RangeSpec(min=0, max=1, step=0.01), + advanced=True, info="Ranges from 0 to 1, with higher values indicating greater diversity (only applies to MMR reranker).", ), IntInput( @@ -76,12 +101,15 @@ class VectaraRagComponent(Component): display_name="Max Results to Summarize", value=7, range_spec=RangeSpec(min=1, max=100, step=1), + advanced=True, + info="The maximum number of search results to be available to the prompt.", ), DropdownInput( name="response_lang", display_name="Response Language", - options=["auto", "eng", "deu", "fra", "ita", "nld", "por", "rus", "spa", "zho"], + options=RESPONSE_LANGUAGES, value="eng", + advanced=True, info="Use the ISO 639-1 or 639-3 language code or auto to automatically detect the language.", ), DropdownInput( @@ -89,6 +117,7 @@ class VectaraRagComponent(Component): display_name="Prompt Name", options=SUMMARIZER_PROMPTS, value=SUMMARIZER_PROMPTS[0], + advanced=True, info="Only vectara-summary-ext-24-05-sml is for Growth customers; all other prompts are for Scale customers only.", ), ]