From edfc8496525d182f716559e99e35f2c162d4038c Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Sun, 17 Dec 2023 22:45:46 -0800 Subject: [PATCH] Search more frequently (#834) --- backend/danswer/chat/prompts.yaml | 5 +-- backend/danswer/prompts/chat_prompts.py | 43 ++++++++++--------- .../secondary_llm_flows/choose_search.py | 6 +-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/backend/danswer/chat/prompts.yaml b/backend/danswer/chat/prompts.yaml index d348e2d6c..4ab9d7918 100644 --- a/backend/danswer/chat/prompts.yaml +++ b/backend/danswer/chat/prompts.yaml @@ -10,10 +10,9 @@ prompts: You are a question answering system that is constantly learning and improving. You can process and comprehend vast amounts of text and utilize this knowledge to provide - grounded and accurate answers to diverse queries. + grounded, accurate, and concise answers to diverse queries. - You clearly communicate ANY UNCERTAINTY in your answer. - If you don't know the answer, just say that you don't know, don't try to make up an answer. + You always clearly communicate ANY UNCERTAINTY in your answer. # Task Prompt (as shown in UI) task: > Answer my query based on the documents provided. diff --git a/backend/danswer/prompts/chat_prompts.py b/backend/danswer/prompts/chat_prompts.py index 6682ef19d..bdb938090 100644 --- a/backend/danswer/prompts/chat_prompts.py +++ b/backend/danswer/prompts/chat_prompts.py @@ -48,6 +48,27 @@ CHAT_USER_CONTEXT_FREE_PROMPT = f""" # consider doing COT for this and keep it brief, but likely only small gains. SKIP_SEARCH = "Skip Search" YES_SEARCH = "Yes Search" +AGGRESSIVE_SEARCH_TEMPLATE = f""" +Given the conversation history and a follow up query, determine if the system should call \ +an external search tool to better answer the latest user input. + +Respond "{SKIP_SEARCH}" if either: +- There is sufficient information in chat history to FULLY and ACCURATELY answer the query AND \ +additional information or details would provide little or no value. +- The query is some form of request that does not require additional information to handle. + +Conversation History: +{GENERAL_SEP_PAT} +{{chat_history}} +{GENERAL_SEP_PAT} + +If you are unsure, respond with {YES_SEARCH}. +Respond with EXACTLY and ONLY "{YES_SEARCH}" or "{SKIP_SEARCH}" + +Follow Up Input: +{{final_query}} +""".strip() + REQUIRE_SEARCH_SINGLE_MSG = f""" Given the conversation history and a follow up query, determine if the system should call \ an external search tool to better answer the latest user input. @@ -97,27 +118,7 @@ Standalone question (Respond with only the short combined query): """.strip() -# NOTE: THE PROMPTS BELOW ARE RETIRED -AGGRESSIVE_SEARCH_TEMPLATE = f""" -Given the conversation history and a follow up query, determine if the system should call \ -an external search tool to better answer the latest user input. - -Respond "{SKIP_SEARCH}" if: -- There is sufficient information in chat history to FULLY and ACCURATELY answer the query. -- Additional information or details would provide little or no value. -- The query is some form of request that does not require additional information to handle. - -{GENERAL_SEP_PAT} -Conversation History: -{{chat_history}} -{GENERAL_SEP_PAT} - -Respond with EXACTLY and ONLY "{YES_SEARCH}" or "{SKIP_SEARCH}" - -Follow Up Input: -{{final_query}} -""" - +# The below prompts are retired NO_SEARCH = "No Search" REQUIRE_SEARCH_SYSTEM_MSG = f""" You are a large language model whose only job is to determine if the system should call an \ diff --git a/backend/danswer/secondary_llm_flows/choose_search.py b/backend/danswer/secondary_llm_flows/choose_search.py index aa91817e4..d0bbfeea5 100644 --- a/backend/danswer/secondary_llm_flows/choose_search.py +++ b/backend/danswer/secondary_llm_flows/choose_search.py @@ -9,9 +9,9 @@ from danswer.llm.factory import get_default_llm from danswer.llm.interfaces import LLM from danswer.llm.utils import dict_based_prompt_to_langchain_prompt from danswer.llm.utils import translate_danswer_msg_to_langchain +from danswer.prompts.chat_prompts import AGGRESSIVE_SEARCH_TEMPLATE from danswer.prompts.chat_prompts import NO_SEARCH from danswer.prompts.chat_prompts import REQUIRE_SEARCH_HINT -from danswer.prompts.chat_prompts import REQUIRE_SEARCH_SINGLE_MSG from danswer.prompts.chat_prompts import REQUIRE_SEARCH_SYSTEM_MSG from danswer.prompts.chat_prompts import SKIP_SEARCH from danswer.utils.logger import setup_logger @@ -57,9 +57,9 @@ def check_if_need_search( messages = [ { "role": "user", - "content": REQUIRE_SEARCH_SINGLE_MSG.format( + "content": AGGRESSIVE_SEARCH_TEMPLATE.format( final_query=question, chat_history=history_str - ), + ).strip(), }, ]