diff --git a/llama_hub/llama_packs/corrective_rag/base.py b/llama_hub/llama_packs/corrective_rag/base.py index 1c7c35859..25c12379a 100644 --- a/llama_hub/llama_packs/corrective_rag/base.py +++ b/llama_hub/llama_packs/corrective_rag/base.py @@ -8,6 +8,40 @@ from llama_index.schema import Document, NodeWithScore from llama_index.query_pipeline.query import QueryPipeline from llama_hub.tools.tavily_research.base import TavilyToolSpec +from llama_index.prompts import PromptTemplate + +DEFAULT_RELEVANCY_PROMPT_TEMPLATE = PromptTemplate( + template="""As a grader, your task is to evaluate the relevance of a document retrieved in response to a user's question. + + Retrieved Document: + ------------------- + {context_str} + + User Question: + -------------- + {query_str} + + Evaluation Criteria: + - Consider whether the document contains keywords or topics related to the user's question. + - The evaluation should not be overly stringent; the primary objective is to identify and filter out clearly irrelevant retrievals. + + Decision: + - Assign a binary score to indicate the document's relevance. + - Use 'yes' if the document is relevant to the question, or 'no' if it is not. + + Please provide your binary score ('yes' or 'no') below to indicate the document's relevance to the user question.""" +) + +DEFAULT_TRANSFORM_QUERY_TEMPLATE = PromptTemplate( + template="""Your task is to refine a query to ensure it is highly effective for retrieving relevant search results. \n + Analyze the given input to grasp the core semantic intent or meaning. \n + Original Query: + \n ------- \n + {query_str} + \n ------- \n + Your goal is to rephrase or enhance this query to improve its search performance. Ensure the revised query is concise and directly aligned with the intended search objective. \n + Respond with the optimized query only:""" +) class CorrectiveRAGPack(BaseLlamaPack): diff --git a/llama_hub/llama_packs/corrective_rag/prompts.py b/llama_hub/llama_packs/corrective_rag/prompts.py deleted file mode 100644 index ac415daa5..000000000 --- a/llama_hub/llama_packs/corrective_rag/prompts.py +++ /dev/null @@ -1,34 +0,0 @@ -from llama_index.prompts import PromptTemplate - -DEFAULT_RELEVANCY_PROMPT_TEMPLATE = PromptTemplate( - template="""As a grader, your task is to evaluate the relevance of a document retrieved in response to a user's question. - - Retrieved Document: - ------------------- - {context_str} - - User Question: - -------------- - {query_str} - - Evaluation Criteria: - - Consider whether the document contains keywords or topics related to the user's question. - - The evaluation should not be overly stringent; the primary objective is to identify and filter out clearly irrelevant retrievals. - - Decision: - - Assign a binary score to indicate the document's relevance. - - Use 'yes' if the document is relevant to the question, or 'no' if it is not. - - Please provide your binary score ('yes' or 'no') below to indicate the document's relevance to the user question.""" -) - -DEFAULT_TRANSFORM_QUERY_TEMPLATE = PromptTemplate( - template="""Your task is to refine a query to ensure it is highly effective for retrieving relevant search results. \n - Analyze the given input to grasp the core semantic intent or meaning. \n - Original Query: - \n ------- \n - {query_str} - \n ------- \n - Your goal is to rephrase or enhance this query to improve its search performance. Ensure the revised query is concise and directly aligned with the intended search objective. \n - Respond with the optimized query only:""" -)