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.

Fix repetitive sections in detailed reports by preserving question history

LearningCircuit2fa7d9097b77
diff --git a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py b/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
index 6a27a72b36..2361327976 100644
--- a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
@@ -12,10 +12,17 @@ from loguru import logger
class BaseSearchStrategy(ABC):
"""Abstract base class for all search strategies."""
- def __init__(self, all_links_of_system=None):
+ def __init__(
+ self,
+ all_links_of_system=None,
+ questions_by_iteration=None,
+ ):
"""Initialize the base strategy with common attributes."""
self.progress_callback = None
- self.questions_by_iteration = {}
+ # Create a new dict if None is provided (avoiding mutable default argument)
+ self.questions_by_iteration = (
+ questions_by_iteration if questions_by_iteration is not None else {}
+ )
# Create a new list if None is provided (avoiding mutable default argument)
self.all_links_of_system = (
all_links_of_system if all_links_of_system is not None else []
diff --git a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
index 38d27de0ef..a70c9b341d 100644
--- a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
@@ -38,11 +38,11 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
"""Initialize with optional dependency injection for testing."""
# Pass the links list to the parent class
super().__init__(all_links_of_system=all_links_of_system)
- self.search = search or get_search()
- self.model = model or get_llm()
- self.progress_callback = None
-
- self.questions_by_iteration = {}
+ # Use provided model and search, or fall back to defaults
+ # Note: If model/search are provided, they should already have the proper context
+ self.model = model if model is not None else get_llm()
+ self.search = search if search is not None else get_search()
+ # Note: progress_callback and questions_by_iteration are already set by parent class
self.include_text_content = include_text_content
self.use_cross_engine_filter = use_cross_engine_filter
self.filter_reorder = filter_reorder
diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.py
index f45fea1b41..076f78d66a 100644
--- a/src/local_deep_research/report_generator.py
+++ b/src/local_deep_research/report_generator.py
@@ -148,6 +148,27 @@ class IntegratedReportGenerator:
"""Research and generate content for each section in one step."""
sections = {}
+ # Preserve questions from initial research to avoid repetition
+ # This follows the same pattern as citation tracking (all_links_of_system)
+ existing_questions = initial_findings.get("questions_by_iteration", {})
+ if existing_questions:
+ # Set questions on both search system and its strategy
+ if hasattr(self.search_system, "questions_by_iteration"):
+ self.search_system.questions_by_iteration = (
+ existing_questions.copy()
+ )
+
+ # More importantly, set it on the strategy which actually uses it
+ if hasattr(self.search_system, "strategy") and hasattr(
+ self.search_system.strategy, "questions_by_iteration"
+ ):
+ self.search_system.strategy.questions_by_iteration = (
+ existing_questions.copy()
+ )
+ logger.info(
+ f"Initialized strategy with {len(existing_questions)} iterations of previous questions"
+ )
+
for section in structure:
logger.info(f"Processing section: {section['name']}")
section_content = []