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: add configurable options for focused-iteration strategy

LearningCircuit9af779e063c3
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.py
index 32048cf9e5..0f6cc45c96 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
@@ -60,6 +60,11 @@ class FocusedIterationStrategy(BaseSearchStrategy):
questions_per_iteration: int = 5, # OPTIMAL FOR SIMPLEQA: proven config
use_browsecomp_optimization: bool = True, # True for 90%+ accuracy with forced_answer handler
settings_snapshot=None,
+ # Options to match main branch behavior for testing:
+ enable_adaptive_questions: bool = False, # Pass results_by_iteration to question generator (False=main behavior)
+ enable_early_termination: bool = False, # Allow early stopping when high confidence found
+ knowledge_summary_limit: int = 10, # Limit results in knowledge summary (None=unlimited, 10=main behavior)
+ knowledge_snippet_truncate: int = 200, # Truncate snippets to N chars (None=no truncation, 200=main behavior)
):
"""Initialize with components optimized for focused iteration."""
super().__init__(all_links_of_system, settings_snapshot)
@@ -78,6 +83,12 @@ class FocusedIterationStrategy(BaseSearchStrategy):
)
self.use_browsecomp_optimization = use_browsecomp_optimization
+ # Options to control behavior (for A/B testing main vs dev behavior)
+ self.enable_adaptive_questions = enable_adaptive_questions
+ self.enable_early_termination = enable_early_termination
+ self.knowledge_summary_limit = knowledge_summary_limit
+ self.knowledge_snippet_truncate = knowledge_snippet_truncate
+
logger.info(
f"FocusedIterationStrategy configuration - max_iterations: {self.max_iterations}, questions_per_iteration: {self.questions_per_iteration}"
)
@@ -157,12 +168,16 @@ class FocusedIterationStrategy(BaseSearchStrategy):
# Generate questions for this iteration
if self.use_browsecomp_optimization:
# Use BrowseComp-aware question generation
+ # Only pass results_by_iteration if adaptive questions enabled
+ # (when disabled, LLM won't see result counts or get "too narrow" warnings)
questions = self.question_generator.generate_questions(
current_knowledge=self._get_current_knowledge_summary(),
query=query,
questions_per_iteration=self.questions_per_iteration,
questions_by_iteration=self.questions_by_iteration,
- results_by_iteration=self.results_by_iteration,
+ results_by_iteration=self.results_by_iteration
+ if self.enable_adaptive_questions
+ else None,
iteration=iteration,
)
@@ -257,11 +272,13 @@ class FocusedIterationStrategy(BaseSearchStrategy):
}
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
+ # Early termination check (controlled by enable_early_termination parameter)
+ if (
+ self.enable_early_termination
+ and 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(
@@ -491,12 +508,21 @@ class FocusedIterationStrategy(BaseSearchStrategy):
if not self.all_search_results:
return ""
- # Summary of all results (no limits)
+ # Apply limit if configured (knowledge_summary_limit=10 matches main branch behavior)
+ results_to_summarize = self.all_search_results
+ if self.knowledge_summary_limit is not None:
+ results_to_summarize = self.all_search_results[
+ : self.knowledge_summary_limit
+ ]
+
summary_parts = []
- for i, result in enumerate(self.all_search_results):
+ for i, result in enumerate(results_to_summarize):
title = result.get("title", "")
snippet = result.get("snippet", "")
if title or snippet:
+ # Truncate snippet if configured (200=main behavior, None=no truncation)
+ if self.knowledge_snippet_truncate is not None:
+ snippet = snippet[: self.knowledge_snippet_truncate] + "..."
summary_parts.append(f"{i + 1}. {title}: {snippet}")
return "\n".join(summary_parts)
diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_service.py b/src/local_deep_research/benchmarks/web_api/benchmark_service.py
index 90a870823b..a7104a75d7 100644
--- a/src/local_deep_research/benchmarks/web_api/benchmark_service.py
+++ b/src/local_deep_research/benchmarks/web_api/benchmark_service.py
@@ -1016,8 +1016,11 @@ class BenchmarkService:
)
benchmark_run.error_message = info.get("error_message")
- # Save all results
- for result in run_data.get("results", []):
+ # Save all results (skip already saved ones)
+ saved_indices = run_data.get("saved_indices", set())
+ for idx, result in enumerate(run_data.get("results", [])):
+ if idx in saved_indices:
+ continue
benchmark_result = BenchmarkResult(
benchmark_run_id=benchmark_run_id,
example_id=result["example_id"],
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index b3c554c67e..f46c0f6ec5 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -740,6 +740,65 @@
"value": 3,
"visible": true
},
+ "search.enable_adaptive_questions": {
+ "category": "search_parameters",
+ "description": "When enabled, the question generator adapts based on search result counts (tells LLM when searches return 0 results). Disable for main-branch-like behavior.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Adaptive Question Generation",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "boolean",
+ "value": false,
+ "visible": true
+ },
+ "search.knowledge_summary_limit": {
+ "category": "search_parameters",
+ "description": "Maximum number of search results to show LLM when generating follow-up questions. Set to 0 for unlimited. Does not affect final synthesis (which always sees all results).",
+ "editable": true,
+ "max_value": 100,
+ "min_value": 0,
+ "name": "Knowledge Summary Limit",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "number",
+ "value": 10,
+ "visible": true
+ },
+ "search.knowledge_snippet_truncate": {
+ "category": "search_parameters",
+ "description": "Maximum characters per snippet when showing results to LLM for question generation. Set to 0 for no truncation.",
+ "editable": true,
+ "max_value": 1000,
+ "min_value": 0,
+ "name": "Snippet Truncation Length",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "number",
+ "value": 200,
+ "visible": true
+ },
+ "search.question_generator": {
+ "category": "search_parameters",
+ "description": "Question generator for focused-iteration strategies. 'browsecomp' uses structured entity extraction, 'flexible' gives LLM more freedom.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Question Generator",
+ "options": [
+ "browsecomp",
+ "flexible"
+ ],
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "select",
+ "value": "browsecomp",
+ "visible": true
+ },
"search.search_strategy": {
"category": "search_parameters",
"description": "Search strategy to use for research",
diff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.py
index 687238d5bc..ebd48a17c3 100644
--- a/src/local_deep_research/search_system_factory.py
+++ b/src/local_deep_research/search_system_factory.py
@@ -9,6 +9,19 @@ from typing import Optional, Dict, Any, List
from langchain_core.language_models import BaseChatModel
+def _get_setting(
+ settings_snapshot: Optional[Dict], key: str, default: Any
+) -> Any:
+ """Get a setting value from the snapshot, handling nested dict structure."""
+ if not settings_snapshot or key not in settings_snapshot:
+ return default
+ value = settings_snapshot[key]
+ # Extract value from dict structure if needed
+ if isinstance(value, dict) and "value" in value:
+ return value["value"]
+ return value
+
+
def create_strategy(
strategy_name: str,
model: BaseChatModel,
@@ -65,15 +78,65 @@ def create_strategy(
FocusedIterationStrategy,
)
- return FocusedIterationStrategy(
+ # Read settings with kwargs override
+ enable_adaptive = kwargs.get(
+ "enable_adaptive_questions",
+ _get_setting(
+ settings_snapshot, "search.enable_adaptive_questions", False
+ ),
+ )
+ knowledge_limit = kwargs.get(
+ "knowledge_summary_limit",
+ _get_setting(
+ settings_snapshot, "search.knowledge_summary_limit", 10
+ ),
+ )
+ snippet_truncate = kwargs.get(
+ "knowledge_snippet_truncate",
+ _get_setting(
+ settings_snapshot, "search.knowledge_snippet_truncate", 200
+ ),
+ )
+ question_gen_type = kwargs.get(
+ "question_generator",
+ _get_setting(
+ settings_snapshot, "search.question_generator", "browsecomp"
+ ),
+ )
+ # Convert 0 to None for "unlimited"
+ if knowledge_limit == 0:
+ knowledge_limit = None
+ if snippet_truncate == 0:
+ snippet_truncate = None
+
+ strategy = FocusedIterationStrategy(
model=model,
search=search,
all_links_of_system=all_links_of_system,
max_iterations=kwargs.get("max_iterations", 8),
questions_per_iteration=kwargs.get("questions_per_iteration", 5),
settings_snapshot=settings_snapshot,
+ # Options read from settings (with kwargs override)
+ enable_adaptive_questions=enable_adaptive,
+ enable_early_termination=kwargs.get(
+ "enable_early_termination", False
+ ),
+ knowledge_summary_limit=knowledge_limit,
+ knowledge_snippet_truncate=snippet_truncate,
)
+ # Override question generator if flexible is selected
+ if question_gen_type == "flexible":
+ from .advanced_search_system.questions.flexible_browsecomp_question import (
+ FlexibleBrowseCompQuestionGenerator,
+ )
+
+ strategy.question_generator = FlexibleBrowseCompQuestionGenerator(
+ model
+ )
+
+ return strategy
+
# Focused iteration strategy with standard citation handler
elif strategy_name_lower in [
"focused-iteration-standard",
@@ -83,15 +146,42 @@ def create_strategy(
FocusedIterationStrategy,
)
from .citation_handler import CitationHandler
- from .advanced_search_system.questions.flexible_browsecomp_question import (
- FlexibleBrowseCompQuestionGenerator,
- )
- # Use standard citation handler and flexible question generator
+ # Use standard citation handler (same question generator as regular focused-iteration)
standard_citation_handler = CitationHandler(
model, handler_type="standard", settings_snapshot=settings_snapshot
)
- flexible_question_gen = FlexibleBrowseCompQuestionGenerator(model)
+
+ # Read settings with kwargs override
+ enable_adaptive = kwargs.get(
+ "enable_adaptive_questions",
+ _get_setting(
+ settings_snapshot, "search.enable_adaptive_questions", False
+ ),
+ )
+ knowledge_limit = kwargs.get(
+ "knowledge_summary_limit",
+ _get_setting(
+ settings_snapshot, "search.knowledge_summary_limit", 10
+ ),
+ )
+ snippet_truncate = kwargs.get(
+ "knowledge_snippet_truncate",
+ _get_setting(
+ settings_snapshot, "search.knowledge_snippet_truncate", 200
+ ),
+ )
+ question_gen_type = kwargs.get(
+ "question_generator",
+ _get_setting(
+ settings_snapshot, "search.question_generator", "browsecomp"
+ ),
+ )
+ # Convert 0 to None for "unlimited"
+ if knowledge_limit == 0:
+ knowledge_limit = None
+ if snippet_truncate == 0:
+ snippet_truncate = None
strategy = FocusedIterationStrategy(
model=model,
@@ -102,9 +192,24 @@ def create_strategy(
questions_per_iteration=kwargs.get("questions_per_iteration", 5),
use_browsecomp_optimization=True, # Keep BrowseComp features
settings_snapshot=settings_snapshot,
+ # Options read from settings (with kwargs override)
+ enable_adaptive_questions=enable_adaptive,
+ enable_early_termination=kwargs.get(
+ "enable_early_termination", False
+ ),
+ knowledge_summary_limit=knowledge_limit,
+ knowledge_snippet_truncate=snippet_truncate,
)
- # Override with flexible question generator
- strategy.question_generator = flexible_question_gen
+
+ # Override question generator if flexible is selected
+ if question_gen_type == "flexible":
+ from .advanced_search_system.questions.flexible_browsecomp_question import (
+ FlexibleBrowseCompQuestionGenerator,
+ )
+
+ strategy.question_generator = FlexibleBrowseCompQuestionGenerator(
+ model
+ )
return strategy