Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: Improve follow-up relevance filter with full context

LearningCircuit176f223f069b
diff --git a/src/local_deep_research/advanced_search_system/filters/followup_relevance_filter.py b/src/local_deep_research/advanced_search_system/filters/followup_relevance_filter.py
index 0e064636c0..c0f84273c0 100644
--- a/src/local_deep_research/advanced_search_system/filters/followup_relevance_filter.py
+++ b/src/local_deep_research/advanced_search_system/filters/followup_relevance_filter.py
@@ -32,6 +32,7 @@ class FollowUpRelevanceFilter(BaseFilter):
**kwargs: Additional parameters:
- max_results: Maximum number of results to return
- past_findings: Summary of past findings for context
+ - original_query: The original research query
Returns:
Filtered list of relevant sources
@@ -41,10 +42,11 @@ class FollowUpRelevanceFilter(BaseFilter):
max_results = kwargs.get("max_results", 10)
past_findings = kwargs.get("past_findings", "")
+ original_query = kwargs.get("original_query", "")
# Use LLM to select relevant sources
relevant_indices = self._select_relevant_sources(
- results, query, past_findings, max_results
+ results, query, past_findings, max_results, original_query
)
# Return selected sources
@@ -58,7 +60,12 @@ class FollowUpRelevanceFilter(BaseFilter):
return filtered
def _select_relevant_sources(
- self, sources: List[Dict], query: str, context: str, max_results: int
+ self,
+ sources: List[Dict],
+ query: str,
+ context: str,
+ max_results: int,
+ original_query: str = "",
) -> List[int]:
"""
Select relevant sources using LLM.
@@ -68,6 +75,7 @@ class FollowUpRelevanceFilter(BaseFilter):
query: The follow-up query
context: Past findings context
max_results: Maximum number of sources to select
+ original_query: The original research query
Returns:
List of indices of relevant sources
@@ -90,17 +98,34 @@ class FollowUpRelevanceFilter(BaseFilter):
sources_text = "\n\n".join(source_list)
- prompt = f"""
-Select the most relevant sources for answering this follow-up question.
+ # Include context if available for better selection
+ context_section = ""
+ if context or original_query:
+ parts = []
+ if original_query:
+ parts.append(f"Original research question: {original_query}")
+ if context:
+ parts.append(f"Previous research findings:\n{context}")
+
+ context_section = f"""
+Previous Research Context:
+{chr(10).join(parts)}
+---
+"""
+
+ prompt = f"""
+Select the most relevant sources for answering this follow-up question based on the previous research context.
+{context_section}
Follow-up question: "{query}"
-Available sources:
+Available sources from previous research:
{sources_text}
Instructions:
-- Select up to {max_results} sources that are most relevant to the follow-up question
-- Consider which sources directly address the question or provide essential context
+- Select sources that are most relevant to the follow-up question given the context
+- Consider which sources directly address the question or provide essential information
+- Think about what the user is asking for in relation to the previous findings
- Return ONLY a comma-separated list of source numbers (e.g., "0,2,5,7")
- Do not include any explanation or other text
diff --git a/src/local_deep_research/advanced_search_system/strategies/followup/enhanced_contextual_followup.py b/src/local_deep_research/advanced_search_system/strategies/followup/enhanced_contextual_followup.py
index 4c1500cbf1..c305e875ba 100644
--- a/src/local_deep_research/advanced_search_system/strategies/followup/enhanced_contextual_followup.py
+++ b/src/local_deep_research/advanced_search_system/strategies/followup/enhanced_contextual_followup.py
@@ -332,6 +332,7 @@ Please address this specific request using the context and findings above.
max_results=15, # Keep more sources for follow-up
threshold=0.3,
past_findings=self.full_context.get("past_findings", ""),
+ original_query=self.full_context.get("original_query", ""),
)
logger.info(