~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: unify search strategy definitions into single source of truth (#3298)
LearningCircuitc0b058d303d0
diff --git a/src/local_deep_research/constants.py b/src/local_deep_research/constants.pyindex 5ab8803743..449d6f6469 100644--- a/src/local_deep_research/constants.py+++ b/src/local_deep_research/constants.py@@ -1,6 +1,7 @@"""Project-wide constants for Local Deep Research."""from enum import StrEnum+from typing import Dict, Listfrom .__version__ import __version__@@ -88,3 +89,49 @@ RESEARCH_HISTORY_COLLECTION_DESCRIPTION = ("your previous research. Used by the History page search when in ""AI or Hybrid mode.")++# --- Available search strategies (UI-facing) ---+# Single source of truth for strategies shown in all UI dropdowns.+# create_strategy() in search_system_factory.py handles additional names+# (aliases, internal strategies) — this list is purely for the UI.+AVAILABLE_STRATEGIES: List[Dict[str, str]] = [+ {+ "name": "source-based",+ "label": "Source-Based (Best for small <16,000 context window)",+ "description": "Comprehensive research with inline citations. Focuses on finding and extracting information from authoritative sources.",+ },+ {+ "name": "focused-iteration",+ "label": "Focused Iteration - Quick (Minimal text output)",+ "description": "Fast & precise Q&A with iterative search. Good for complex queries requiring specific answers.",+ },+ {+ "name": "focused-iteration-standard",+ "label": "Focused Iteration - Comprehensive (Needs >16,000 context window)",+ "description": "Detailed long-form output with citations. Uses standard citation handler for comprehensive answers.",+ },+ {+ "name": "iterative-refinement",+ "label": "Iterative Refinement (Progressive refinement)",+ "description": "LLM-guided progressive refinement. Iteratively refines results using evaluation and follow-up queries.",+ },+ {+ "name": "topic-organization",+ "label": "Topic Organization (Clusters by topic)",+ "description": "Clusters sources into topics with lead texts. Organizes research by themes for structured output.",+ },+ {+ "name": "mcp",+ "label": "MCP ReAct (Agentic research - LLM decides tools)",+ "description": "Agentic research using ReAct pattern. LLM decides what tools to call, analyzes results, and iterates.",+ },+]+++def get_available_strategies() -> List[Dict[str, str]]:+ """Get the list of available research strategies.++ Returns:+ List of dictionaries with 'name', 'label', and 'description' keys.+ """+ return AVAILABLE_STRATEGIES.copy()diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.jsonindex d9bc16564d..1460dde30c 100644--- a/src/local_deep_research/defaults/default_settings.json+++ b/src/local_deep_research/defaults/default_settings.json@@ -977,14 +977,7 @@"max_value": null,"min_value": null,"name": "Search Strategy",- "options": [- "source-based",- "focused-iteration",- "focused-iteration-standard",- "iterative-refinement",- "topic-organization",- "mcp"- ],+ "options": null,"step": null,"type": "SEARCH","ui_element": "select",diff --git a/src/local_deep_research/news/web.py b/src/local_deep_research/news/web.pyindex 29e23be496..71721c3f73 100644--- a/src/local_deep_research/news/web.py+++ b/src/local_deep_research/news/web.py@@ -4,6 +4,8 @@ Flask blueprint for news system web routes.from flask import Blueprint, jsonify, render_templatefrom loguru import logger++from ..constants import get_available_strategiesfrom . import api# get_db_setting not available in merged codebase - will use defaults@@ -28,20 +30,9 @@ def create_news_blueprint():@bp.route("/")def news_page():"""Render the main news page."""- # Get available strategies for dropdown- strategies = [- "topic_based",- "news_aggregation",- "source_based",- "focused_iteration",- ]-- default_strategy = "topic_based" # Default strategy-return render_template("pages/news.html",- strategies=strategies,- default_strategy=default_strategy,+ strategies=get_available_strategies(),)@bp.route("/subscriptions")@@ -81,6 +72,7 @@ def create_news_blueprint():"pages/news-subscription-form.html",subscription=None,default_settings=default_settings,+ strategies=get_available_strategies(),)@bp.route("/subscriptions/<subscription_id>/edit")@@ -117,6 +109,7 @@ def create_news_blueprint():subscription=None,error="Subscription not found",default_settings=default_settings,+ strategies=get_available_strategies(),)# Load user's default settings if logged in@@ -136,12 +129,14 @@ def create_news_blueprint():subscription=None,error="Error loading subscription",default_settings=default_settings,+ strategies=get_available_strategies(),)return render_template("pages/news-subscription-form.html",subscription=subscription,default_settings=default_settings,+ strategies=get_available_strategies(),)# Health checkdiff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.pyindex 91250bdb34..c564bd2f14 100644--- a/src/local_deep_research/search_system_factory.py+++ b/src/local_deep_research/search_system_factory.py@@ -8,99 +8,8 @@ from loguru import loggerfrom typing import Optional, Dict, Any, Listfrom langchain_core.language_models import BaseChatModel--# =============================================================================-# Strategy Registry - Single Source of Truth-# =============================================================================--AVAILABLE_STRATEGIES: List[Dict[str, str]] = [- {- "name": "source-based",- "description": "Comprehensive research with inline citations. Focuses on finding and extracting information from authoritative sources. Good for general research.",- },- {- "name": "focused-iteration",- "description": "Fast & precise Q&A with iterative search. Good for complex queries requiring specific answers.",- },- {- "name": "focused-iteration-standard",- "description": "Detailed long-form output with citations. Uses standard citation handler for comprehensive answers.",- },- {- "name": "iterative-refinement",- "description": "LLM-guided progressive refinement. Iteratively refines results using evaluation and follow-up queries.",- },- {- "name": "topic-organization",- "description": "Clusters sources into topics with lead texts. Organizes research by themes for structured output.",- },- {- "name": "mcp",- "description": "Agentic research using ReAct pattern (Reasoning + Acting). LLM decides what tools to call, analyzes results, and iterates until satisfied.",- },- {- "name": "rapid",- "description": "Quick single-pass search for fast results. Good for simple queries.",- },- {- "name": "iterative",- "description": "Loop-based reasoning with persistent knowledge accumulation and confidence tracking.",- },- {- "name": "parallel",- "description": "Runs multiple search queries in parallel for comprehensive coverage.",- },- {- "name": "recursive",- "description": "Recursive decomposition of complex queries into simpler sub-queries.",- },- {- "name": "adaptive",- "description": "Adaptive step-by-step reasoning that adjusts strategy based on results.",- },- {- "name": "smart",- "description": "Smart decomposition with automatic sub-query generation.",- },- {- "name": "browsecomp",- "description": "BrowseComp optimized strategy with confidence-based iteration.",- },- {- "name": "evidence",- "description": "Enhanced evidence-based verification with candidate discovery and pattern learning.",- },- {- "name": "constrained",- "description": "Progressive constraint-based search that narrows candidates step by step.",- },- {- "name": "news",- "description": "Specialized for news aggregation and current events.",- },- {- "name": "standard",- "description": "Basic iterative search strategy for general use.",- },- {- "name": "iterdrag",- "description": "IterDRAG strategy for iterative document retrieval and generation.",- },- {- "name": "iterative-reasoning",- "description": "Iterative reasoning with depth-based exploration.",- },-]---def get_available_strategies() -> List[Dict[str, str]]:- """- Get the list of available research strategies.-- Returns:- List of dictionaries with 'name' and 'description' keys for each strategy.- """- return AVAILABLE_STRATEGIES.copy()+# Re-export from constants so existing importers don't break+from .constants import AVAILABLE_STRATEGIES, get_available_strategies # noqa: F401def _get_setting(diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.pyindex 76add0ac55..63bfd413f7 100644--- a/src/local_deep_research/settings/manager.py+++ b/src/local_deep_research/settings/manager.py@@ -424,6 +424,15 @@ class SettingsManager(ISettingsManager):# Theme registry not available, use static options from JSONpass+ # Inject search strategy options from code (single source of truth)+ if "search.search_strategy" in settings:+ from local_deep_research.constants import AVAILABLE_STRATEGIES++ settings["search.search_strategy"]["options"] = [+ {"label": s["label"], "value": s["name"]}+ for s in AVAILABLE_STRATEGIES+ ]+logger.debug(f"Loaded {len(settings)} total settings")return settingsdiff --git a/src/local_deep_research/web/app_factory.py b/src/local_deep_research/web/app_factory.pyindex 377fa03892..82016af315 100644--- a/src/local_deep_research/web/app_factory.py+++ b/src/local_deep_research/web/app_factory.py@@ -670,6 +670,7 @@ def register_blueprints(app):"""Root route - redirect to login if not authenticated"""from flask import redirect, session, url_for+ from ..constants import get_available_strategiesfrom ..database.session_context import get_user_db_sessionfrom ..utilities.db_utils import get_settings_managerfrom .utils.templates import render_template_with_defaults@@ -719,7 +720,9 @@ def register_blueprints(app):log_settings(settings, "Research page settings loaded")return render_template_with_defaults(- "pages/research.html", settings=settings+ "pages/research.html",+ settings=settings,+ strategies=get_available_strategies(),)# Register auth blueprint FIRST (so login page is accessible)diff --git a/src/local_deep_research/web/routes/metrics_routes.py b/src/local_deep_research/web/routes/metrics_routes.pyindex 6ebbff223e..ec9b52c7d7 100644--- a/src/local_deep_research/web/routes/metrics_routes.py+++ b/src/local_deep_research/web/routes/metrics_routes.py@@ -18,6 +18,7 @@ from ...database.models import (ResearchStrategy,TokenUsage,)+from ...constants import get_available_strategiesfrom ...domain_classifier import DomainClassifier, DomainClassificationfrom ...database.session_context import get_user_db_sessionfrom ...metrics import TokenCounter@@ -435,92 +436,6 @@ def get_link_analytics(period="30d", username=None):}-def get_available_strategies():- """Get list of all available search strategies from the search system."""- # This list comes from the AdvancedSearchSystem.__init__ method- return [- {"name": "standard", "description": "Basic iterative search strategy"},- {- "name": "iterdrag",- "description": "Iterative Dense Retrieval Augmented Generation",- },- {- "name": "source-based",- "description": "Focuses on finding and extracting from sources",- },- {- "name": "parallel",- "description": "Runs multiple search queries in parallel",- },- {"name": "rapid", "description": "Quick single-pass search"},- {- "name": "recursive",- "description": "Recursive decomposition of complex queries",- },- {- "name": "iterative",- "description": "Loop-based reasoning with persistent knowledge",- },- {"name": "adaptive", "description": "Adaptive step-by-step reasoning"},- {- "name": "smart",- "description": "Automatically chooses best strategy based on query",- },- {- "name": "browsecomp",- "description": "Optimized for BrowseComp-style puzzle queries",- },- {- "name": "evidence",- "description": "Enhanced evidence-based verification with improved candidate discovery",- },- {- "name": "constrained",- "description": "Progressive constraint-based search that narrows candidates step by step",- },- {- "name": "parallel-constrained",- "description": "Parallel constraint-based search with combined constraint execution",- },- {- "name": "early-stop-constrained",- "description": "Parallel constraint search with immediate evaluation and early stopping at 99% confidence",- },- {- "name": "smart-query",- "description": "Smart query generation strategy",- },- {- "name": "dual-confidence",- "description": "Dual confidence scoring with positive/negative/uncertainty",- },- {- "name": "dual-confidence-with-rejection",- "description": "Dual confidence with early rejection of poor candidates",- },- {- "name": "concurrent-dual-confidence",- "description": "Concurrent search & evaluation with progressive constraint relaxation",- },- {- "name": "modular",- "description": "Modular architecture using constraint checking and candidate exploration modules",- },- {- "name": "modular-parallel",- "description": "Modular strategy with parallel exploration",- },- {- "name": "focused-iteration",- "description": "Focused iteration strategy optimized for accuracy",- },- {- "name": "browsecomp-entity",- "description": "Entity-focused search for BrowseComp questions with knowledge graph building",- },- ]--def get_strategy_analytics(period="30d", username=None):"""Get strategy usage analytics for the specified period."""try:diff --git a/src/local_deep_research/web/templates/pages/news-subscription-form.html b/src/local_deep_research/web/templates/pages/news-subscription-form.htmlindex ef4fd34078..098128da89 100644--- a/src/local_deep_research/web/templates/pages/news-subscription-form.html+++ b/src/local_deep_research/web/templates/pages/news-subscription-form.html@@ -132,9 +132,9 @@<div class="mb-3"><label for="subscription-strategy" class="ldr-form-label">Search Strategy</label><select class="form-select" id="subscription-strategy">- <option value="source-based" {% if (subscription and subscription.search_strategy == 'source-based') or (not subscription and default_settings.search_strategy == 'source-based') %}selected{% endif %}>Source Based (Comprehensive research)</option>- <option value="focused-iteration" {% if (subscription and subscription.search_strategy == 'focused-iteration') or (not subscription and default_settings.search_strategy == 'focused-iteration') %}selected{% endif %}>Focused Iteration - Quick (Fast Q&A)</option>- <option value="iterative-refinement" {% if (subscription and subscription.search_strategy == 'iterative-refinement') or (not subscription and default_settings.search_strategy == 'iterative-refinement') %}selected{% endif %}>Experimental: Iterative Refinement (Progressive refinement)</option>+ {% for s in strategies %}+ <option value="{{ s.name }}" {% if (subscription and subscription.search_strategy == s.name) or (not subscription and default_settings.search_strategy == s.name) %}selected{% endif %}>{{ s.label }}</option>+ {% endfor %}</select><div class="ldr-form-text">Choose the search strategy that best fits your needs</div></div>diff --git a/src/local_deep_research/web/templates/pages/news.html b/src/local_deep_research/web/templates/pages/news.htmlindex 4a43d53f87..35873842f2 100644--- a/src/local_deep_research/web/templates/pages/news.html+++ b/src/local_deep_research/web/templates/pages/news.html@@ -308,10 +308,9 @@<div class="mb-3"><label for="news-subscription-strategy" class="form-label">Search Strategy</label><select class="form-select" id="news-subscription-strategy">- <option value="news_aggregation">News Aggregation</option>- <option value="source-based">Source Based</option>- <option value="focused-iteration">Focused Iteration - Quick</option>- <option value="rapid">Rapid Search</option>+ {% for s in strategies %}+ <option value="{{ s.name }}">{{ s.label }}</option>+ {% endfor %}</select></div>diff --git a/src/local_deep_research/web/templates/pages/research.html b/src/local_deep_research/web/templates/pages/research.htmlindex 68eb96ce9f..5b5e66475f 100644--- a/src/local_deep_research/web/templates/pages/research.html+++ b/src/local_deep_research/web/templates/pages/research.html@@ -233,12 +233,9 @@<div class="ldr-form-group ldr-half"><label for="strategy">{{ tooltip("Search Strategy", "Source-Based: Full report with inline citations. Focused Quick: Concise Q&A. Focused Comprehensive: Detailed answer with citations. Topic Organization: Groups results by theme.") }}</label><select id="strategy" name="strategy" class="ldr-form-control">- <option value="source-based" {% if settings.search_strategy == 'source-based' %}selected{% endif %}>Source-Based (Best for small <16,000 context window)</option>- <option value="focused-iteration" {% if settings.search_strategy == 'focused-iteration' %}selected{% endif %}>Focused Iteration - Quick (Minimal text output)</option>- <option value="focused-iteration-standard" {% if settings.search_strategy == 'focused-iteration-standard' %}selected{% endif %}>Focused Iteration - Comprehensive (Needs >16,000 context window)</option>- <option value="iterative-refinement" {% if settings.search_strategy == 'iterative-refinement' %}selected{% endif %}>Experimental: Iterative Refinement (Progressive refinement)</option>- <option value="topic-organization" {% if settings.search_strategy == 'topic-organization' %}selected{% endif %}>Experimental: Topic Organization (Clusters by topic)</option>- <option value="mcp" {% if settings.search_strategy == 'mcp' %}selected{% endif %}>MCP ReAct (Agentic research - LLM decides tools)</option>+ {% for s in strategies %}+ <option value="{{ s.name }}" {% if settings.search_strategy == s.name %}selected{% endif %}>{{ s.label }}</option>+ {% endfor %}</select><span class="ldr-input-help">Focused Iteration works best with >16,000 context window</span></div>diff --git a/tests/news/test_web_blueprint_logic_behavior.py b/tests/news/test_web_blueprint_logic_behavior.pyindex 055c379f15..58e70dd072 100644--- a/tests/news/test_web_blueprint_logic_behavior.py+++ b/tests/news/test_web_blueprint_logic_behavior.py@@ -183,44 +183,6 @@ class TestHealthCheckResponse:assert "internal" in response["error"].lower()-# --- Available strategies list ------class TestAvailableStrategies:- """Tests for available strategy list."""-- def _get_strategies(self):- return [- "topic_based",- "news_aggregation",- "source_based",- "focused_iteration",- ]-- def test_has_topic_based(self):- assert "topic_based" in self._get_strategies()-- def test_has_news_aggregation(self):- assert "news_aggregation" in self._get_strategies()-- def test_has_source_based(self):- assert "source_based" in self._get_strategies()-- def test_has_focused_iteration(self):- assert "focused_iteration" in self._get_strategies()-- def test_exactly_four_strategies(self):- assert len(self._get_strategies()) == 4---class TestDefaultStrategy:- """Tests for default strategy selection."""-- def test_default_is_topic_based(self):- default_strategy = "topic_based"- assert default_strategy == "topic_based"--# --- Subscription page context ---diff --git a/tests/settings/golden_master_settings.json b/tests/settings/golden_master_settings.jsonindex 0d626669e6..5afdd8180f 100644--- a/tests/settings/golden_master_settings.json+++ b/tests/settings/golden_master_settings.json@@ -7437,12 +7437,30 @@"min_value": null,"name": "Search Strategy","options": [- "source-based",- "focused-iteration",- "focused-iteration-standard",- "iterative-refinement",- "topic-organization",- "mcp"+ {+ "label": "Source-Based (Best for small <16,000 context window)",+ "value": "source-based"+ },+ {+ "label": "Focused Iteration - Quick (Minimal text output)",+ "value": "focused-iteration"+ },+ {+ "label": "Focused Iteration - Comprehensive (Needs >16,000 context window)",+ "value": "focused-iteration-standard"+ },+ {+ "label": "Iterative Refinement (Progressive refinement)",+ "value": "iterative-refinement"+ },+ {+ "label": "Topic Organization (Clusters by topic)",+ "value": "topic-organization"+ },+ {+ "label": "MCP ReAct (Agentic research - LLM decides tools)",+ "value": "mcp"+ }],"step": null,"type": "SEARCH",diff --git a/tests/test_search_system_factory_high_value.py b/tests/test_search_system_factory_high_value.pyindex a83d59c6ff..43b52ff13e 100644--- a/tests/test_search_system_factory_high_value.py+++ b/tests/test_search_system_factory_high_value.py@@ -20,7 +20,7 @@ class TestAvailableStrategiesList:assert isinstance(AVAILABLE_STRATEGIES, list)def test_expected_count(self):- assert len(AVAILABLE_STRATEGIES) == 19+ assert len(AVAILABLE_STRATEGIES) == 6def test_all_entries_are_dicts(self):for entry in AVAILABLE_STRATEGIES:@@ -53,19 +53,6 @@ class TestAvailableStrategiesList:"iterative-refinement","topic-organization","mcp",- "rapid",- "iterative",- "parallel",- "recursive",- "adaptive",- "smart",- "browsecomp",- "evidence",- "constrained",- "news",- "standard",- "iterdrag",- "iterative-reasoning",],)def test_contains_known_strategy(self, strategy_name):@@ -78,7 +65,7 @@ class TestAvailableStrategiesList:def test_entries_have_only_expected_keys(self):for entry in AVAILABLE_STRATEGIES:- assert set(entry.keys()) == {"name", "description"}+ assert set(entry.keys()) == {"name", "label", "description"}class TestGetAvailableStrategies: