diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/edges.py similarity index 78% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/edges.py index d152c7a17..da3f58a38 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/edges.py @@ -3,10 +3,10 @@ from datetime import datetime from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) from onyx.utils.logger import setup_logger diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/graph_builder.py similarity index 75% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/graph_builder.py index e08aa2a4e..cc06e6d16 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/graph_builder.py @@ -2,31 +2,31 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.edges import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.edges import ( send_to_expanded_retrieval, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.answer_check import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.answer_check import ( answer_check, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.answer_generation import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.answer_generation import ( answer_generation, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.format_answer import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.format_answer import ( format_answer, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.ingest_retrieval import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.ingest_retrieval import ( ingest_retrieval, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionState, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.graph_builder import ( expanded_retrieval_graph_builder, ) from onyx.agents.agent_search.shared_graph_utils.utils import get_test_config diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/models.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/models.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/models.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/models.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_check.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_check.py similarity index 90% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_check.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_check.py index a58debba2..da679581e 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_check.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_check.py @@ -5,10 +5,10 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_message_runs from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionState, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( QACheckUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_generation.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_generation.py similarity index 93% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_generation.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_generation.py index 121f32628..150cdced5 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/answer_generation.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/answer_generation.py @@ -6,10 +6,10 @@ from langchain_core.callbacks.manager import dispatch_custom_event from langchain_core.messages import merge_message_runs from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionState, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( QAGenerationUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig @@ -102,7 +102,9 @@ def answer_generation( ) answer_citation_ids = get_answer_citation_ids(answer_str) - cited_docs = [context_docs[id] for id in answer_citation_ids] + cited_docs = [ + context_docs[id] for id in answer_citation_ids if id < len(context_docs) + ] stop_event = StreamStopInfo( stop_reason=StreamStopReason.FINISHED, diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/format_answer.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/format_answer.py similarity index 80% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/format_answer.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/format_answer.py index 469e67f52..f4d870dce 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/format_answer.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/format_answer.py @@ -1,7 +1,7 @@ -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionState, ) from onyx.agents.agent_search.shared_graph_utils.models import ( diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/ingest_retrieval.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/ingest_retrieval.py similarity index 80% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/ingest_retrieval.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/ingest_retrieval.py index 50682e95d..cc11d4997 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/nodes/ingest_retrieval.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/nodes/ingest_retrieval.py @@ -1,7 +1,7 @@ -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( RetrievalIngestionUpdate, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalOutput, ) from onyx.agents.agent_search.shared_graph_utils.models import AgentChunkStats diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/states.py b/backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/states.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/initial__individual_sub_answer__subgraph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/individual_sub_answer_generation/states.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/edges.py similarity index 85% rename from backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/edges.py index f92727b4f..788c24ce3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/edges.py @@ -3,13 +3,13 @@ from datetime import datetime from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) from onyx.agents.agent_search.shared_graph_utils.utils import make_question_id diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/graph_builder.py similarity index 79% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/graph_builder.py index 67cc07451..825d43cf9 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/graph_builder.py @@ -2,27 +2,27 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.graph_builder import ( - initial_sq_subgraph_builder, -) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.graph_builder import ( - base_raw_search_graph_builder, -) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.nodes.generate_initial_answer import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.nodes.generate_initial_answer import ( generate_initial_answer, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.nodes.initial_answer_quality_check import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.nodes.initial_answer_quality_check import ( initial_answer_quality_check, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.nodes.retrieval_consolidation import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.nodes.retrieval_consolidation import ( retrieval_consolidation, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQInput, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) +from onyx.agents.agent_search.deep_search_a.initial.retrieval.graph_builder import ( + base_raw_search_graph_builder, +) +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.graph_builder import ( + initial_sq_subgraph_builder, +) from onyx.utils.logger import setup_logger logger = setup_logger() diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/generate_initial_answer.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/generate_initial_answer.py similarity index 93% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/generate_initial_answer.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/generate_initial_answer.py index e427b208f..bce661ec8 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/generate_initial_answer.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/generate_initial_answer.py @@ -7,19 +7,19 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_content from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import AgentBaseMetrics -from onyx.agents.agent_search.deep_search_a.main__graph.operations import ( +from onyx.agents.agent_search.deep_search_a.main.models import AgentBaseMetrics +from onyx.agents.agent_search.deep_search_a.main.operations import ( calculate_initial_agent_stats, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import get_query_info -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.operations import ( +from onyx.agents.agent_search.deep_search_a.main.operations import get_query_info +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.operations import ( remove_document_citations, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig @@ -127,7 +127,7 @@ def generate_initial_answer( ) else: - decomp_answer_results = state.decomp_answer_results + decomp_answer_results = state.sub_question_results good_qa_list: list[str] = [] @@ -220,7 +220,7 @@ def generate_initial_answer( answer = cast(str, response) initial_agent_stats = calculate_initial_agent_stats( - state.decomp_answer_results, state.original_question_retrieval_stats + state.sub_question_results, state.original_question_retrieval_stats ) logger.debug( diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/ingest_initial_base_retrieval.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/ingest_initial_base_retrieval.py similarity index 84% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/ingest_initial_base_retrieval.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/ingest_initial_base_retrieval.py index 88357a3c9..0fb8e5d62 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/ingest_initial_base_retrieval.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/ingest_initial_base_retrieval.py @@ -1,10 +1,10 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchOutput, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( ExpandedRetrievalUpdate, ) from onyx.agents.agent_search.shared_graph_utils.models import AgentChunkStats diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/initial_answer_quality_check.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/initial_answer_quality_check.py similarity index 78% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/initial_answer_quality_check.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/initial_answer_quality_check.py index 6b7199ae6..a9978b49f 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/initial_answer_quality_check.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/initial_answer_quality_check.py @@ -1,10 +1,10 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerQualityUpdate, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/retrieval_consolidation.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/retrieval_consolidation.py similarity index 56% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/retrieval_consolidation.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/retrieval_consolidation.py index acc27c0e3..f2007dff3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/nodes/retrieval_consolidation.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/nodes/retrieval_consolidation.py @@ -1,9 +1,9 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import LoggerUpdate +from onyx.agents.agent_search.deep_search_a.main.states import LoggerUpdate def retrieval_consolidation( diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/states.py b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/states.py similarity index 62% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/states.py index 982d39d6f..c199d0cf6 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/initial_answer_generation/states.py @@ -3,23 +3,23 @@ from typing import Annotated from typing import TypedDict from onyx.agents.agent_search.core_state import CoreState -from onyx.agents.agent_search.deep_search_a.main__graph.states import BaseDecompUpdate -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import BaseDecompUpdate +from onyx.agents.agent_search.deep_search_a.main.states import ( DecompAnswersUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( ExpandedRetrievalUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( ExploratorySearchUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerQualityUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerUpdate, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.models import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.models import ( ExpandedRetrievalResult, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/graph_builder.py similarity index 71% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/graph_builder.py index a91a9dacc..a8d4fbe09 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/graph_builder.py @@ -2,25 +2,25 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.nodes.format_raw_search_results import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.nodes.format_raw_search_results import ( format_raw_search_results, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.nodes.generate_raw_search_data import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.nodes.generate_raw_search_data import ( generate_raw_search_data, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.nodes.ingest_initial_base_retrieval import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.nodes.ingest_initial_base_retrieval import ( ingest_initial_base_retrieval, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchInput, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchState, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.graph_builder import ( expanded_retrieval_graph_builder, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/models.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/models.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/models.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/models.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/format_raw_search_results.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/format_raw_search_results.py similarity index 72% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/format_raw_search_results.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/format_raw_search_results.py index 7ab7c5107..2f25b2be8 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/format_raw_search_results.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/format_raw_search_results.py @@ -1,7 +1,7 @@ -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchOutput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalOutput, ) from onyx.utils.logger import setup_logger diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/generate_raw_search_data.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/generate_raw_search_data.py similarity index 89% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/generate_raw_search_data.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/generate_raw_search_data.py index 34eddfb18..35d8dc7b1 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/generate_raw_search_data.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/generate_raw_search_data.py @@ -3,7 +3,7 @@ from typing import cast from langchain_core.runnables.config import RunnableConfig from onyx.agents.agent_search.core_state import CoreState -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/ingest_initial_base_retrieval.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/ingest_initial_base_retrieval.py similarity index 83% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/ingest_initial_base_retrieval.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/ingest_initial_base_retrieval.py index 3f600c837..fe9811db3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/nodes/ingest_initial_base_retrieval.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/nodes/ingest_initial_base_retrieval.py @@ -1,10 +1,10 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.retrieval.states import ( BaseRawSearchOutput, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( ExpandedRetrievalUpdate, ) from onyx.agents.agent_search.shared_graph_utils.models import AgentChunkStats diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/states.py b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/states.py similarity index 78% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/states.py index 132f7fe5a..1046f7323 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval__subgraph/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/retrieval/states.py @@ -1,12 +1,12 @@ from pydantic import BaseModel -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( ExpandedRetrievalUpdate, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.models import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.models import ( ExpandedRetrievalResult, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/edges.py similarity index 85% rename from backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/edges.py index f92727b4f..788c24ce3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__retrieval_sub_answers__subgraph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/edges.py @@ -3,13 +3,13 @@ from datetime import datetime from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) from onyx.agents.agent_search.shared_graph_utils.utils import make_question_id diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/graph_builder.py similarity index 75% rename from backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/graph_builder.py index 41f9de1d5..a594aaf65 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/graph_builder.py @@ -2,24 +2,24 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.edges import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.graph_builder import ( + answer_query_graph_builder, +) +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.edges import ( parallelize_initial_sub_question_answering, ) -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.nodes.ingest_initial_sub_answers import ( +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.nodes.ingest_initial_sub_answers import ( ingest_initial_sub_answers, ) -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.nodes.initial_decomposition import ( +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.nodes.initial_decomposition import ( initial_sub_question_creation, ) -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.states import ( SQInput, ) -from onyx.agents.agent_search.deep_search_a.initial__consolidate_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.sub_answer_consolidation.states import ( SQState, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.graph_builder import ( - answer_query_graph_builder, -) from onyx.utils.logger import setup_logger logger = setup_logger() diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/ingest_initial_sub_answers.py b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/ingest_initial_sub_answers.py similarity index 82% rename from backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/ingest_initial_sub_answers.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/ingest_initial_sub_answers.py index f4c606bba..92860ca18 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/ingest_initial_sub_answers.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/ingest_initial_sub_answers.py @@ -1,10 +1,10 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( DecompAnswersUpdate, ) from onyx.agents.agent_search.shared_graph_utils.operators import ( @@ -38,7 +38,7 @@ def ingest_initial_sub_answers( documents=dedup_inference_sections(documents, []), context_documents=dedup_inference_sections(context_documents, []), cited_docs=dedup_inference_sections(cited_docs, []), - decomp_answer_results=answer_results, + sub_question_results=answer_results, log_messages=[ f"{now_start} -- Main - Ingest initial processed sub questions, Time taken: {now_end - now_start}" ], diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/initial_decomposition.py b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/initial_decomposition.py similarity index 91% rename from backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/initial_decomposition.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/initial_decomposition.py index 2466185fb..f7edb2434 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/nodes/initial_decomposition.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/nodes/initial_decomposition.py @@ -6,17 +6,17 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_content from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.states import ( SearchSQState, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentRefinedMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import ( +from onyx.agents.agent_search.deep_search_a.main.operations import ( dispatch_subquestion, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import BaseDecompUpdate +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import BaseDecompUpdate from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.agent_prompt_ops import ( build_history_prompt, diff --git a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/states.py b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/states.py similarity index 70% rename from backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/states.py index a563defd0..fed585e4d 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/initial__consolidate_sub_answers__subgraph/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/initial/sub_answer_consolidation/states.py @@ -1,11 +1,11 @@ from typing import TypedDict from onyx.agents.agent_search.core_state import CoreState -from onyx.agents.agent_search.deep_search_a.main__graph.states import BaseDecompUpdate -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import BaseDecompUpdate +from onyx.agents.agent_search.deep_search_a.main.states import ( DecompAnswersUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerUpdate, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/main/edges.py similarity index 91% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/main/edges.py index c8d3b2e5f..5ed7254a9 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/edges.py @@ -6,14 +6,14 @@ from typing import Literal from langchain_core.runnables import RunnableConfig from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import ( RequireRefinedAnswerUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/main/graph_builder.py similarity index 88% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/main/graph_builder.py index 609914e3a..bb8479dae 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/graph_builder.py @@ -2,45 +2,45 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__retrieval_sub_answers__subgraph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.initial.initial_answer_generation.graph_builder import ( initial_search_sq_subgraph_builder, ) -from onyx.agents.agent_search.deep_search_a.main__graph.edges import ( +from onyx.agents.agent_search.deep_search_a.main.edges import ( continue_to_refined_answer_or_end, ) -from onyx.agents.agent_search.deep_search_a.main__graph.edges import ( +from onyx.agents.agent_search.deep_search_a.main.edges import ( parallelize_refined_sub_question_answering, ) -from onyx.agents.agent_search.deep_search_a.main__graph.edges import ( +from onyx.agents.agent_search.deep_search_a.main.edges import ( route_initial_tool_choice, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.agent_logging import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.agent_logging import ( agent_logging, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.agent_search_start import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.agent_search_start import ( agent_search_start, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.answer_comparison import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.answer_comparison import ( answer_comparison, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.entity_term_extraction_llm import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.entity_term_extraction_llm import ( entity_term_extraction_llm, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.generate_refined_answer import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.generate_refined_answer import ( generate_refined_answer, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.ingest_refined_answers import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.ingest_refined_answers import ( ingest_refined_answers, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.refined_answer_decision import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.refined_answer_decision import ( refined_answer_decision, ) -from onyx.agents.agent_search.deep_search_a.main__graph.nodes.refined_sub_question_creation import ( +from onyx.agents.agent_search.deep_search_a.main.nodes.refined_sub_question_creation import ( refined_sub_question_creation, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainInput -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState -from onyx.agents.agent_search.deep_search_a.refinement__consolidate_sub_answers__subgraph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.main.states import MainInput +from onyx.agents.agent_search.deep_search_a.main.states import MainState +from onyx.agents.agent_search.deep_search_a.refininement.sub_answer_consolidation.graph_builder import ( answer_refined_query_graph_builder, ) from onyx.agents.agent_search.orchestration.nodes.basic_use_tool_response import ( diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/models.py b/backend/onyx/agents/agent_search/deep_search_a/main/models.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/models.py rename to backend/onyx/agents/agent_search/deep_search_a/main/models.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_logging.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_logging.py similarity index 90% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_logging.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_logging.py index 8ec12ea9d..21f00c603 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_logging.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_logging.py @@ -3,13 +3,13 @@ from typing import cast from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentAdditionalMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import AgentTimings -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainOutput -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.models import AgentTimings +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import MainOutput +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.models import CombinedAgentMetrics from onyx.db.chat import log_agent_metrics @@ -85,7 +85,7 @@ def agent_logging(state: MainState, config: RunnableConfig) -> MainOutput: db_session = agent_a_config.db_session chat_session_id = agent_a_config.chat_session_id primary_message_id = agent_a_config.message_id - sub_question_answer_results = state.decomp_answer_results + sub_question_answer_results = state.sub_question_results log_agent_sub_question_results( db_session=db_session, diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_decision.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_decision.py similarity index 79% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_decision.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_decision.py index 1027f8a76..89cfb425e 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_decision.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_decision.py @@ -3,9 +3,9 @@ from typing import cast from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState -from onyx.agents.agent_search.deep_search_a.main__graph.states import RoutingDecision +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import RoutingDecision from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_routing.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_routing.py similarity index 90% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_routing.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_routing.py index 967a8c25e..56dc837ad 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_path_routing.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_path_routing.py @@ -3,7 +3,7 @@ from typing import Literal from langgraph.types import Command -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState def agent_path_routing( diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_search_start.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_search_start.py similarity index 89% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_search_start.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_search_start.py index 752bbea1f..358bb0d25 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/agent_search_start.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/agent_search_start.py @@ -3,11 +3,11 @@ from typing import cast from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( ExploratorySearchUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.agent_prompt_ops import ( build_history_prompt, diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/answer_comparison.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py similarity index 88% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/answer_comparison.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py index 1bdcdd9e1..f2f19322b 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/answer_comparison.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/answer_comparison.py @@ -5,9 +5,9 @@ from langchain_core.callbacks.manager import dispatch_custom_event from langchain_core.messages import HumanMessage from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import AnswerComparison -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import AnswerComparison +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.prompts import ANSWER_COMPARISON_PROMPT from onyx.chat.models import RefinedAnswerImprovement diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/direct_llm_handling.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/direct_llm_handling.py similarity index 91% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/direct_llm_handling.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/direct_llm_handling.py index 8f275f297..371d6ae6a 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/direct_llm_handling.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/direct_llm_handling.py @@ -7,11 +7,11 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_content from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.prompts import DIRECT_LLM_PROMPT from onyx.agents.agent_search.shared_graph_utils.utils import ( diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/entity_term_extraction_llm.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/entity_term_extraction_llm.py similarity index 94% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/entity_term_extraction_llm.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/entity_term_extraction_llm.py index 7df9d11a0..dbef33257 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/entity_term_extraction_llm.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/entity_term_extraction_llm.py @@ -6,11 +6,11 @@ from typing import cast from langchain_core.messages import HumanMessage from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( EntityTermExtractionUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.agent_prompt_ops import ( trim_prompt_piece, diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_initial_base_search_only_answer.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_base_search_only_answer.py similarity index 87% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_initial_base_search_only_answer.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_base_search_only_answer.py index 4bba848c8..a40f3e6db 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_initial_base_search_only_answer.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_initial_base_search_only_answer.py @@ -4,11 +4,11 @@ from typing import cast from langchain_core.messages import HumanMessage from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( InitialAnswerBASEUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.agent_prompt_ops import ( trim_prompt_piece, diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_refined_answer.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_refined_answer.py similarity index 94% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_refined_answer.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_refined_answer.py index 114b904df..6389bad61 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/generate_refined_answer.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/generate_refined_answer.py @@ -7,16 +7,16 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_content from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentRefinedMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import get_query_info -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.operations import ( +from onyx.agents.agent_search.deep_search_a.main.operations import get_query_info +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.operations import ( remove_document_citations, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import ( RefinedAnswerUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig @@ -36,7 +36,7 @@ from onyx.agents.agent_search.shared_graph_utils.prompts import ( REVISED_RAG_PROMPT_NO_SUB_QUESTIONS, ) from onyx.agents.agent_search.shared_graph_utils.prompts import ( - SUB_QUESTION_ANSWER_TEMPLATE, + SUB_QUESTION_ANSWER_TEMPLATE_REVISED, ) from onyx.agents.agent_search.shared_graph_utils.prompts import UNKNOWN_ANSWER from onyx.agents.agent_search.shared_graph_utils.utils import ( @@ -119,7 +119,7 @@ def generate_refined_answer( else: revision_doc_effectiveness = 10.0 - decomp_answer_results = state.decomp_answer_results + decomp_answer_results = state.sub_question_results # revised_answer_results = state.refined_decomp_answer_results answered_qa_list: list[str] = [] @@ -141,17 +141,20 @@ def generate_refined_answer( and len(decomp_answer_result.answer) > 0 and decomp_answer_result.answer != UNKNOWN_ANSWER ): + if question_level == 0: + initial_good_sub_questions.append(decomp_answer_result.question) + sub_question_type = "initial" + else: + new_revised_good_sub_questions.append(decomp_answer_result.question) + sub_question_type = "refined" answered_qa_list.append( - SUB_QUESTION_ANSWER_TEMPLATE.format( + SUB_QUESTION_ANSWER_TEMPLATE_REVISED.format( sub_question=decomp_answer_result.question, sub_answer=decomp_answer_result.answer, sub_question_nr=sub_question_nr, + sub_question_type=sub_question_type, ) ) - if question_level == 0: - initial_good_sub_questions.append(decomp_answer_result.question) - else: - new_revised_good_sub_questions.append(decomp_answer_result.question) sub_question_nr += 1 diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/ingest_refined_answers.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/ingest_refined_answers.py similarity index 78% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/ingest_refined_answers.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/ingest_refined_answers.py index de15e664d..b30671221 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/ingest_refined_answers.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/ingest_refined_answers.py @@ -1,10 +1,10 @@ from datetime import datetime -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( DecompAnswersUpdate, ) from onyx.agents.agent_search.shared_graph_utils.operators import ( @@ -34,7 +34,7 @@ def ingest_refined_answers( # Deduping is done by the documents operator for the main graph # so we might not need to dedup here documents=dedup_inference_sections(documents, []), - decomp_answer_results=answer_results, + sub_question_results=answer_results, log_messages=[ f"{now_start} -- Main - Ingest refined answers, Time taken: {now_end - now_start}" ], diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_answer_decision.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_answer_decision.py similarity index 84% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_answer_decision.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_answer_decision.py index 6dfd42b30..1c31d8998 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_answer_decision.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_answer_decision.py @@ -3,9 +3,9 @@ from typing import cast from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import ( RequireRefinedAnswerUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_sub_question_creation.py b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_sub_question_creation.py similarity index 89% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_sub_question_creation.py rename to backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_sub_question_creation.py index b0a82a772..807ed5f46 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/nodes/refined_sub_question_creation.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/nodes/refined_sub_question_creation.py @@ -6,17 +6,17 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_content from langchain_core.runnables import RunnableConfig -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( FollowUpSubQuestion, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import ( +from onyx.agents.agent_search.deep_search_a.main.operations import ( dispatch_subquestion, ) -from onyx.agents.agent_search.deep_search_a.main__graph.operations import logger -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.operations import logger +from onyx.agents.agent_search.deep_search_a.main.states import ( FollowUpSubQuestionsUpdate, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import MainState +from onyx.agents.agent_search.deep_search_a.main.states import MainState from onyx.agents.agent_search.models import AgentSearchConfig from onyx.agents.agent_search.shared_graph_utils.agent_prompt_ops import ( build_history_prompt, @@ -64,7 +64,7 @@ def refined_sub_question_creation( entity_retlation_term_extractions ) - initial_question_answers = state.decomp_answer_results + initial_question_answers = state.sub_question_results addressed_question_list = [ x.question for x in initial_question_answers if x.verified_high_quality diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/operations.py b/backend/onyx/agents/agent_search/deep_search_a/main/operations.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/operations.py rename to backend/onyx/agents/agent_search/deep_search_a/main/operations.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/main__graph/states.py b/backend/onyx/agents/agent_search/deep_search_a/main/states.py similarity index 93% rename from backend/onyx/agents/agent_search/deep_search_a/main__graph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/main/states.py index 6cfca52ff..bb6e1283f 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/main__graph/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/main/states.py @@ -6,14 +6,14 @@ from typing import TypedDict from pydantic import BaseModel from onyx.agents.agent_search.core_state import CoreState -from onyx.agents.agent_search.deep_search_a.main__graph.models import AgentBaseMetrics -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import AgentBaseMetrics +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentRefinedMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( FollowUpSubQuestion, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.models import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.models import ( ExpandedRetrievalResult, ) from onyx.agents.agent_search.orchestration.states import ToolCallUpdate @@ -107,7 +107,7 @@ class DecompAnswersUpdate(LoggerUpdate): cited_docs: Annotated[ list[InferenceSection], dedup_inference_sections ] = [] # cited docs from sub-answers are used for answer context - decomp_answer_results: Annotated[ + sub_question_results: Annotated[ list[QuestionAnswerResults], dedup_question_answer_results ] = [] diff --git a/backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/edges.py similarity index 78% rename from backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/edges.py index 370da0708..da6bf42d3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/edges.py @@ -3,10 +3,10 @@ from datetime import datetime from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) from onyx.utils.logger import setup_logger diff --git a/backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/graph_builder.py similarity index 75% rename from backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/graph_builder.py index 9bb4f3293..cbabe34d3 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/graph_builder.py @@ -2,31 +2,31 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.answer_check import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.answer_check import ( answer_check, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.answer_generation import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.answer_generation import ( answer_generation, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.format_answer import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.format_answer import ( format_answer, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.nodes.ingest_retrieval import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.nodes.ingest_retrieval import ( ingest_retrieval, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionInput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionOutput, ) -from onyx.agents.agent_search.deep_search_a.initial__individual_sub_answer__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.initial.individual_sub_answer_generation.states import ( AnswerQuestionState, ) -from onyx.agents.agent_search.deep_search_a.refinement__consolidate_sub_answers__subgraph.edges import ( +from onyx.agents.agent_search.deep_search_a.refininement.sub_answer_consolidation.edges import ( send_to_expanded_refined_retrieval, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.graph_builder import ( expanded_retrieval_graph_builder, ) from onyx.utils.logger import setup_logger diff --git a/backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/models.py b/backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/models.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/refinement__consolidate_sub_answers__subgraph/models.py rename to backend/onyx/agents/agent_search/deep_search_a/refininement/sub_answer_consolidation/models.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/edges.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/edges.py similarity index 83% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/edges.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/edges.py index a93b18fb9..9bf2db96d 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/edges.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/edges.py @@ -4,10 +4,10 @@ from typing import cast from langchain_core.runnables.config import RunnableConfig from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( RetrievalInput, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/graph_builder.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/graph_builder.py similarity index 73% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/graph_builder.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/graph_builder.py index 141c3d418..2f8546494 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/graph_builder.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/graph_builder.py @@ -2,37 +2,37 @@ from langgraph.graph import END from langgraph.graph import START from langgraph.graph import StateGraph -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.edges import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.edges import ( parallel_retrieval_edge, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.doc_reranking import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.doc_reranking import ( doc_reranking, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.doc_retrieval import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.doc_retrieval import ( doc_retrieval, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.doc_verification import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.doc_verification import ( doc_verification, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.dummy import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.dummy import ( dummy, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.expand_queries import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.expand_queries import ( expand_queries, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.format_results import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.format_results import ( format_results, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.nodes.verification_kickoff import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.nodes.verification_kickoff import ( verification_kickoff, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalOutput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) from onyx.agents.agent_search.shared_graph_utils.utils import get_test_config diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/models.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/models.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/models.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/models.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_reranking.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_reranking.py similarity index 92% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_reranking.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_reranking.py index 56fce68b6..5261f8d6b 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_reranking.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_reranking.py @@ -3,13 +3,13 @@ from typing import cast from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.operations import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.operations import ( logger, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( DocRerankingUpdate, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_retrieval.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_retrieval.py similarity index 93% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_retrieval.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_retrieval.py index 651311fc5..ade4be9ec 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_retrieval.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_retrieval.py @@ -3,13 +3,13 @@ from typing import cast from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.operations import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.operations import ( logger, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( DocRetrievalUpdate, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( RetrievalInput, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_verification.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_verification.py similarity index 89% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_verification.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_verification.py index 36a61e363..d877544b6 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/doc_verification.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/doc_verification.py @@ -3,10 +3,10 @@ from typing import cast from langchain_core.messages import HumanMessage from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( DocVerificationInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( DocVerificationUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/dummy.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/dummy.py similarity index 61% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/dummy.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/dummy.py index 62941f35f..6527146d2 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/dummy.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/dummy.py @@ -1,9 +1,9 @@ from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( QueryExpansionUpdate, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/expand_queries.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/expand_queries.py similarity index 85% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/expand_queries.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/expand_queries.py index c34eeee7e..620267af5 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/expand_queries.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/expand_queries.py @@ -5,16 +5,16 @@ from langchain_core.messages import HumanMessage from langchain_core.messages import merge_message_runs from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.operations import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.operations import ( dispatch_subquery, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.operations import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.operations import ( logger, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( QueryExpansionUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/format_results.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/format_results.py similarity index 89% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/format_results.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/format_results.py index 846f8029a..198c9b872 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/format_results.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/format_results.py @@ -3,16 +3,16 @@ from typing import cast from langchain_core.callbacks.manager import dispatch_custom_event from langchain_core.runnables.config import RunnableConfig -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.models import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.models import ( ExpandedRetrievalResult, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.operations import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.operations import ( calculate_sub_question_retrieval_stats, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalUpdate, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/verification_kickoff.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/verification_kickoff.py similarity index 83% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/verification_kickoff.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/verification_kickoff.py index 261a596a5..65d5d7ade 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/nodes/verification_kickoff.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/nodes/verification_kickoff.py @@ -4,10 +4,10 @@ from langchain_core.runnables.config import RunnableConfig from langgraph.types import Command from langgraph.types import Send -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( DocVerificationInput, ) -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.states import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.states import ( ExpandedRetrievalState, ) diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/operations.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/operations.py similarity index 100% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/operations.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/operations.py diff --git a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/states.py b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/states.py similarity index 95% rename from backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/states.py rename to backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/states.py index c2704bdec..0f490a101 100644 --- a/backend/onyx/agents/agent_search/deep_search_a/util__expanded_retrieval__subgraph/states.py +++ b/backend/onyx/agents/agent_search/deep_search_a/shared/expanded_retrieval/states.py @@ -4,7 +4,7 @@ from typing import Annotated from pydantic import BaseModel from onyx.agents.agent_search.core_state import SubgraphCoreState -from onyx.agents.agent_search.deep_search_a.util__expanded_retrieval__subgraph.models import ( +from onyx.agents.agent_search.deep_search_a.shared.expanded_retrieval.models import ( ExpandedRetrievalResult, ) from onyx.agents.agent_search.shared_graph_utils.models import QueryResult diff --git a/backend/onyx/agents/agent_search/run_graph.py b/backend/onyx/agents/agent_search/run_graph.py index 38b41d06a..188e3170f 100644 --- a/backend/onyx/agents/agent_search/run_graph.py +++ b/backend/onyx/agents/agent_search/run_graph.py @@ -9,10 +9,10 @@ from langgraph.graph.state import CompiledStateGraph from onyx.agents.agent_search.basic.graph_builder import basic_graph_builder from onyx.agents.agent_search.basic.states import BasicInput -from onyx.agents.agent_search.deep_search_a.main__graph.graph_builder import ( +from onyx.agents.agent_search.deep_search_a.main.graph_builder import ( main_graph_builder as main_graph_builder_a, ) -from onyx.agents.agent_search.deep_search_a.main__graph.states import ( +from onyx.agents.agent_search.deep_search_a.main.states import ( MainInput as MainInput_a, ) from onyx.agents.agent_search.models import AgentSearchConfig diff --git a/backend/onyx/agents/agent_search/shared_graph_utils/models.py b/backend/onyx/agents/agent_search/shared_graph_utils/models.py index a399fa1df..5540777f8 100644 --- a/backend/onyx/agents/agent_search/shared_graph_utils/models.py +++ b/backend/onyx/agents/agent_search/shared_graph_utils/models.py @@ -2,14 +2,14 @@ from typing import Literal from pydantic import BaseModel -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentAdditionalMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import AgentBaseMetrics -from onyx.agents.agent_search.deep_search_a.main__graph.models import ( +from onyx.agents.agent_search.deep_search_a.main.models import AgentBaseMetrics +from onyx.agents.agent_search.deep_search_a.main.models import ( AgentRefinedMetrics, ) -from onyx.agents.agent_search.deep_search_a.main__graph.models import AgentTimings +from onyx.agents.agent_search.deep_search_a.main.models import AgentTimings from onyx.context.search.models import InferenceSection from onyx.tools.models import SearchQueryInfo diff --git a/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py b/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py index b429ac095..02c02fc3e 100644 --- a/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py +++ b/backend/onyx/agents/agent_search/shared_graph_utils/prompts.py @@ -1,9 +1,14 @@ +# The prompts for the agentic framework: + UNKNOWN_ANSWER = "I do not have enough information to answer this question." + NO_RECOVERED_DOCS = "No relevant information recovered" + DATE_PROMPT = """Today is {date}.\n\n""" + HISTORY_PROMPT = """\n For more context, here is the history of the conversation so far that preceded this question: \n ------- \n @@ -11,58 +16,63 @@ For more context, here is the history of the conversation so far that preceded t \n ------- \n\n """ + REWRITE_PROMPT_MULTI_ORIGINAL = """ \n - Please convert an initial user question into a 2-3 more appropriate short and pointed search queries for retrivel from a - document store. Particularly, try to think about resolving ambiguities and make the search queries more specific, - enabling the system to search more broadly. - Also, try to make the search queries not redundant, i.e. not too similar! \n\n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n - Formulate the queries separated by newlines (Do not say 'Query 1: ...', just write the querytext) as follows: +Please convert an initial user question into a 2-3 more appropriate short and pointed search queries for retrivel from a +document store. Particularly, try to think about resolving ambiguities and make the search queries more specific, +enabling the system to search more broadly. +Also, try to make the search queries not redundant, i.e. not too similar! \n\n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n +Formulate the queries separated by newlines (Do not say 'Query 1: ...', just write the querytext) as follows: ... - queries: """ +queries: """ + REWRITE_PROMPT_MULTI = """ \n - Please create a list of 2-3 sample documents that could answer an original question. Each document - should be about as long as the original question. \n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n - Formulate the sample documents separated by '--' (Do not say 'Document 1: ...', just write the text): """ +Please create a list of 2-3 sample documents that could answer an original question. Each document +should be about as long as the original question. \n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n +Formulate the sample documents separated by '--' (Do not say 'Document 1: ...', just write the text): """ + # The prompt is only used if there is no persona prompt, so the placeholder is '' BASE_RAG_PROMPT = ( """ \n - {persona_specification} - {date_prompt} - Use the context provided below - and only the - provided context - to answer the given question. (Note that the answer is in service of ansering a broader - question, given below as 'motivation'.) +{persona_specification} +{date_prompt} +Use the context provided below - and only the +provided context - to answer the given question. (Note that the answer is in service of ansering a broader +question, given below as 'motivation'.) - Again, only use the provided context and do not use your internal knowledge! If you cannot answer the - question based on the context, say """ +Again, only use the provided context and do not use your internal knowledge! If you cannot answer the +question based on the context, say """ + f'"{UNKNOWN_ANSWER}"' + """. - It is a matter of life and death that you do NOT use your internal knowledge, just the provided` - information! - Make sure that you keep all relevant information, specifically as it concerns to the ultimate goal. - (But keep other details as well.) +It is a matter of life and death that you do NOT use your internal knowledge, just the provided` +information! - \nContext:\n {context} \n +Make sure that you keep all relevant information, specifically as it concerns to the ultimate goal. +(But keep other details as well.) - Motivation:\n {original_question} \n\n - \n\n - And here is the question I want you to answer based on the context above (with the motivation in mind): - \n--\n {question} \n--\n - """ +\nContext:\n {context} \n + +Motivation:\n {original_question} \n\n +\n\n +And here is the question I want you to answer based on the context above (with the motivation in mind): +\n--\n {question} \n--\n +""" ) + BASE_RAG_PROMPT_v2 = ( """ \n {date_prompt} @@ -84,8 +94,10 @@ It is important that the citation is close to the information it supports. Proper citations are very important to the user!\n\n\n For your general information, here is the ultimate motivation: -\n--\n {original_question} \n--\n -\n\n +\n--\n +{original_question} +\n--\n +\n And here is the actual question I want you to answer based on the context above (with the motivation in mind): \n--\n {question} \n--\n @@ -97,61 +109,72 @@ Answer: """ ) + SUB_CHECK_YES = "yes" SUB_CHECK_NO = "no" + SUB_CHECK_PROMPT = ( - """ - Your task is to see whether a given answer addresses a given question. - Please do not use any internal knowledge you may have - just focus on whether the answer - as given seems to largely address the question as given, or at least addresses part of the question. - Here is the question: - \n ------- \n - {question} - \n ------- \n - Here is the suggested answer: - \n ------- \n - {base_answer} - \n ------- \n - Does the suggested answer address the question? Please answer with """ + """\n +Your task is to see whether a given answer addresses a given question. +Please do not use any internal knowledge you may have - just focus on whether the answer +as given seems to largely address the question as given, or at least addresses part of the question. +Here is the question: +\n ------- \n +{question} +\n ------- \n +Here is the suggested answer: +\n ------- \n +{base_answer} +\n ------- \n +Does the suggested answer address the question? Please answer with """ + f'"{SUB_CHECK_YES}" or "{SUB_CHECK_NO}".' ) BASE_CHECK_PROMPT = """ \n - Please check whether 1) the suggested answer seems to fully address the original question AND 2)the - original question requests a simple, factual answer, and there are no ambiguities, judgements, - aggregations, or any other complications that may require extra context. (I.e., if the question is - somewhat addressed, but the answer would benefit from more context, then answer with 'no'.) +Please check whether 1) the suggested answer seems to fully address the original question AND 2)the +original question requests a simple, factual answer, and there are no ambiguities, judgements, +aggregations, or any other complications that may require extra context. (I.e., if the question is +somewhat addressed, but the answer would benefit from more context, then answer with 'no'.) + +Please only answer with 'yes' or 'no' \n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n +Here is the proposed answer: +\n ------- \n +{initial_answer} +\n ------- \n +Please answer with yes or no:""" - Please only answer with 'yes' or 'no' \n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n - Here is the proposed answer: - \n ------- \n - {initial_answer} - \n ------- \n - Please answer with yes or no:""" VERIFIER_PROMPT = """ You are supposed to judge whether a document text contains data or information that is potentially relevant for a question. It does not have to be fully relevant, but check whether it has some information that would help - possibly in conjunction with other documents - to address the question. +Be careful that you do not use a document where you are not sure whether the text applies to the objects +or entities that are relevant for the question. For example, a book about chess could have long passage +discussing the psychology of chess without - within the passage - mentioning chess. If now a question +is asked about the psychology of football, one could be tempted to use the document as it does discuss +psychology in sports. However, it is NOT about football and should not be deemed relevant. Please +consider this logic. + Here is a document text that you can take as a fact: --- + DOCUMENT INFORMATION: +\n ------- \n {document_content} --- +\n ------- \n Do you think that this document text is useful and relevant to answer the following question? --- QUESTION: +\n ------- \n {question} --- +\n ------- \n Please answer with 'yes' or 'no': @@ -181,41 +204,47 @@ Answer: """ REWRITE_PROMPT_SINGLE = """ \n - Please convert an initial user question into a more appropriate search query for retrieval from a - document store. \n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n +Please convert an initial user question into a more appropriate search query for retrieval from a +document store. \n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n - Formulate the query: """ +Formulate the query: """ MODIFIED_RAG_PROMPT = ( """You are an assistant for question-answering tasks. Use the context provided below - - and only this context - to answer the question. It is a matter of life and death that you do NOT - use your internal knowledge, just the provided information! - If you don't have enough information to generate an answer, just say """ +- and only this context - to answer the question. It is a matter of life and death that you do NOT +use your internal knowledge, just the provided information! +If you don't have enough information to generate an answer, just say """ + f'"{UNKNOWN_ANSWER}"' + """. - Use three sentences maximum and keep the answer concise. - Pay also particular attention to the sub-questions and their answers, at least it may enrich the answer. - Again, only use the provided context and do not use your internal knowledge! +Use three sentences maximum and keep the answer concise. +Pay also particular attention to the sub-questions and their answers, at least it may enrich the answer. +Again, only use the provided context and do not use your internal knowledge! - \nQuestion: {question} - \nContext: {combined_context} \n +\nQuestion: +\n ------- \n +{question} +\n ------- \n +\nContext: +\n ------- \n +{combined_context} +\n ------- \n - Answer:""" +Answer:""" ) ERT_INFORMED_DEEP_DECOMPOSE_PROMPT = """ \n - An initial user question needs to be answered. An initial answer has been provided but it wasn't quite - good enough. Also, some sub-questions had been answered and this information has been used to provide - the initial answer. Some other subquestions may have been suggested based on little knowledge, but they - were not directly answerable. Also, some entities, relationships and terms are givenm to you so that - you have an idea of how the available data looks like. +An initial user question needs to be answered. An initial answer has been provided but it wasn't quite +good enough. Also, some sub-questions had been answered and this information has been used to provide +the initial answer. Some other subquestions may have been suggested based on little knowledge, but they +were not directly answerable. Also, some entities, relationships and terms are givenm to you so that +you have an idea of how the available data looks like. - Your role is to generate 3-5 new sub-questions that would help to answer the initial question, - considering: +Your role is to generate 3-5 new sub-questions that would help to answer the initial question, +considering: 1) The initial question 2) The initial answer that was found to be unsatisfactory @@ -223,319 +252,325 @@ ERT_INFORMED_DEEP_DECOMPOSE_PROMPT = """ \n 4) The sub-questions that were suggested but not answered 5) The entities, relationships and terms that were extracted from the context - The individual questions should be answerable by a good RAG system. - So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the - question for different entities that may be involved in the original question, but in a way that does - not duplicate questions that were already tried. +The individual questions should be answerable by a good RAG system. +So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the +question for different entities that may be involved in the original question, but in a way that does +not duplicate questions that were already tried. - Additional Guidelines: +Additional Guidelines: - The sub-questions should be specific to the question and provide richer context for the question, - resolve ambiguities, or address shortcoming of the initial answer - Each sub-question - when answered - should be relevant for the answer to the original question - The sub-questions should be free from comparisons, ambiguities,judgements, aggregations, or any other complications that may require extra context. - The sub-questions MUST have the full context of the original question so that it can be executed by a RAG system independently without the original question available - (Example: - - initial question: "What is the capital of France?" - - bad sub-question: "What is the name of the river there?" - - good sub-question: "What is the name of the river that flows through Paris?" - - For each sub-question, please provide a short explanation for why it is a good sub-question. So - generate a list of dictionaries with the following format: - [{{"sub_question": , "explanation": , "search_term": }}, ...] + (Example: + - initial question: "What is the capital of France?" + - bad sub-question: "What is the name of the river there?" + - good sub-question: "What is the name of the river that flows through Paris?" - \n\n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n +For each sub-question, please provide a short explanation for why it is a good sub-question. So +generate a list of dictionaries with the following format: + [{{"sub_question": , "explanation": , "search_term": }}, ...] - Here is the initial sub-optimal answer: - \n ------- \n - {base_answer} - \n ------- \n +\n\n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n - Here are the sub-questions that were answered: - \n ------- \n - {answered_sub_questions} - \n ------- \n +Here is the initial sub-optimal answer: +\n ------- \n +{base_answer} +\n ------- \n - Here are the sub-questions that were suggested but not answered: - \n ------- \n - {failed_sub_questions} - \n ------- \n +Here are the sub-questions that were answered: +\n ------- \n +{answered_sub_questions} +\n ------- \n - And here are the entities, relationships and terms extracted from the context: - \n ------- \n - {entity_term_extraction_str} - \n ------- \n +Here are the sub-questions that were suggested but not answered: +\n ------- \n +{failed_sub_questions} +\n ------- \n - Please generate the list of good, fully contextualized sub-questions that would help to address the - main question. Again, please find questions that are NOT overlapping too much with the already answered - sub-questions or those that already were suggested and failed. - In other words - what can we try in addition to what has been tried so far? +And here are the entities, relationships and terms extracted from the context: +\n ------- \n +{entity_term_extraction_str} +\n ------- \n - Please think through it step by step and then generate the list of json dictionaries with the following - format: +Please generate the list of good, fully contextualized sub-questions that would help to address the +main question. Again, please find questions that are NOT overlapping too much with the already answered +sub-questions or those that already were suggested and failed. +In other words - what can we try in addition to what has been tried so far? + +Please think through it step by step and then generate the list of json dictionaries with the following +format: + +{{"sub_questions": [{{"sub_question": , + "explanation": , + "search_term": }}, + ...]}} """ - {{"sub_questions": [{{"sub_question": , - "explanation": , - "search_term": }}, - ...]}} """ DOC_INFORMED_DEEP_DECOMPOSE_PROMPT = """ \n - An initial user question needs to be answered. An initial answer has been provided but it wasn't quite - good enough. Also, some sub-questions had been answered and this information has been used to provide - the initial answer. Some other subquestions may have been suggested based on little knowledge, but they - were not directly answerable. Also, some entities, relationships and terms are given to you so that - you have an idea of how the avaiolable data looks like. +An initial user question needs to be answered. An initial answer has been provided but it wasn't quite +good enough. Also, some sub-questions had been answered and this information has been used to provide +the initial answer. Some other subquestions may have been suggested based on little knowledge, but they +were not directly answerable. Also, some entities, relationships and terms are given to you so that +you have an idea of how the avaiolable data looks like. - Your role is to generate 2-4 new sub-questions that would help to answer the initial question, - considering: +Your role is to generate 2-4 new sub-questions that would help to answer the initial question, +considering: - 1) The initial question - 2) The initial answer that was found to be unsatisfactory - 3) The sub-questions that were answered - 4) The sub-questions that were suggested but not answered - 5) A sample of the TYPE of documents that may be in the database in order to inform - you what type of entities, relationships, and terms you may want to consider asking about. - (But do not build the questions strictly on these documents! They are only examples! - Take the, as illustrations.) +1) The initial question +2) The initial answer that was found to be unsatisfactory +3) The sub-questions that were answered +4) The sub-questions that were suggested but not answered +5) A sample of the TYPE of documents that may be in the database in order to inform +you what type of entities, relationships, and terms you may want to consider asking about. +(But do not build the questions strictly on these documents! They are only examples! +Take the, as illustrations.) - The individual questions should be answerable by a good RAG system. - So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the - question for different entities that may be involved in the original question, but in a way that does - not duplicate questions that were already tried. +The individual questions should be answerable by a good RAG system. +So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the +question for different entities that may be involved in the original question, but in a way that does +not duplicate questions that were already tried. - Additional Guidelines: - - The sub-questions should be specific to the question and provide richer context for the question, - resolve ambiguities, or address shortcoming of the initial answer - - Each sub-question - when answered - should be relevant for the answer to the original question - - The sub-questions should be free from comparisions, ambiguities,judgements, aggregations, or any - other complications that may require extra context. - - The sub-questions MUST have the full context of the original question so that it can be executed by - a RAG system independently without the original question available - (Example: - - initial question: "What is the capital of France?" - - bad sub-question: "What is the name of the river there?" - - good sub-question: "What is the name of the river that flows through Paris?" - - For each sub-question, please also provide a search term that can be used to retrieve relevant - documents from a document store. - - Consider specifically the sub-questions that were suggested but not answered. This is a sign that they are not - answerable with the available context, and you should not ask similar questions. - \n\n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n - {history} +Additional Guidelines: +- The sub-questions should be specific to the question and provide richer context for the question, +resolve ambiguities, or address shortcoming of the initial answer +- Each sub-question - when answered - should be relevant for the answer to the original question +- The sub-questions should be free from comparisions, ambiguities,judgements, aggregations, or any +other complications that may require extra context. +- The sub-questions MUST have the full context of the original question so that it can be executed by +a RAG system independently without the original question available + (Example: + - initial question: "What is the capital of France?" + - bad sub-question: "What is the name of the river there?" + - good sub-question: "What is the name of the river that flows through Paris?" +- For each sub-question, please also provide a search term that can be used to retrieve relevant +documents from a document store. +- Consider specifically the sub-questions that were suggested but not answered. This is a sign that they are not +answerable with the available context, and you should not ask similar questions. +\n\n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n +{history} - Here is the initial sub-optimal answer: - \n ------- \n - {base_answer} - \n ------- \n +Here is the initial sub-optimal answer: +\n ------- \n +{base_answer} +\n ------- \n - Here are the sub-questions that were answered: - \n ------- \n - {answered_sub_questions} - \n ------- \n +Here are the sub-questions that were answered: +\n ------- \n +{answered_sub_questions} +\n ------- \n - Here are the sub-questions that were suggested but not answered: - \n ------- \n - {failed_sub_questions} - \n ------- \n +Here are the sub-questions that were suggested but not answered: +\n ------- \n +{failed_sub_questions} +\n ------- \n - And here some reference documents that show you what type of entities, relationships, - and terms you may want to consider to be as relevant to your initial question. - \n ------- \n - {docs_str} - \n ------- \n +And here some reference documents that show you what type of entities, relationships, +and terms you may want to consider to be as relevant to your initial question. +\n ------- \n +{docs_str} +\n ------- \n - Please generate the list of good, fully contextualized sub-questions that would help to address the - main question. +Please generate the list of good, fully contextualized sub-questions that would help to address the +main question. - Specifically pay attention also to the entities, relationships and terms extracted, as these indicate what type of - objects/relationships/terms you can ask about! Do not ask about entities, terms or relationships that are not - mentioned in the 'entities, relationships and terms' section. +Specifically pay attention also to the entities, relationships and terms extracted, as these indicate what type of +objects/relationships/terms you can ask about! Do not ask about entities, terms or relationships that are not +mentioned in the 'entities, relationships and terms' section. - Again, please find questions that are NOT overlapping too much with the already answered - sub-questions or those that already were suggested and failed. - In other words - what can we try in addition to what has been tried so far? +Again, please find questions that are NOT overlapping too much with the already answered +sub-questions or those that already were suggested and failed. +In other words - what can we try in addition to what has been tried so far? - Generate the list of questions separated by one new line like this: +Generate the list of questions separated by one new line like this: - ... - """ +... +""" + DEEP_DECOMPOSE_PROMPT_WITH_ENTITIES = """ \n - An initial user question needs to be answered. An initial answer has been provided but it wasn't quite - good enough. Also, some sub-questions had been answered and this information has been used to provide - the initial answer. Some other subquestions may have been suggested based on little knowledge, but they - were not directly answerable. Also, some entities, relationships and terms are given to you so that - you have an idea of how the available data looks like. +An initial user question needs to be answered. An initial answer has been provided but it wasn't quite +good enough. Also, some sub-questions had been answered and this information has been used to provide +the initial answer. Some other subquestions may have been suggested based on little knowledge, but they +were not directly answerable. Also, some entities, relationships and terms are given to you so that +you have an idea of how the available data looks like. - Your role is to generate 2-4 new sub-questions that would help to answer the initial question, - considering: +Your role is to generate 2-4 new sub-questions that would help to answer the initial question, +considering: - 1) The initial question - 2) The initial answer that was found to be unsatisfactory - 3) The sub-questions that were answered - 4) The sub-questions that were suggested but not answered - 5) The entities, relationships and terms that were extracted from the context +1) The initial question +2) The initial answer that was found to be unsatisfactory +3) The sub-questions that were answered +4) The sub-questions that were suggested but not answered +5) The entities, relationships and terms that were extracted from the context - The individual questions should be answerable by a good RAG system. - So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the - question for different entities that may be involved in the original question, but in a way that does - not duplicate questions that were already tried. +The individual questions should be answerable by a good RAG system. +So a good idea would be to use the sub-questions to resolve ambiguities and/or to separate the +question for different entities that may be involved in the original question, but in a way that does +not duplicate questions that were already tried. - Additional Guidelines: - - The sub-questions should be specific to the question and provide richer context for the question, - resolve ambiguities, or address shortcoming of the initial answer - - Each sub-question - when answered - should be relevant for the answer to the original question - - The sub-questions should be free from comparisons, ambiguities,judgements, aggregations, or any - other complications that may require extra context. - - The sub-questions MUST have the full context of the original question so that it can be executed by - a RAG system independently without the original question available - (Example: - - initial question: "What is the capital of France?" - - bad sub-question: "What is the name of the river there?" - - good sub-question: "What is the name of the river that flows through Paris?" - - For each sub-question, please also provide a search term that can be used to retrieve relevant - documents from a document store. - - Consider specifically the sub-questions that were suggested but not answered. This is a sign that they are not - answerable with the available context, and you should not ask similar questions. - \n\n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n - {history} +Additional Guidelines: +- The sub-questions should be specific to the question and provide richer context for the question, +resolve ambiguities, or address shortcoming of the initial answer +- Each sub-question - when answered - should be relevant for the answer to the original question +- The sub-questions should be free from comparisons, ambiguities,judgements, aggregations, or any +other complications that may require extra context. +- The sub-questions MUST have the full context of the original question so that it can be executed by +a RAG system independently without the original question available + (Example: + - initial question: "What is the capital of France?" + - bad sub-question: "What is the name of the river there?" + - good sub-question: "What is the name of the river that flows through Paris?" +- For each sub-question, please also provide a search term that can be used to retrieve relevant +documents from a document store. +- Consider specifically the sub-questions that were suggested but not answered. This is a sign that they are not +answerable with the available context, and you should not ask similar questions. +\n\n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n +{history} - Here is the initial sub-optimal answer: - \n ------- \n - {base_answer} - \n ------- \n +Here is the initial sub-optimal answer: +\n ------- \n +{base_answer} +\n ------- \n - Here are the sub-questions that were answered: - \n ------- \n - {answered_sub_questions} - \n ------- \n +Here are the sub-questions that were answered: +\n ------- \n +{answered_sub_questions} +\n ------- \n - Here are the sub-questions that were suggested but not answered: - \n ------- \n - {failed_sub_questions} - \n ------- \n +Here are the sub-questions that were suggested but not answered: +\n ------- \n +{failed_sub_questions} +\n ------- \n - And here are the entities, relationships and terms extracted from the context: - \n ------- \n - {entity_term_extraction_str} - \n ------- \n +And here are the entities, relationships and terms extracted from the context: +\n ------- \n +{entity_term_extraction_str} +\n ------- \n - Please generate the list of good, fully contextualized sub-questions that would help to address the - main question. +Please generate the list of good, fully contextualized sub-questions that would help to address the +main question. - Specifically pay attention also to the entities, relationships and terms extracted, as these indicate what type of - objects/relationships/terms you can ask about! Do not ask about entities, terms or relationships that are not - mentioned in the 'entities, relationships and terms' section. +Specifically pay attention also to the entities, relationships and terms extracted, as these indicate what type of +objects/relationships/terms you can ask about! Do not ask about entities, terms or relationships that are not +mentioned in the 'entities, relationships and terms' section. - Again, please find questions that are NOT overlapping too much with the already answered - sub-questions or those that already were suggested and failed. - In other words - what can we try in addition to what has been tried so far? +Again, please find questions that are NOT overlapping too much with the already answered +sub-questions or those that already were suggested and failed. +In other words - what can we try in addition to what has been tried so far? - Generate the list of questions separated by one new line like this: +Generate the list of questions separated by one new line like this: - ... +... """ DECOMPOSE_PROMPT = """ \n - For an initial user question, please generate at 5-10 individual sub-questions whose answers would help - \n to answer the initial question. The individual questions should be answerable by a good RAG system. - So a good idea would be to \n use the sub-questions to resolve ambiguities and/or to separate the - question for different entities that may be involved in the original question. +For an initial user question, please generate at 5-10 individual sub-questions whose answers would help +\n to answer the initial question. The individual questions should be answerable by a good RAG system. +So a good idea would be to \n use the sub-questions to resolve ambiguities and/or to separate the +question for different entities that may be involved in the original question. - In order to arrive at meaningful sub-questions, please also consider the context retrieved from the - document store, expressed as entities, relationships and terms. You can also think about the types - mentioned in brackets +In order to arrive at meaningful sub-questions, please also consider the context retrieved from the +document store, expressed as entities, relationships and terms. You can also think about the types +mentioned in brackets - Guidelines: - - The sub-questions should be specific to the question and provide richer context for the question, - and or resolve ambiguities - - Each sub-question - when answered - should be relevant for the answer to the original question - - The sub-questions should be free from comparisons, ambiguities,judgements, aggregations, or any - other complications that may require extra context. - - The sub-questions MUST have the full context of the original question so that it can be executed by - a RAG system independently without the original question available - (Example: - - initial question: "What is the capital of France?" - - bad sub-question: "What is the name of the river there?" - - good sub-question: "What is the name of the river that flows through Paris?" - - For each sub-question, please provide a short explanation for why it is a good sub-question. So - generate a list of dictionaries with the following format: - [{{"sub_question": , "explanation": }}, ...] +Guidelines: +- The sub-questions should be specific to the question and provide richer context for the question, +and or resolve ambiguities +- Each sub-question - when answered - should be relevant for the answer to the original question +- The sub-questions should be free from comparisons, ambiguities,judgements, aggregations, or any +other complications that may require extra context. +- The sub-questions MUST have the full context of the original question so that it can be executed by +a RAG system independently without the original question available + (Example: + - initial question: "What is the capital of France?" + - bad sub-question: "What is the name of the river there?" + - good sub-question: "What is the name of the river that flows through Paris?" +- For each sub-question, please provide a short explanation for why it is a good sub-question. So +generate a list of dictionaries with the following format: + [{{"sub_question": , "explanation": }}, ...] - \n\n - Here is the initial question: - \n ------- \n - {question} - \n ------- \n +\n\n +Here is the initial question: +\n ------- \n +{question} +\n ------- \n - And here are the entities, relationships and terms extracted from the context: - \n ------- \n - {entity_term_extraction_str} - \n ------- \n +And here are the entities, relationships and terms extracted from the context: +\n ------- \n +{entity_term_extraction_str} +\n ------- \n - Please generate the list of good, fully contextualized sub-questions that would help to address the - main question. Don't be too specific unless the original question is specific. - Please think through it step by step and then generate the list of json dictionaries with the following - format: - {{"sub_questions": [{{"sub_question": , - "explanation": , - "search_term": }}, - ...]}} """ +Please generate the list of good, fully contextualized sub-questions that would help to address the +main question. Don't be too specific unless the original question is specific. +Please think through it step by step and then generate the list of json dictionaries with the following +format: +{{"sub_questions": [{{"sub_question": , + "explanation": , + "search_term": }}, + ...]}} """ #### Consolidations COMBINED_CONTEXT = """------- - Below you will find useful information to answer the original question. First, you see a number of - sub-questions with their answers. This information should be considered to be more focussed and - somewhat more specific to the original question as it tries to contextualized facts. - After that will see the documents that were considered to be relevant to answer the original question. +Below you will find useful information to answer the original question. First, you see a number of +sub-questions with their answers. This information should be considered to be more focussed and +somewhat more specific to the original question as it tries to contextualized facts. +After that will see the documents that were considered to be relevant to answer the original question. - Here are the sub-questions and their answers: - \n\n {deep_answer_context} \n\n - \n\n Here are the documents that were considered to be relevant to answer the original question: - \n\n {formated_docs} \n\n - ---------------- - """ +Here are the sub-questions and their answers: +\n\n {deep_answer_context} \n\n +\n\n Here are the documents that were considered to be relevant to answer the original question: +\n\n {formated_docs} \n\n +---------------- +""" SUB_QUESTION_EXPLANATION_RANKER_PROMPT = """------- - Below you will find a question that we ultimately want to answer (the original question) and a list of - motivations in arbitrary order for generated sub-questions that are supposed to help us answering the - original question. The motivations are formatted as : . - (Again, the numbering is arbitrary and does not necessarily mean that 1 is the most relevant - motivation and 2 is less relevant.) +Below you will find a question that we ultimately want to answer (the original question) and a list of +motivations in arbitrary order for generated sub-questions that are supposed to help us answering the +original question. The motivations are formatted as : . +(Again, the numbering is arbitrary and does not necessarily mean that 1 is the most relevant +motivation and 2 is less relevant.) - Please rank the motivations in order of relevance for answering the original question. Also, try to - ensure that the top questions do not duplicate too much, i.e. that they are not too similar. - Ultimately, create a list with the motivation numbers where the number of the most relevant - motivation comes first. +Please rank the motivations in order of relevance for answering the original question. Also, try to +ensure that the top questions do not duplicate too much, i.e. that they are not too similar. +Ultimately, create a list with the motivation numbers where the number of the most relevant +motivation comes first. - Here is the original question: - \n\n {original_question} \n\n - \n\n Here is the list of sub-question motivations: - \n\n {sub_question_explanations} \n\n - ---------------- +Here is the original question: +\n -------\n +{original_question} +\n -------\n - Please think step by step and then generate the ranked list of motivations. +Here is the list of sub-question motivations: +\n -------\n +{sub_question_explanations} +\n -------\n - Please format your answer as a json object in the following format: - {{"reasonning": , - "ranked_motivations": }} - """ +Please think step by step and then generate the ranked list of motivations. + +Please format your answer as a json object in the following format: +{{"reasonning": , + "ranked_motivations": }} +""" INITIAL_DECOMPOSITION_PROMPT_QUESTIONS = """ @@ -554,9 +589,9 @@ answer the original question. The purpose for this decomposition may be to If you think that a decomposition is not needed or helpful, please just return an empty string. That is ok too. Here is the initial question: -------- +\n -------\n {question} -------- +\n -------\n {history} Please formulate your answer as a newline-separated list of questions like so: @@ -566,6 +601,7 @@ Please formulate your answer as a newline-separated list of questions like so: Answer:""" + INITIAL_DECOMPOSITION_PROMPT_QUESTIONS_AFTER_SEARCH = """ If you think it is helpful, please decompose an initial user question into no more than 3 appropriate sub-questions that help to answer the original question. The purpose for this decomposition may be to @@ -589,14 +625,14 @@ disambiguations are most important! 2) If you think that a decomposition is not needed or helpful, please just return an empty string. That is very much ok too. Here are the sample docs to give you some context: -------- +\n -------\n {sample_doc_str} -------- +\n -------\n And here is the initial question that you should think about decomposing: -------- +\n -------\n {question} -------- +\n -------\n {history} @@ -608,32 +644,34 @@ Please formulate your answer as a newline-separated list of questions like so: Answer:""" + INITIAL_DECOMPOSITION_PROMPT = """ \n - Please decompose an initial user question into 2 or 3 appropriate sub-questions that help to - answer the original question. The purpose for this decomposition is to isolate individual entities - (i.e., 'compare sales of company A and company B' -> 'what are sales for company A' + 'what are sales - for company B'), split ambiguous terms (i.e., 'what is our success with company A' -> 'what are our - sales with company A' + 'what is our market share with company A' + 'is company A a reference customer - for us'), etc. Each sub-question should realistically be answerable by a good RAG system. \n +Please decompose an initial user question into 2 or 3 appropriate sub-questions that help to +answer the original question. The purpose for this decomposition is to isolate individual entities +(i.e., 'compare sales of company A and company B' -> 'what are sales for company A' + 'what are sales +for company B'), split ambiguous terms (i.e., 'what is our success with company A' -> 'what are our +sales with company A' + 'what is our market share with company A' + 'is company A a reference customer +for us'), etc. Each sub-question should realistically be answerable by a good RAG system. \n - For each sub-question, please also create one search term that can be used to retrieve relevant - documents from a document store. +For each sub-question, please also create one search term that can be used to retrieve relevant +documents from a document store. - Here is the initial question: - \n ------- \n - {question} - \n ------- \n +Here is the initial question: +\n-------\n +{question} +\n-------\n - Please formulate your answer as a list of json objects with the following format: +Please formulate your answer as a list of json objects with the following format: - [{{"sub_question": , "search_term": }}, ...] +[{{"sub_question": , "search_term": }}, ...] + +Answer: +""" - Answer: - """ INITIAL_RAG_BASE_PROMPT = ( """ \n - You are an assistant for question-answering tasks. Use the information provided below - and only the +You are an assistant for question-answering tasks. Use the information provided below - and only the provided information - to answer the provided question. The information provided below consists ofa number of documents that were deemed relevant for the question. @@ -649,11 +687,12 @@ You may give some additional facts you learned, but do not try to invent an answ Try to keep your answer concise. Here is the contextual information from the document store: -\n ------- \n +\n -------\n {context} \n\n\n -\n ------- \n +\n -------\n And here is the question I want you to answer based on the context above (with the motivation in mind): -\n--\n {question} \n--\n +\n -------\n +{question} \n-------\n Answer:""" ) @@ -673,9 +712,9 @@ the 'LLM' option. {history} Here is the initial question: -------- +\n -------\n {question} -------- +\n -------\n Please decide whether to use the agent search or the LLM to answer the question. Choose from two choices, 'research' or 'LLM'. @@ -698,14 +737,14 @@ you know the answer/can handle the request, you should choose the 'LLM' option. {history} Here is the initial question: -------- +\n -------\n {question} -------- +\n -------\n Here is the sample of documents that were retrieved from a document store: -------- +\n -------\n {sample_doc_str} -------- +\n -------\n Please decide whether to use the agent search ('research') or the LLM to answer the question. Choose from two choices, 'research' or 'LLM'. @@ -720,24 +759,42 @@ You are an assistant for question-answering tasks.""" ASSISTANT_SYSTEM_PROMPT_PERSONA = """ You are an assistant for question-answering tasks. Here is more information about you: -\n ------- \n +\n-------\n {persona_prompt} -\n ------- \n +\n-------\n """ -SUB_QUESTION_ANSWER_TEMPLATE = """ - Sub-Question: Q{sub_question_nr}\n Sub-Question:\n - \n{sub_question}\n --\nAnswer:\n -\n {sub_answer}\n\n - """ +SUB_QUESTION_ANSWER_TEMPLATE = """\n +Sub-Question: Q{sub_question_nr}\n Sub-Question:\n - \n{sub_question}\n --\nAnswer:\n -\n {sub_answer}\n\n +""" -SUB_QUESTION_ANSWER_TEMPLATE_REVISED = """ - Sub-Question: Q{sub_question_nr}\n Type: {level_type}\n Sub-Question:\n +SUB_QUESTION_ANSWER_TEMPLATE_REVISED = """\n +Sub-Question: Q{sub_question_nr}\n +Type: +\n----\n +{sub_question_type} +\n----\n +Sub-Question: +\n----\n +{sub_question} +\n----\n +\nAnswer: +\n----\n +{sub_answer} +\n----\n +\n +""" + + +SUB_QUESTION_ANSWER_TEMPLATE_REVISED = """\n +Sub-Question: Q{sub_question_nr}\n Type: {sub_question_type}\n Sub-Question:\n - \n{sub_question}\n --\nAnswer:\n -\n {sub_answer}\n\n """ -SUB_QUESTION_SEARCH_RESULTS_TEMPLATE = """ - Sub-Question: Q{sub_question_nr}\n Sub-Question:\n - \n{sub_question}\n --\nRelevant Documents:\n - -\n {formatted_sub_question_docs}\n\n - """ +SUB_QUESTION_SEARCH_RESULTS_TEMPLATE = """\n +Sub-Question: Q{sub_question_nr}\n Sub-Question:\n - \n{sub_question}\n --\nRelevant Documents:\n +-\n {formatted_sub_question_docs}\n\n +""" INITIAL_RAG_PROMPT_SUB_QUESTION_SEARCH = ( """ \n @@ -770,8 +827,10 @@ Try to keep your answer concise. But also highlight uncertainties you may have s or assumptions you made. Here is the contextual information: -\n-------\n +--------------- + *Answered Sub-questions (these should really help to organize your thoughts): +\n-------\n {answered_sub_questions} And here are relevant document information that supports the sub-question answers, or that are relevant for the actual question:\n @@ -781,9 +840,9 @@ And here are relevant document information that supports the sub-question answer \n-------\n \n And here is the main question I want you to answer based on the information above: -\n--\n +\n-------\n {question} -\n--\n\n +\n-------\n\n Answer:""" ) @@ -792,9 +851,9 @@ DIRECT_LLM_PROMPT = """ \n {persona_specification} Please answer the following question/address the request: -\n--\n +\n-------\n {question} -\n--\n\n +\n-------\n\n Answer:""" INITIAL_RAG_PROMPT = ( @@ -804,8 +863,7 @@ INITIAL_RAG_PROMPT = ( Use the information provided below - and only the provided information - to answer the provided main question. The information provided below consists of: - 1) a number of answered sub-questions - these are very important to help you organize your thoughts and your -answer + 1) a number of answered sub-questions - these are very important to help you organize your thoughts and your answer 2) a number of documents that deemed relevant for the question. {history} @@ -832,20 +890,22 @@ Try to keep your answer concise. But also highlight uncertainties you may have s or assumptions you made. Here is the contextual information: -\n-------\n +--------------- + *Answered Sub-questions (these should really matter!): +\n-------\n {answered_sub_questions} +\n-------\n And here are relevant document information that support the sub-question answers, or that are relevant for the actual question:\n - -{relevant_docs} - \n-------\n -\n +{relevant_docs} +\n-------\n + And here is the question I want you to answer based on the information above: -\n--\n +\n-------\n {question} -\n--\n\n +\n-------\n\n Please keep your answer brief and concise, and focus on facts and data. @@ -854,7 +914,8 @@ Answer:""" # sub_question_answer_str is empty INITIAL_RAG_PROMPT_NO_SUB_QUESTIONS = ( - """{answered_sub_questions} + """\n +{answered_sub_questions} {persona_specification} {date_prompt} @@ -885,9 +946,9 @@ Here are is the relevant context information: \n-------\n And here is the question I want you to answer based on the context above -\n--\n +\n-------\n {question} -\n--\n +\n-------\n Please keep your answer brief and concise, and focus on facts and data. @@ -904,11 +965,11 @@ Use the information provided below - and only the provided information - to writ The information provided below consists of: 1) an initial answer that was given but found to be lacking in some way. - 2) a number of answered sub-questions - these are very important(!) and definitely should help you to answer -the main question. Note that the sub-questions have a type, 'initial' and 'revised'. The 'initial' -ones were available for the initial answer, and the 'revised' were not, they are new. So please use -the 'revised' sub-questions in particular to update/extend/correct the initial answer! +the main question. Note that the sub-questions have a type, 'initial' and 'refined'. The 'initial' +ones were available for the creation of the initial answer, but the 'refined' were not, they are new. So please use +the 'refined' sub-questions in particular to update/extend/correct/enrich the initial answer and to add +more details/new facts! 3) a number of documents that were deemed relevant for the question. This the is the context that you use largely for citations (see below). So consider the answers to the sub-questions as guidelines to construct your new answer, but @@ -942,25 +1003,27 @@ Try to keep your answer concise. But also highlight uncertainties you may have s or assumptions you made. Here is the contextual information: -\n-------\n +--------------- *Initial Answer that was found to be lacking: +\n-------\n {initial_answer} +\n-------\n *Answered Sub-questions (these should really help you to research your answer! They also contain questions/answers that were not available when the original answer was constructed): {answered_sub_questions} And here are the relevant documents that support the sub-question answers, and that are relevant for the actual question:\n - -{relevant_docs} - \n-------\n +{relevant_docs} +\n-------\n + \n Lastly, here is the main question I want you to answer based on the information above: -\n--\n +\n-------\n {question} -\n--\n\n +\n-------\n Please keep your answer brief and concise, and focus on facts and data. @@ -969,7 +1032,8 @@ Answer:""" # sub_question_answer_str is empty REVISED_RAG_PROMPT_NO_SUB_QUESTIONS = ( - """{answered_sub_questions}\n + """\n +{answered_sub_questions}\n {persona_specification} {date_prompt} Use the information provided below - and only the @@ -982,9 +1046,9 @@ The information provided below consists of: It is critical that you provide proper] inline citations to documents in the format [[D1]](), [[D2]](), [[D3]](), etc! It is important that the citation is close to the information it supports. If you have multiple citations, please cite for example as [[D1]]()[[D3]](), or [[D2]]()[[D4]](), etc. Citations are very important for the user!\n\n - +\n-------\n {history} - +\n-------\n IMPORTANT RULES: - If you cannot reliably answer the question solely using the provided information, say that you cannot reliably answer. You may give some additional facts you learned, but do not try to invent an answer. @@ -1000,21 +1064,22 @@ Try to keep your answer concise. But also highlight uncertainties you may have s or assumptions you made. Here is the contextual information: -\n-------\n +--------------- *Initial Answer that was found to be lacking: +\n-------\n {initial_answer} +\n-------\n And here are relevant document information that support the sub-question answers, or that are relevant for the actual question:\n - +\n-------\n {relevant_docs} - \n-------\n \n Lastly, here is the question I want you to answer based on the information above: -\n--\n +\n-------\n {question} -\n--\n\n +\n-------\n\n Please keep your answer brief and concise, and focus on facts and data. Answer:""" @@ -1056,53 +1121,57 @@ Please format your answer as a json object in the following format: }} }} + """ ANSWER_COMPARISON_PROMPT = """ For the given question, please compare the initial answer and the refined answer and determine if -the refined answer is substantially better than the initial answer. Better could mean: +the refined answer is substantially better than the initial answer, not just a bit better. Better could mean: - additional information - more comprehensive information - more concise information - more structured information + - morde details - new bullet points - substantially more document citations ([[D1]](), [[D2]](), [[D3]](), etc.) Put yourself in the shoes of the user and think about whether the refined answer is really substantially - better than the initial answer. + better and delivers really new insights than the initial answer. Here is the question: --- +\n-------\n {question} --- +\n-------\n Here is the initial answer: --- +\n-------\n {initial_answer} --- +\n-------\n Here is the refined answer: --- +\n-------\n {refined_answer} --- +\n-------\n With these criteria in mind, is the refined answer substantially better than the initial answer? Please answer with a simple 'yes' or 'no'. """ + + HISTORY_CONTEXT_SUMMARY_PROMPT = """\n {persona_specification} -You need to summarize the key parts of the history of a conversation between a user and an agent -strictly for the purposed of providing the suitable context for a question. - -Here is the question: -\n--\n +You need to summarize the key parts of the history of a conversation between a user and an agent. The +summary has two purposes: + 1) providing the suitable context for a new question, and + 2) To capture the key information that was discussed and that the user may have a follow-up question about. +\n-------\n {question} -\n--\n +\n-------\n And here is the history: -\n--\n +\n-------\n {history} -\n--\n +\n-------\n Please provide a summarized context from the history so that the question makes sense and can - with suitable extra information - be answered.