diff --git a/surfsense_backend/app/agents/researcher/nodes.py b/surfsense_backend/app/agents/researcher/nodes.py index 165efcb..22c70cc 100644 --- a/surfsense_backend/app/agents/researcher/nodes.py +++ b/surfsense_backend/app/agents/researcher/nodes.py @@ -1174,7 +1174,7 @@ async def handle_qna_workflow(state: State, config: RunnableConfig, writer: Stre await connector_service.initialize_counter() # Use the reformulated query as a single research question - research_questions = [reformulated_query] + research_questions = [reformulated_query, user_query] relevant_documents = await fetch_relevant_documents( research_questions=research_questions, @@ -1210,7 +1210,8 @@ async def handle_qna_workflow(state: State, config: RunnableConfig, writer: Stre # Prepare configuration for the QNA agent qna_config = { "configurable": { - "user_query": reformulated_query, # Use the reformulated query + "user_query": user_query, # Use the reformulated query + "reformulated_query": reformulated_query, "relevant_documents": all_documents, # Use combined documents "user_id": configuration.user_id, "search_space_id": configuration.search_space_id diff --git a/surfsense_backend/app/agents/researcher/qna_agent/configuration.py b/surfsense_backend/app/agents/researcher/qna_agent/configuration.py index 6e7ef20..0f3c74d 100644 --- a/surfsense_backend/app/agents/researcher/qna_agent/configuration.py +++ b/surfsense_backend/app/agents/researcher/qna_agent/configuration.py @@ -14,6 +14,7 @@ class Configuration: # Configuration parameters for the Q&A agent user_query: str # The user's question to answer + reformulated_query: str # The reformulated query relevant_documents: List[Any] # Documents provided directly to the agent for answering user_id: str # User identifier search_space_id: int # Search space identifier diff --git a/surfsense_backend/app/agents/researcher/qna_agent/nodes.py b/surfsense_backend/app/agents/researcher/qna_agent/nodes.py index d9575ff..4684290 100644 --- a/surfsense_backend/app/agents/researcher/qna_agent/nodes.py +++ b/surfsense_backend/app/agents/researcher/qna_agent/nodes.py @@ -26,6 +26,7 @@ async def rerank_documents(state: State, config: RunnableConfig) -> Dict[str, An configuration = Configuration.from_runnable_config(config) documents = configuration.relevant_documents user_query = configuration.user_query + reformulated_query = configuration.reformulated_query # If no documents were provided, return empty list if not documents or len(documents) == 0: @@ -57,7 +58,7 @@ async def rerank_documents(state: State, config: RunnableConfig) -> Dict[str, An ] # Rerank documents using the user's query - reranked_docs = reranker_service.rerank_documents(user_query, reranker_input_docs) + reranked_docs = reranker_service.rerank_documents(user_query + "\n" + reformulated_query, reranker_input_docs) # Sort by score in descending order reranked_docs.sort(key=lambda x: x.get("score", 0), reverse=True)