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.

refactor: Address code review feedback from bots

LearningCircuit8360ae9602b4
diff --git a/src/local_deep_research/advanced_search_system/strategies/iterative_refinement_strategy.py b/src/local_deep_research/advanced_search_system/strategies/iterative_refinement_strategy.py
index b9eb04f44a..582a238875 100644
--- a/src/local_deep_research/advanced_search_system/strategies/iterative_refinement_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/iterative_refinement_strategy.py
@@ -10,7 +10,7 @@ This strategy orchestrates iterative refinement of research results by:
"""
import json
-from typing import Dict
+from typing import Dict, Optional
from loguru import logger
from .base_strategy import BaseSearchStrategy
@@ -41,6 +41,7 @@ class IterativeRefinementStrategy(BaseSearchStrategy):
evaluation_frequency: int = 1,
max_refinements: int = 3,
confidence_threshold: float = 0.8,
+ max_evaluation_tokens: Optional[int] = None, # None = no truncation
**kwargs,
):
"""
@@ -55,15 +56,27 @@ class IterativeRefinementStrategy(BaseSearchStrategy):
evaluation_frequency: Evaluate after N refinement rounds (1 = every round)
max_refinements: Maximum number of refinement cycles
confidence_threshold: Confidence level to stop refinement (0.0-1.0)
+ max_evaluation_tokens: Maximum tokens for LLM evaluation (None = no truncation)
"""
super().__init__(all_links_of_system, settings_snapshot)
+ # Validate parameters
+ if not 0 <= confidence_threshold <= 1:
+ raise ValueError("confidence_threshold must be between 0 and 1")
+ if max_refinements < 0:
+ raise ValueError("max_refinements must be non-negative")
+ if evaluation_frequency < 1:
+ raise ValueError("evaluation_frequency must be at least 1")
+ if max_evaluation_tokens is not None and max_evaluation_tokens <= 0:
+ raise ValueError("max_evaluation_tokens must be positive or None")
+
self.model = model
self.search = search
self.initial_strategy = initial_strategy
self.evaluation_frequency = evaluation_frequency
self.max_refinements = max_refinements
self.confidence_threshold = confidence_threshold
+ self.max_evaluation_tokens = max_evaluation_tokens
# Track refinement history
self.refinement_history = []
@@ -250,15 +263,14 @@ class IterativeRefinementStrategy(BaseSearchStrategy):
# Re-raise to see the actual error
raise
- # Update accumulated sources
+ # Update accumulated sources (O(1) lookup with set)
+ existing_urls = {s.get("url") for s in all_accumulated_sources}
new_sources = followup_results.get("all_links_of_system", [])
for source in new_sources:
# Check if URL already exists to avoid duplicates
- if not any(
- s.get("url") == source.get("url")
- for s in all_accumulated_sources
- ):
+ if source.get("url") not in existing_urls:
all_accumulated_sources.append(source)
+ existing_urls.add(source.get("url"))
# Update research context for next iteration
research_context = self._build_research_context(results, query)
@@ -400,7 +412,7 @@ Original Research Query: {original_query}
Current Refinement Iteration: {iteration + 1} of {self.max_refinements}
Current Research Findings:
-{findings[:3000]} # Truncate for token limits
+{findings if self.max_evaluation_tokens is None else findings[: self.max_evaluation_tokens]}
Number of sources found: {sources_count}
Previous gaps identified: {", ".join(previous_gaps) if previous_gaps else "None"}