~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
refactor: Create factory pattern for strategy creation
LearningCircuit222e08881282
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.pyindex c21144ef9c..beb423e6cf 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@@ -326,10 +326,15 @@ Please address this specific request using the context and findings above.return []# Filter sources using the relevance filter+ # Get max sources from settings or use default+ max_followup_sources = self.settings_snapshot.get(+ "search.max_followup_sources", {}+ ).get("value", 15)+relevant = self.relevance_filter.filter_results(results=past_sources,query=query,- max_results=15, # Keep more sources for follow-up+ max_results=max_followup_sources,threshold=0.3,past_findings=self.full_context.get("past_findings", ""),original_query=self.full_context.get("original_query", ""),@@ -383,17 +388,18 @@ Please address this specific request using the context and findings above.f"Injected {injected_count} relevant past sources into delegate strategy")- # Also pass context through settings if delegate supports it- if (- hasattr(self.delegate_strategy, "settings_snapshot")- and self.delegate_strategy.settings_snapshot- ):- self.delegate_strategy.settings_snapshot["followup_context"] = {- "reformulated_query": reformulated_query,- "past_findings_summary": self.full_context.get("summary", ""),- "key_entities": self.full_context.get("key_entities", []),- "sources_injected": injected_count,- }+ # Pass context to delegate if it supports it+ if hasattr(self.delegate_strategy, "set_followup_context"):+ self.delegate_strategy.set_followup_context(+ {+ "reformulated_query": reformulated_query,+ "past_findings_summary": self.full_context.get(+ "summary", ""+ ),+ "key_entities": self.full_context.get("key_entities", []),+ "sources_injected": injected_count,+ }+ )def set_progress_callback(self, callback):"""diff --git a/src/local_deep_research/followup_research/routes.py b/src/local_deep_research/followup_research/routes.pyindex becfd83840..763820273e 100644--- a/src/local_deep_research/followup_research/routes.py+++ b/src/local_deep_research/followup_research/routes.py@@ -206,11 +206,6 @@ def start_followup():"question": data.get("question"),"strategy": "contextual-followup",},- "system": {- "timestamp": created_at,- "user": username,- "version": "1.0",- },}research = ResearchHistory(@@ -231,12 +226,8 @@ def start_followup():# Start the research process using the existing infrastructure# Use quick_summary mode for follow-ups by defaultlogger.info(- f"About to start research with query: {research_params['query']} (type: {type(research_params['query'])})"+ f"Starting follow-up research for query of type: {type(research_params.get('query'))}")- logger.info(f"Settings snapshot type: {type(settings_snapshot)}")- logger.info(- f"Settings snapshot keys: {list(settings_snapshot.keys())[:5] if settings_snapshot else 'None'}"- ) # First 5 keys# Get user password for metrics database accessuser_password = Nonediff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.pyindex 61cab67aed..05fdeb1bc3 100644--- a/src/local_deep_research/search_system.py+++ b/src/local_deep_research/search_system.py@@ -8,48 +8,6 @@ from .advanced_search_system.findings.repository import FindingsRepositoryfrom .advanced_search_system.questions.standard_question import (StandardQuestionGenerator,)-from .advanced_search_system.strategies.adaptive_decomposition_strategy import (- AdaptiveDecompositionStrategy,-)-from .advanced_search_system.strategies.browsecomp_optimized_strategy import (- BrowseCompOptimizedStrategy,-)-from .advanced_search_system.strategies.constrained_search_strategy import (- ConstrainedSearchStrategy,-)-from .advanced_search_system.strategies.early_stop_constrained_strategy import (- EarlyStopConstrainedStrategy,-)-from .advanced_search_system.strategies.evidence_based_strategy_v2 import (- EnhancedEvidenceBasedStrategy,-)-from .advanced_search_system.strategies.iterative_reasoning_strategy import (- IterativeReasoningStrategy,-)-from .advanced_search_system.strategies.iterdrag_strategy import (- IterDRAGStrategy,-)-from .advanced_search_system.strategies.parallel_constrained_strategy import (- ParallelConstrainedStrategy,-)-from .advanced_search_system.strategies.parallel_search_strategy import (- ParallelSearchStrategy,-)-from .advanced_search_system.strategies.rapid_search_strategy import (- RapidSearchStrategy,-)-from .advanced_search_system.strategies.recursive_decomposition_strategy import (- RecursiveDecompositionStrategy,-)-from .advanced_search_system.strategies.smart_decomposition_strategy import (- SmartDecompositionStrategy,-)-from .advanced_search_system.strategies.source_based_strategy import (- SourceBasedSearchStrategy,-)-from .advanced_search_system.strategies.news_strategy import (- NewsAggregationStrategy,-)from .advanced_search_system.strategies.followup.enhanced_contextual_followup import (EnhancedContextualFollowUpStrategy,)@@ -181,380 +139,11 @@ class AdvancedSearchSystem:self.progress_callback = lambda _1, _2, _3: Noneself.all_links_of_system = list()- # Initialize strategy based on name- if strategy_name.lower() == "iterdrag":- logger.info("Creating IterDRAGStrategy instance")- self.strategy = IterDRAGStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in ["source-based", "source_based"]:- logger.info("Creating SourceBasedSearchStrategy instance")- self.strategy = SourceBasedSearchStrategy(- model=self.model,- search=self.search,- include_text_content=include_text_content,- use_cross_engine_filter=use_cross_engine_filter,- all_links_of_system=self.all_links_of_system,- use_atomic_facts=use_atomic_facts,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "parallel":- logger.info("Creating ParallelSearchStrategy instance")- self.strategy = ParallelSearchStrategy(- model=self.model,- search=self.search,- include_text_content=include_text_content,- use_cross_engine_filter=use_cross_engine_filter,- all_links_of_system=self.all_links_of_system,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "rapid":- logger.info("Creating RapidSearchStrategy instance")- self.strategy = RapidSearchStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- settings_snapshot=self.settings_snapshot,- )- elif (- strategy_name.lower() == "recursive"- or strategy_name.lower() == "recursive-decomposition"- ):- logger.info("Creating RecursiveDecompositionStrategy instance")- self.strategy = RecursiveDecompositionStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "iterative":- logger.info("Creating IterativeReasoningStrategy instance")- # For iterative reasoning, use more iterations to allow thorough exploration- # while keeping search iterations separate- self.strategy = IterativeReasoningStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20, # Increased reasoning iterations- confidence_threshold=0.95, # Increased from 0.85 to require very high confidence- search_iterations_per_round=self.max_iterations- or 1, # Search iterations from settings- questions_per_search=self.questions_per_iteration,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "adaptive":- logger.info("Creating AdaptiveDecompositionStrategy instance")- self.strategy = AdaptiveDecompositionStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_steps=self.max_iterations,- min_confidence=0.8,- source_search_iterations=2,- source_questions_per_iteration=self.questions_per_iteration,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "smart":- logger.info("Creating SmartDecompositionStrategy instance")- self.strategy = SmartDecompositionStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=self.max_iterations,- source_search_iterations=2,- source_questions_per_iteration=self.questions_per_iteration,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "browsecomp":- logger.info("Creating BrowseCompOptimizedStrategy instance")- self.strategy = BrowseCompOptimizedStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_browsecomp_iterations=15, # BrowseComp strategy main iterations- confidence_threshold=0.9,- max_iterations=self.max_iterations, # Source-based sub-searches- questions_per_iteration=self.questions_per_iteration, # Source-based sub-searches- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "evidence":- logger.info("Creating EnhancedEvidenceBasedStrategy instance")- self.strategy = EnhancedEvidenceBasedStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20, # Main evidence-gathering iterations- confidence_threshold=0.95, # Increased from 0.85 to require very high confidence- candidate_limit=20, # Increased from 10- evidence_threshold=0.9, # Increased from 0.6 to require strong evidence- max_search_iterations=self.max_iterations, # Source-based sub-searches- questions_per_iteration=self.questions_per_iteration,- min_candidates_threshold=10, # Increased from 3- enable_pattern_learning=True,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() == "constrained":- logger.info("Creating ConstrainedSearchStrategy instance")- self.strategy = ConstrainedSearchStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95, # Increased from 0.85 to require very high confidence- candidate_limit=100, # Increased from 30- evidence_threshold=0.9, # Increased from 0.6 to require strong evidence- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20, # Increased from 5- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "parallel-constrained",- "parallel_constrained",- ]:- logger.info("Creating ParallelConstrainedStrategy instance")- self.strategy = ParallelConstrainedStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95, # Increased from 0.85 to require very high confidence- candidate_limit=100,- evidence_threshold=0.9, # Increased from 0.6 to require strong evidence- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20, # Correct parameter name for parent class- parallel_workers=100, # Run up to 100 searches in parallel- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "early-stop-constrained",- "early_stop_constrained",- ]:- logger.info("Creating EarlyStopConstrainedStrategy instance")- self.strategy = EarlyStopConstrainedStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95,- candidate_limit=100,- evidence_threshold=0.9,- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20,- parallel_workers=100, # Increased parallelism as requested- early_stop_threshold=0.99, # Stop when we find 99%+ confidence- concurrent_evaluation=True, # Evaluate candidates as we find them- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in ["smart-query", "smart_query"]:- from .advanced_search_system.strategies.smart_query_strategy import (- SmartQueryStrategy,- )-- logger.info("Creating SmartQueryStrategy instance")- self.strategy = SmartQueryStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95,- candidate_limit=100,- evidence_threshold=0.9,- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20,- parallel_workers=100, # High parallelism- early_stop_threshold=0.99, # Stop when we find 99%+ confidence- concurrent_evaluation=True, # Evaluate candidates as we find them- use_llm_query_generation=True, # Use smart query generation- queries_per_combination=3, # Generate multiple queries- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in ["dual-confidence", "dual_confidence"]:- from .advanced_search_system.strategies.dual_confidence_strategy import (- DualConfidenceStrategy,- )-- logger.info("Creating DualConfidenceStrategy instance")- self.strategy = DualConfidenceStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95,- candidate_limit=100,- evidence_threshold=0.9,- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20,- parallel_workers=100,- early_stop_threshold=0.95, # Lower threshold since dual confidence is more accurate- concurrent_evaluation=True,- use_llm_query_generation=True,- queries_per_combination=3,- use_entity_seeding=True,- use_direct_property_search=True,- uncertainty_penalty=0.2, # Penalty for uncertain evidence- negative_weight=0.5, # How much negative evidence counts against- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "dual-confidence-with-rejection",- "dual_confidence_with_rejection",- ]:- from .advanced_search_system.strategies.dual_confidence_with_rejection import (- DualConfidenceWithRejectionStrategy,- )-- logger.info("Creating DualConfidenceWithRejectionStrategy instance")- self.strategy = DualConfidenceWithRejectionStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95,- candidate_limit=100,- evidence_threshold=0.9,- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20,- parallel_workers=100,- early_stop_threshold=0.95,- concurrent_evaluation=True,- use_llm_query_generation=True,- queries_per_combination=3,- use_entity_seeding=True,- use_direct_property_search=True,- uncertainty_penalty=0.2,- negative_weight=0.5,- rejection_threshold=0.3, # Reject if negative confidence > 30%- positive_threshold=0.2, # Unless positive confidence > 20%- critical_constraint_rejection=0.2, # Stricter for critical constraints- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "concurrent-dual-confidence",- "concurrent_dual_confidence",- ]:- from .advanced_search_system.strategies.concurrent_dual_confidence_strategy import (- ConcurrentDualConfidenceStrategy,- )-- logger.info("Creating ConcurrentDualConfidenceStrategy instance")- self.strategy = ConcurrentDualConfidenceStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=20,- confidence_threshold=0.95,- candidate_limit=100,- evidence_threshold=0.9,- max_search_iterations=self.max_iterations,- questions_per_iteration=self.questions_per_iteration,- min_candidates_per_stage=20,- parallel_workers=10, # Concurrent evaluation threads- early_stop_threshold=0.95,- concurrent_evaluation=True,- use_llm_query_generation=True,- queries_per_combination=3,- use_entity_seeding=True,- use_direct_property_search=True,- uncertainty_penalty=0.2,- negative_weight=0.5,- rejection_threshold=0.3,- positive_threshold=0.2,- critical_constraint_rejection=0.2,- # Concurrent-specific parameters- min_good_candidates=3,- target_candidates=5,- max_candidates=10,- min_score_threshold=0.65,- exceptional_score=0.95,- quality_plateau_threshold=0.1,- max_search_time=30.0,- max_evaluations=30,- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in ["modular", "modular-strategy"]:- from .advanced_search_system.strategies.modular_strategy import (- ModularStrategy,- )+ # Initialize strategy using factory+ from .search_system_factory import create_strategy- logger.info("Creating ModularStrategy instance")- self.strategy = ModularStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- constraint_checker_type="dual_confidence", # dual_confidence, strict, threshold- exploration_strategy="adaptive", # parallel, adaptive, constraint_guided, diversity- early_rejection=True, # Enable fast pre-screening- early_stopping=True, # Enable early stopping- llm_constraint_processing=True, # Enable LLM-driven constraint processing- immediate_evaluation=True, # Enable immediate candidate evaluation- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in ["modular-parallel", "modular_parallel"]:- from .advanced_search_system.strategies.modular_strategy import (- ModularStrategy,- )-- logger.info(- "Creating ModularStrategy with parallel exploration and dual confidence"- )- self.strategy = ModularStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- constraint_checker_type="dual_confidence", # Concurrent evaluation with +/-/? scoring- exploration_strategy="parallel", # Parallel constraint searches- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "focused-iteration",- "focused_iteration",- ]:- from .advanced_search_system.strategies.focused_iteration_strategy import (- FocusedIterationStrategy,- )-- logger.info("Creating FocusedIterationStrategy instance")- # Use database settings for iterations and questions_per_iteration- self.strategy = FocusedIterationStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- max_iterations=self.max_iterations, # Use database setting- questions_per_iteration=self.questions_per_iteration, # Use database setting- use_browsecomp_optimization=True, # Enable BrowseComp optimizations for 95% accuracy- settings_snapshot=self.settings_snapshot,- )- elif strategy_name.lower() in [- "browsecomp-entity",- "browsecomp_entity",- ]:- from .advanced_search_system.strategies.browsecomp_entity_strategy import (- BrowseCompEntityStrategy,- )-- logger.info("Creating BrowseCompEntityStrategy instance")- self.strategy = BrowseCompEntityStrategy(- model=self.model,- search=self.search,- all_links_of_system=self.all_links_of_system,- )- elif strategy_name.lower() in [- "news",- "news_aggregation",- "news-aggregation",- ]:- logger.info("Creating NewsAggregationStrategy instance")- self.strategy = NewsAggregationStrategy()- elif strategy_name.lower() in [+ # Special handling for follow-up strategy which needs different logic+ if strategy_name.lower() in ["enhanced-contextual-followup","enhanced_contextual_followup","contextual-followup",@@ -569,109 +158,14 @@ class AdvancedSearchSystem:else "source-based")- # Create the appropriate delegate strategy based on user's selection- if delegate_strategy_name.lower() in [- "source-based",- "source_based",- "source_based_search",- ]:- delegate = SourceBasedSearchStrategy(- model=self.model,- search=self.search,- include_text_content=True,- use_cross_engine_filter=True,- all_links_of_system=[],- use_atomic_facts=False,- settings_snapshot=self.settings_snapshot,- )- elif delegate_strategy_name.lower() in [- "focused-iteration",- "focused_iteration",- ]:- from .advanced_search_system.strategies.focused_iteration_strategy import (- FocusedIterationStrategy,- )-- delegate = FocusedIterationStrategy(- model=self.model,- search=self.search,- all_links_of_system=[],- knowledge_accumulation_mode=True,- settings_snapshot=self.settings_snapshot,- )- elif delegate_strategy_name.lower() in [- "multi-source",- "multi_source",- "multi-source_cross_reference",- ]:- from .advanced_search_system.strategies.multi_source_strategy import (- MultiSourceCrossReferenceStrategy,- )-- delegate = MultiSourceCrossReferenceStrategy(- model=self.model,- search=self.search,- all_links_of_system=[],- knowledge_accumulation_mode=True,- settings_snapshot=self.settings_snapshot,- )- elif delegate_strategy_name.lower() in [- "academic",- "academic_deep_dive",- ]:- from .advanced_search_system.strategies.academic_strategy import (- AcademicDeepDiveStrategy,- )-- delegate = AcademicDeepDiveStrategy(- model=self.model,- search=self.search,- all_links_of_system=[],- knowledge_accumulation_mode=True,- settings_snapshot=self.settings_snapshot,- )- elif delegate_strategy_name.lower() in [- "investigative",- "investigative_journalism",- ]:- from .advanced_search_system.strategies.investigative_strategy import (- InvestigativeJournalismStrategy,- )-- delegate = InvestigativeJournalismStrategy(- model=self.model,- search=self.search,- all_links_of_system=[],- settings_snapshot=self.settings_snapshot,- )- elif delegate_strategy_name.lower() in [- "comprehensive",- "comprehensive_analysis",- ]:- from .advanced_search_system.strategies.comprehensive_strategy import (- ComprehensiveAnalysisStrategy,- )-- delegate = ComprehensiveAnalysisStrategy(- model=self.model,- search=self.search,- all_links_of_system=[],- settings_snapshot=self.settings_snapshot,- )- else:- # Default to source-based if unknown strategy- logger.warning(- f"Unknown delegate strategy: {delegate_strategy_name}, defaulting to source-based"- )- delegate = SourceBasedSearchStrategy(- model=self.model,- search=self.search,- include_text_content=True,- use_cross_engine_filter=True,- all_links_of_system=[],- use_atomic_facts=False,- settings_snapshot=self.settings_snapshot,- )+ delegate = create_strategy(+ strategy_name=delegate_strategy_name,+ model=self.model,+ search=self.search,+ all_links_of_system=[],+ settings_snapshot=self.settings_snapshot,+ knowledge_accumulation_mode=True,+ )# Create the contextual follow-up strategy with the delegateself.strategy = EnhancedContextualFollowUpStrategy(@@ -683,17 +177,30 @@ class AdvancedSearchSystem:research_context=self.research_context,)else:- logger.info("Creating StandardSearchStrategy instance")- # Import lazily to avoid database access during module import- from .advanced_search_system.strategies.standard_strategy import (- StandardSearchStrategy,- )-- self.strategy = StandardSearchStrategy(+ # Use factory for all other strategies+ logger.info(f"Creating {strategy_name} strategy using factory")+ self.strategy = create_strategy(+ strategy_name=strategy_name,model=self.model,search=self.search,all_links_of_system=self.all_links_of_system,settings_snapshot=self.settings_snapshot,+ # Pass strategy-specific parameters+ include_text_content=include_text_content,+ use_cross_engine_filter=use_cross_engine_filter,+ use_atomic_facts=use_atomic_facts,+ max_iterations=self.max_iterations,+ questions_per_iteration=self.questions_per_iteration,+ # Special parameters for iterative strategy+ search_iterations_per_round=self.max_iterations or 1,+ questions_per_search=self.questions_per_iteration,+ # Special parameters for adaptive strategy+ max_steps=self.max_iterations,+ source_questions_per_iteration=self.questions_per_iteration,+ # Special parameters for evidence and constrained strategies+ max_search_iterations=self.max_iterations,+ # Special parameters for focused iteration+ use_browsecomp_optimization=True,)# Log the actual strategy classdiff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.pynew file mode 100644index 0000000000..bd9b25d21b--- /dev/null+++ b/src/local_deep_research/search_system_factory.py@@ -0,0 +1,646 @@+"""+Factory for creating search strategies.+This module provides a centralized way to create search strategies+to avoid code duplication.+"""++from loguru import logger+from typing import Optional, Dict, Any, List+from langchain_core.language_models import BaseChatModel+++def create_strategy(+ strategy_name: str,+ model: BaseChatModel,+ search: Any,+ all_links_of_system: Optional[List[Dict]] = None,+ settings_snapshot: Optional[Dict] = None,+ research_context: Optional[Dict] = None,+ **kwargs,+):+ """+ Create a search strategy by name.++ Args:+ strategy_name: Name of the strategy to create+ model: Language model to use+ search: Search engine instance+ all_links_of_system: List of existing links+ settings_snapshot: Settings snapshot+ research_context: Research context for special strategies+ **kwargs: Additional strategy-specific parameters++ Returns:+ Strategy instance+ """+ if all_links_of_system is None:+ all_links_of_system = []++ strategy_name_lower = strategy_name.lower()++ # Source-based strategy+ if strategy_name_lower in [+ "source-based",+ "source_based",+ "source_based_search",+ ]:+ from .advanced_search_system.strategies.source_based_strategy import (+ SourceBasedSearchStrategy,+ )++ return SourceBasedSearchStrategy(+ model=model,+ search=search,+ include_text_content=kwargs.get("include_text_content", True),+ use_cross_engine_filter=kwargs.get("use_cross_engine_filter", True),+ all_links_of_system=all_links_of_system,+ use_atomic_facts=kwargs.get("use_atomic_facts", False),+ settings_snapshot=settings_snapshot,+ )++ # Focused iteration strategy+ elif strategy_name_lower in ["focused-iteration", "focused_iteration"]:+ from .advanced_search_system.strategies.focused_iteration_strategy import (+ FocusedIterationStrategy,+ )++ return FocusedIterationStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ knowledge_accumulation_mode=kwargs.get(+ "knowledge_accumulation_mode", True+ ),+ settings_snapshot=settings_snapshot,+ )++ # Multi-source strategy+ elif strategy_name_lower in [+ "multi-source",+ "multi_source",+ "multi-source_cross_reference",+ ]:+ from .advanced_search_system.strategies.multi_source_strategy import (+ MultiSourceCrossReferenceStrategy,+ )++ return MultiSourceCrossReferenceStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ knowledge_accumulation_mode=kwargs.get(+ "knowledge_accumulation_mode", True+ ),+ settings_snapshot=settings_snapshot,+ )++ # Academic strategy+ elif strategy_name_lower in ["academic", "academic_deep_dive"]:+ from .advanced_search_system.strategies.academic_strategy import (+ AcademicDeepDiveStrategy,+ )++ return AcademicDeepDiveStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ knowledge_accumulation_mode=kwargs.get(+ "knowledge_accumulation_mode", True+ ),+ settings_snapshot=settings_snapshot,+ )++ # Investigative strategy+ elif strategy_name_lower in ["investigative", "investigative_journalism"]:+ from .advanced_search_system.strategies.investigative_strategy import (+ InvestigativeJournalismStrategy,+ )++ return InvestigativeJournalismStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Comprehensive strategy+ elif strategy_name_lower in ["comprehensive", "comprehensive_analysis"]:+ from .advanced_search_system.strategies.comprehensive_strategy import (+ ComprehensiveAnalysisStrategy,+ )++ return ComprehensiveAnalysisStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Adaptive strategy+ elif strategy_name_lower in ["adaptive", "adaptive_research"]:+ from .advanced_search_system.strategies.adaptive_strategy import (+ AdaptiveResearchStrategy,+ )++ return AdaptiveResearchStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ knowledge_accumulation_mode=kwargs.get(+ "knowledge_accumulation_mode", True+ ),+ initial_strategy=kwargs.get("initial_strategy", "source-based"),+ max_strategy_switches=kwargs.get("max_strategy_switches", 2),+ settings_snapshot=settings_snapshot,+ )++ # Iterative reasoning strategy+ elif strategy_name_lower in [+ "iterative-reasoning",+ "iterative_reasoning",+ "iterative_reasoning_depth",+ ]:+ from .advanced_search_system.strategies.iterative_reasoning_strategy import (+ IterativeReasoningDepthStrategy,+ )++ return IterativeReasoningDepthStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ use_atomic_facts=kwargs.get("use_atomic_facts", True),+ settings_snapshot=settings_snapshot,+ )++ # News aggregation strategy+ elif strategy_name_lower in [+ "news",+ "news_aggregation",+ "news-aggregation",+ ]:+ from .advanced_search_system.strategies.news_strategy import (+ NewsAggregationStrategy,+ )++ return NewsAggregationStrategy()++ # IterDRAG strategy+ elif strategy_name_lower == "iterdrag":+ from .advanced_search_system.strategies.iterdrag_strategy import (+ IterDRAGStrategy,+ )++ return IterDRAGStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Parallel strategy+ elif strategy_name_lower == "parallel":+ from .advanced_search_system.strategies.parallel_search_strategy import (+ ParallelSearchStrategy,+ )++ return ParallelSearchStrategy(+ model=model,+ search=search,+ include_text_content=kwargs.get("include_text_content", True),+ use_cross_engine_filter=kwargs.get("use_cross_engine_filter", True),+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Rapid strategy+ elif strategy_name_lower == "rapid":+ from .advanced_search_system.strategies.rapid_search_strategy import (+ RapidSearchStrategy,+ )++ return RapidSearchStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Recursive decomposition strategy+ elif strategy_name_lower in ["recursive", "recursive-decomposition"]:+ from .advanced_search_system.strategies.recursive_decomposition_strategy import (+ RecursiveDecompositionStrategy,+ )++ return RecursiveDecompositionStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ # Iterative reasoning strategy (different from iterative_reasoning_depth)+ elif strategy_name_lower == "iterative":+ from .advanced_search_system.strategies.iterative_reasoning_strategy import (+ IterativeReasoningStrategy,+ )++ # Get iteration settings from kwargs or use defaults+ max_iterations = kwargs.get("max_iterations", 20)+ questions_per_iteration = kwargs.get("questions_per_iteration", 3)+ search_iterations_per_round = kwargs.get(+ "search_iterations_per_round", 1+ )++ return IterativeReasoningStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=max_iterations,+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ search_iterations_per_round=search_iterations_per_round,+ questions_per_search=questions_per_iteration,+ settings_snapshot=settings_snapshot,+ )++ # Adaptive decomposition strategy (different from adaptive_research)+ elif strategy_name_lower == "adaptive":+ from .advanced_search_system.strategies.adaptive_decomposition_strategy import (+ AdaptiveDecompositionStrategy,+ )++ return AdaptiveDecompositionStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_steps=kwargs.get("max_steps", kwargs.get("max_iterations", 5)),+ min_confidence=kwargs.get("min_confidence", 0.8),+ source_search_iterations=kwargs.get("source_search_iterations", 2),+ source_questions_per_iteration=kwargs.get(+ "source_questions_per_iteration",+ kwargs.get("questions_per_iteration", 3),+ ),+ settings_snapshot=settings_snapshot,+ )++ # Smart decomposition strategy+ elif strategy_name_lower == "smart":+ from .advanced_search_system.strategies.smart_decomposition_strategy import (+ SmartDecompositionStrategy,+ )++ return SmartDecompositionStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 5),+ source_search_iterations=kwargs.get("source_search_iterations", 2),+ source_questions_per_iteration=kwargs.get(+ "source_questions_per_iteration",+ kwargs.get("questions_per_iteration", 3),+ ),+ settings_snapshot=settings_snapshot,+ )++ # BrowseComp optimized strategy+ elif strategy_name_lower == "browsecomp":+ from .advanced_search_system.strategies.browsecomp_optimized_strategy import (+ BrowseCompOptimizedStrategy,+ )++ return BrowseCompOptimizedStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_browsecomp_iterations=kwargs.get(+ "max_browsecomp_iterations", 15+ ),+ confidence_threshold=kwargs.get("confidence_threshold", 0.9),+ max_iterations=kwargs.get("max_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ settings_snapshot=settings_snapshot,+ )++ # Enhanced evidence-based strategy+ elif strategy_name_lower == "evidence":+ from .advanced_search_system.strategies.evidence_based_strategy_v2 import (+ EnhancedEvidenceBasedStrategy,+ )++ return EnhancedEvidenceBasedStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 20),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_threshold=kwargs.get("min_candidates_threshold", 10),+ enable_pattern_learning=kwargs.get("enable_pattern_learning", True),+ settings_snapshot=settings_snapshot,+ )++ # Constrained search strategy+ elif strategy_name_lower == "constrained":+ from .advanced_search_system.strategies.constrained_search_strategy import (+ ConstrainedSearchStrategy,+ )++ return ConstrainedSearchStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ settings_snapshot=settings_snapshot,+ )++ # Parallel constrained strategy+ elif strategy_name_lower in [+ "parallel-constrained",+ "parallel_constrained",+ ]:+ from .advanced_search_system.strategies.parallel_constrained_strategy import (+ ParallelConstrainedStrategy,+ )++ return ParallelConstrainedStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 100),+ settings_snapshot=settings_snapshot,+ )++ # Early stop constrained strategy+ elif strategy_name_lower in [+ "early-stop-constrained",+ "early_stop_constrained",+ ]:+ from .advanced_search_system.strategies.early_stop_constrained_strategy import (+ EarlyStopConstrainedStrategy,+ )++ return EarlyStopConstrainedStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 100),+ early_stop_threshold=kwargs.get("early_stop_threshold", 0.99),+ concurrent_evaluation=kwargs.get("concurrent_evaluation", True),+ settings_snapshot=settings_snapshot,+ )++ # Smart query strategy+ elif strategy_name_lower in ["smart-query", "smart_query"]:+ from .advanced_search_system.strategies.smart_query_strategy import (+ SmartQueryStrategy,+ )++ return SmartQueryStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 100),+ early_stop_threshold=kwargs.get("early_stop_threshold", 0.99),+ concurrent_evaluation=kwargs.get("concurrent_evaluation", True),+ use_llm_query_generation=kwargs.get(+ "use_llm_query_generation", True+ ),+ queries_per_combination=kwargs.get("queries_per_combination", 3),+ settings_snapshot=settings_snapshot,+ )++ # Dual confidence strategy+ elif strategy_name_lower in ["dual-confidence", "dual_confidence"]:+ from .advanced_search_system.strategies.dual_confidence_strategy import (+ DualConfidenceStrategy,+ )++ return DualConfidenceStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 100),+ early_stop_threshold=kwargs.get("early_stop_threshold", 0.95),+ concurrent_evaluation=kwargs.get("concurrent_evaluation", True),+ use_llm_query_generation=kwargs.get(+ "use_llm_query_generation", True+ ),+ queries_per_combination=kwargs.get("queries_per_combination", 3),+ use_entity_seeding=kwargs.get("use_entity_seeding", True),+ use_direct_property_search=kwargs.get(+ "use_direct_property_search", True+ ),+ uncertainty_penalty=kwargs.get("uncertainty_penalty", 0.2),+ negative_weight=kwargs.get("negative_weight", 0.5),+ settings_snapshot=settings_snapshot,+ )++ # Dual confidence with rejection strategy+ elif strategy_name_lower in [+ "dual-confidence-with-rejection",+ "dual_confidence_with_rejection",+ ]:+ from .advanced_search_system.strategies.dual_confidence_with_rejection import (+ DualConfidenceWithRejectionStrategy,+ )++ return DualConfidenceWithRejectionStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 100),+ early_stop_threshold=kwargs.get("early_stop_threshold", 0.95),+ concurrent_evaluation=kwargs.get("concurrent_evaluation", True),+ use_llm_query_generation=kwargs.get(+ "use_llm_query_generation", True+ ),+ queries_per_combination=kwargs.get("queries_per_combination", 3),+ use_entity_seeding=kwargs.get("use_entity_seeding", True),+ use_direct_property_search=kwargs.get(+ "use_direct_property_search", True+ ),+ uncertainty_penalty=kwargs.get("uncertainty_penalty", 0.2),+ negative_weight=kwargs.get("negative_weight", 0.5),+ rejection_threshold=kwargs.get("rejection_threshold", 0.3),+ positive_threshold=kwargs.get("positive_threshold", 0.2),+ critical_constraint_rejection=kwargs.get(+ "critical_constraint_rejection", 0.2+ ),+ settings_snapshot=settings_snapshot,+ )++ # Concurrent dual confidence strategy+ elif strategy_name_lower in [+ "concurrent-dual-confidence",+ "concurrent_dual_confidence",+ ]:+ from .advanced_search_system.strategies.concurrent_dual_confidence_strategy import (+ ConcurrentDualConfidenceStrategy,+ )++ return ConcurrentDualConfidenceStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ max_iterations=kwargs.get("max_iterations", 20),+ confidence_threshold=kwargs.get("confidence_threshold", 0.95),+ candidate_limit=kwargs.get("candidate_limit", 100),+ evidence_threshold=kwargs.get("evidence_threshold", 0.9),+ max_search_iterations=kwargs.get("max_search_iterations", 5),+ questions_per_iteration=kwargs.get("questions_per_iteration", 3),+ min_candidates_per_stage=kwargs.get("min_candidates_per_stage", 20),+ parallel_workers=kwargs.get("parallel_workers", 10),+ early_stop_threshold=kwargs.get("early_stop_threshold", 0.95),+ concurrent_evaluation=kwargs.get("concurrent_evaluation", True),+ use_llm_query_generation=kwargs.get(+ "use_llm_query_generation", True+ ),+ queries_per_combination=kwargs.get("queries_per_combination", 3),+ use_entity_seeding=kwargs.get("use_entity_seeding", True),+ use_direct_property_search=kwargs.get(+ "use_direct_property_search", True+ ),+ uncertainty_penalty=kwargs.get("uncertainty_penalty", 0.2),+ negative_weight=kwargs.get("negative_weight", 0.5),+ rejection_threshold=kwargs.get("rejection_threshold", 0.3),+ positive_threshold=kwargs.get("positive_threshold", 0.2),+ critical_constraint_rejection=kwargs.get(+ "critical_constraint_rejection", 0.2+ ),+ min_good_candidates=kwargs.get("min_good_candidates", 3),+ target_candidates=kwargs.get("target_candidates", 5),+ max_candidates=kwargs.get("max_candidates", 10),+ min_score_threshold=kwargs.get("min_score_threshold", 0.65),+ exceptional_score=kwargs.get("exceptional_score", 0.95),+ quality_plateau_threshold=kwargs.get(+ "quality_plateau_threshold", 0.1+ ),+ max_search_time=kwargs.get("max_search_time", 30.0),+ max_evaluations=kwargs.get("max_evaluations", 30),+ settings_snapshot=settings_snapshot,+ )++ # Modular strategy+ elif strategy_name_lower in ["modular", "modular-strategy"]:+ from .advanced_search_system.strategies.modular_strategy import (+ ModularStrategy,+ )++ return ModularStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ constraint_checker_type=kwargs.get(+ "constraint_checker_type", "dual_confidence"+ ),+ exploration_strategy=kwargs.get("exploration_strategy", "adaptive"),+ early_rejection=kwargs.get("early_rejection", True),+ early_stopping=kwargs.get("early_stopping", True),+ llm_constraint_processing=kwargs.get(+ "llm_constraint_processing", True+ ),+ immediate_evaluation=kwargs.get("immediate_evaluation", True),+ settings_snapshot=settings_snapshot,+ )++ # Modular parallel strategy+ elif strategy_name_lower in ["modular-parallel", "modular_parallel"]:+ from .advanced_search_system.strategies.modular_strategy import (+ ModularStrategy,+ )++ return ModularStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ constraint_checker_type="dual_confidence",+ exploration_strategy="parallel",+ settings_snapshot=settings_snapshot,+ )++ # BrowseComp entity strategy+ elif strategy_name_lower in ["browsecomp-entity", "browsecomp_entity"]:+ from .advanced_search_system.strategies.browsecomp_entity_strategy import (+ BrowseCompEntityStrategy,+ )++ return BrowseCompEntityStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ )++ # Standard strategy+ elif strategy_name_lower == "standard":+ from .advanced_search_system.strategies.standard_strategy import (+ StandardSearchStrategy,+ )++ return StandardSearchStrategy(+ model=model,+ search=search,+ all_links_of_system=all_links_of_system,+ settings_snapshot=settings_snapshot,+ )++ else:+ # Default to source-based if unknown+ logger.warning(+ f"Unknown strategy: {strategy_name}, defaulting to source-based"+ )+ from .advanced_search_system.strategies.source_based_strategy import (+ SourceBasedSearchStrategy,+ )++ return SourceBasedSearchStrategy(+ model=model,+ search=search,+ include_text_content=True,+ use_cross_engine_filter=True,+ all_links_of_system=all_links_of_system,+ use_atomic_facts=False,+ settings_snapshot=settings_snapshot,+ )