~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
feat: add Focused Iteration - Standard strategy with adaptive search
LearningCircuit6dbba9bcfcf5
diff --git a/src/local_deep_research/advanced_search_system/questions/browsecomp_question.py b/src/local_deep_research/advanced_search_system/questions/browsecomp_question.pyindex 367cd51eab..d4bd30c29d 100644--- a/src/local_deep_research/advanced_search_system/questions/browsecomp_question.py+++ b/src/local_deep_research/advanced_search_system/questions/browsecomp_question.py@@ -32,6 +32,7 @@ class BrowseCompQuestionGenerator(BaseQuestionGenerator):query: str,questions_per_iteration: int = 5,questions_by_iteration: dict = None,+ results_by_iteration: dict = None,iteration: int = 1,) -> List[str]:"""Generate progressive search queries for BrowseComp problems."""@@ -50,6 +51,7 @@ class BrowseCompQuestionGenerator(BaseQuestionGenerator):current_knowledge,self.extracted_entities,questions_by_iteration,+ results_by_iteration or {},questions_per_iteration,iteration,)@@ -203,13 +205,36 @@ DESCRIPTORS: [entity1], [entity2], ...current_knowledge: str,entities: Dict[str, List[str]],questions_by_iteration: dict,+ results_by_iteration: dict,num_questions: int,iteration: int,) -> List[str]:"""Generate progressively more specific searches based on findings."""+ # Check if recent searches are failing (returning 0 results)+ recent_iterations = [i for i in range(max(1, iteration - 5), iteration)]+ zero_count = sum(+ 1 for i in recent_iterations if results_by_iteration.get(i, 1) == 0+ )+ searches_failing = zero_count >= 3++ # Adjust strategy based on success/failure+ if searches_failing:+ strategy_instruction = """+IMPORTANT: Your recent searches are returning 0 results - they are TOO NARROW!+- Use FEWER constraints (1-2 terms instead of 4-5)+- Try BROADER, more general searches+- Remove overly specific combinations+- Focus on key concepts, not detailed entity combinations+"""+ else:+ strategy_instruction = """+Focus on finding the specific answer by combining entities systematically.+"""+# Analyze what we've found so farprompt = f"""Based on our search progress, generate targeted follow-up searches.+{strategy_instruction}Original Query: {query}@@ -220,10 +245,10 @@ Entities Found:- Key Features: {", ".join(entities["descriptors"][:3])}Current Knowledge Summary:-{current_knowledge[:1500]}+{current_knowledge}Previous Searches:-{self._format_previous_searches(questions_by_iteration)}+{self._format_previous_searches(questions_by_iteration, results_by_iteration)}Generate {num_questions} NEW search queries that:1. Combine 2-3 entities we haven't tried together@@ -291,15 +316,21 @@ Format: One search per linereturn searches[:num_questions]- def _format_previous_searches(self, questions_by_iteration: dict) -> str:- """Format previous searches for context."""+ def _format_previous_searches(+ self, questions_by_iteration: dict, results_by_iteration: dict+ ) -> str:+ """Format previous searches for context with result counts."""formatted = []for iteration, questions in questions_by_iteration.items():if isinstance(questions, list):- formatted.extend(- [f"Iteration {iteration}: {q}" for q in questions[:3]]- )- return "\n".join(formatted[-10:]) # Last 10 searches+ result_count = results_by_iteration.get(iteration, "?")+ for q in questions:+ formatted.append(+ f"Iteration {iteration}: {q} ({result_count} results)"+ )+ return "\n".join(+ formatted+ ) # Show all previous searches to avoid duplicatesdef _was_searched(self, term: str, questions_by_iteration: dict) -> bool:"""Check if a term was already searched."""diff --git a/src/local_deep_research/advanced_search_system/questions/flexible_browsecomp_question.py b/src/local_deep_research/advanced_search_system/questions/flexible_browsecomp_question.pynew file mode 100644index 0000000000..58a964c9d2--- /dev/null+++ b/src/local_deep_research/advanced_search_system/questions/flexible_browsecomp_question.py@@ -0,0 +1,101 @@+"""+Flexible BrowseComp question generator with less prescriptive instructions.++Inherits from BrowseComp but gives the LLM more freedom in search strategy.+"""++from typing import Dict, List++from .browsecomp_question import BrowseCompQuestionGenerator+++class FlexibleBrowseCompQuestionGenerator(BrowseCompQuestionGenerator):+ """+ BrowseComp variant with simplified, less prescriptive prompts.++ Gives the LLM more freedom to explore different search strategies+ instead of strict entity-combination rules.+ """++ def _generate_progressive_searches(+ self,+ query: str,+ current_knowledge: str,+ entities: Dict[str, List[str]],+ questions_by_iteration: dict,+ results_by_iteration: dict,+ num_questions: int,+ iteration: int,+ ) -> List[str]:+ """Generate searches with more freedom and less rigid instructions."""++ # Check if recent searches are failing+ recent_iterations = [i for i in range(max(1, iteration - 5), iteration)]+ zero_count = sum(+ 1 for i in recent_iterations if results_by_iteration.get(i, 1) == 0+ )+ searches_failing = zero_count >= 3++ # Simpler strategy hint+ if searches_failing:+ hint = "Recent searches returned 0 results. Try broader, simpler queries."+ else:+ hint = "Continue exploring to answer the query."++ # Much simpler prompt - less prescriptive+ prompt = f"""Generate {num_questions} new search queries for: {query}++{hint}++Available terms: {", ".join(entities["names"] + entities["temporal"] + entities["descriptors"])}++Previous searches with results:+{self._format_previous_searches(questions_by_iteration, results_by_iteration)}++Current findings:+{current_knowledge}++Create {num_questions} diverse search queries. Avoid exact duplicates. One per line.+"""++ response = self.model.invoke(prompt)+ content = (+ response.content if hasattr(response, "content") else str(response)+ )++ # Extract searches+ searches = []+ for line in content.strip().split("\n"):+ line = line.strip()+ if line and not line.endswith(":") and len(line) > 5:+ for prefix in [+ "Q:",+ "Search:",+ "-",+ "*",+ "•",+ "1.",+ "2.",+ "3.",+ "4.",+ "5.",+ ]:+ if line.startswith(prefix):+ line = line[len(prefix) :].strip()+ if line:+ searches.append(line)++ # If not enough, fall back to parent's logic+ if len(searches) < num_questions:+ parent_searches = super()._generate_progressive_searches(+ query,+ current_knowledge,+ entities,+ questions_by_iteration,+ results_by_iteration,+ num_questions - len(searches),+ iteration,+ )+ searches.extend(parent_searches)++ return searches[:num_questions]diff --git a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.pyindex 14d39925cc..c28e1acc8f 100644--- a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py@@ -108,6 +108,8 @@ class FocusedIterationStrategy(BaseSearchStrategy):# Track all search resultsself.all_search_results = []# Note: questions_by_iteration is already initialized by parent class+ # Track result counts per iteration for question generator feedback+ self.results_by_iteration = {}def analyze_topic(self, query: str) -> Dict:"""@@ -156,6 +158,7 @@ class FocusedIterationStrategy(BaseSearchStrategy):query=query,questions_per_iteration=self.questions_per_iteration,questions_by_iteration=self.questions_by_iteration,+ results_by_iteration=self.results_by_iteration,iteration=iteration,)@@ -268,6 +271,9 @@ class FocusedIterationStrategy(BaseSearchStrategy):self.all_search_results.extend(iteration_results)self.all_links_of_system.extend(iteration_results)+ # Track result count for this iteration+ self.results_by_iteration[iteration] = len(iteration_results)+# Update progressself._update_progress(f"Completed iteration {iteration} - {len(iteration_results)} results",@@ -283,15 +289,20 @@ class FocusedIterationStrategy(BaseSearchStrategy):finding = {"phase": f"Iteration {iteration}","content": f"Searched with {len(questions)} questions, found {len(iteration_results)} results.",- "question": query,+ "question": questions[0]+ if len(questions) == 1+ else "\n".join(questions)+ if questions+ else query,"documents": [],}findings.append(finding)+ # TODO: Early termination temporarily disabled for testing - may need to re-enable# Early termination check for BrowseComp- if self._should_terminate_early(iteration):- logger.info(f"Early termination at iteration {iteration}")- break+ # if self._should_terminate_early(iteration):+ # logger.info(f"Early termination at iteration {iteration}")+ # break# Final synthesis (like source-based - trust the LLM!)self._update_progress(@@ -301,11 +312,12 @@ class FocusedIterationStrategy(BaseSearchStrategy):)# Use citation handler for final synthesis+ # Note: nr_of_links=0 ensures citations start at [1]final_result = self.citation_handler.analyze_followup(query,self.all_search_results,previous_knowledge="",- nr_of_links=len(self.all_links_of_system),+ nr_of_links=0,)synthesized_content = final_result.get(@@ -514,13 +526,13 @@ class FocusedIterationStrategy(BaseSearchStrategy):if not self.all_search_results:return ""- # Simple summary of top results+ # Summary of all results (no limits)summary_parts = []- for i, result in enumerate(self.all_search_results[:10]):+ for i, result in enumerate(self.all_search_results):title = result.get("title", "")snippet = result.get("snippet", "")if title or snippet:- summary_parts.append(f"{i + 1}. {title}: {snippet[:200]}...")+ summary_parts.append(f"{i + 1}. {title}: {snippet}")return "\n".join(summary_parts)diff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.pyindex ccdf70b63c..687238d5bc 100644--- a/src/local_deep_research/search_system_factory.py+++ b/src/local_deep_research/search_system_factory.py@@ -74,6 +74,40 @@ def create_strategy(settings_snapshot=settings_snapshot,)+ # Focused iteration strategy with standard citation handler+ elif strategy_name_lower in [+ "focused-iteration-standard",+ "focused_iteration_standard",+ ]:+ from .advanced_search_system.strategies.focused_iteration_strategy import (+ FocusedIterationStrategy,+ )+ from .citation_handler import CitationHandler+ from .advanced_search_system.questions.flexible_browsecomp_question import (+ FlexibleBrowseCompQuestionGenerator,+ )++ # Use standard citation handler and flexible question generator+ standard_citation_handler = CitationHandler(+ model, handler_type="standard", settings_snapshot=settings_snapshot+ )+ flexible_question_gen = FlexibleBrowseCompQuestionGenerator(model)++ strategy = FocusedIterationStrategy(+ model=model,+ search=search,+ citation_handler=standard_citation_handler,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 8),+ questions_per_iteration=kwargs.get("questions_per_iteration", 5),+ use_browsecomp_optimization=True, # Keep BrowseComp features+ settings_snapshot=settings_snapshot,+ )+ # Override with flexible question generator+ strategy.question_generator = flexible_question_gen++ return strategy+# Multi-source strategyelif strategy_name_lower in ["multi-source",diff --git a/src/local_deep_research/web/templates/pages/research.html b/src/local_deep_research/web/templates/pages/research.htmlindex 09c7faea76..204a04a9ed 100644--- a/src/local_deep_research/web/templates/pages/research.html+++ b/src/local_deep_research/web/templates/pages/research.html@@ -149,6 +149,7 @@<select id="strategy" name="strategy" class="ldr-form-control"><option value="source-based" {% if settings.search_strategy == 'source-based' %}selected{% endif %}>Source-Based (~70% SimpleQA, Comprehensive Research & Text Creation)</option><option value="focused-iteration" {% if settings.search_strategy == 'focused-iteration' %}selected{% endif %}>Focused Iteration (~95% SimpleQA, Fast & Precise Q&A)</option>+ <option value="focused-iteration-standard" {% if settings.search_strategy == 'focused-iteration-standard' %}selected{% endif %}>Focused Iteration - Standard (Standard citation handler, allows "information not found")</option><option value="iterative-refinement" {% if settings.search_strategy == 'iterative-refinement' %}selected{% endif %}>Iterative Refinement (LLM-guided progressive refinement)</option><option value="topic-organization" {% if settings.search_strategy == 'topic-organization' %}selected{% endif %}>Topic Organization (Clusters sources into topics with lead texts)</option></select>