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 news search detection to optimize query generation (#678)

LearningCircuitfdf29c55a9d9
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 c25073f53e..8ed4ee5f66 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
@@ -17,8 +17,16 @@ class BaseSearchStrategy(ABC):
all_links_of_system=None,
settings_snapshot=None,
questions_by_iteration=None,
+ search_original_query: bool = True,
):
- """Initialize the base strategy with common attributes."""
+ """Initialize the base strategy with common attributes.
+
+ Args:
+ all_links_of_system: List to store all discovered links
+ settings_snapshot: Settings snapshot for configuration
+ questions_by_iteration: Dictionary of questions by iteration
+ search_original_query: Whether to include the original query in the first iteration
+ """
self.progress_callback = None
# Create a new dict if None is provided (avoiding mutable default argument)
self.questions_by_iteration = (
@@ -29,6 +37,7 @@ class BaseSearchStrategy(ABC):
all_links_of_system if all_links_of_system is not None else []
)
self.settings_snapshot = settings_snapshot or {}
+ self.search_original_query = search_original_query
def get_setting(self, key: str, default=None):
"""Get a setting value from the snapshot."""
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 57de68bff5..bf7f7f7e67 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,12 +38,14 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
all_links_of_system=None,
use_atomic_facts: bool = False,
settings_snapshot=None,
+ search_original_query: bool = True,
):
"""Initialize with optional dependency injection for testing."""
# Pass the links list and settings to the parent class
super().__init__(
all_links_of_system=all_links_of_system,
settings_snapshot=settings_snapshot,
+ search_original_query=search_original_query,
)
# Model and search are always provided by AdvancedSearchSystem
@@ -172,11 +174,17 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
questions_by_iteration=self.questions_by_iteration,
)
- # Always include the original query for the first iteration
- if query not in questions:
- all_questions = [query] + questions
- else:
- all_questions = questions
+ # Include original query if enabled and not already present
+ all_questions = (
+ [query] + questions
+ if self.search_original_query and query not in questions
+ else questions
+ )
+
+ if not self.search_original_query:
+ logger.info(
+ "search_original_query=False - skipping original query"
+ )
self.questions_by_iteration[iteration] = all_questions
logger.info(
diff --git a/src/local_deep_research/api/research_functions.py b/src/local_deep_research/api/research_functions.py
index 893a7997bd..a05b07f680 100644
--- a/src/local_deep_research/api/research_functions.py
+++ b/src/local_deep_research/api/research_functions.py
@@ -35,6 +35,7 @@ def _init_search_system(
research_id: Optional[Union[int, str]] = None,
research_context: Optional[Dict[str, Any]] = None,
programmatic_mode: bool = True,
+ search_original_query: bool = True,
**kwargs: Any,
) -> AdvancedSearchSystem:
"""
@@ -58,6 +59,7 @@ def _init_search_system(
retrievers: Optional dictionary of {name: retriever} pairs to use as search engines
llms: Optional dictionary of {name: llm} pairs to use as language models
programmatic_mode: If True, disables database operations and metrics tracking
+ search_original_query: Whether to include the original query in the first iteration of search
Returns:
AdvancedSearchSystem: An instance of the configured AdvancedSearchSystem.
@@ -126,6 +128,7 @@ def _init_search_system(
research_context=research_context,
settings_snapshot=settings_snapshot,
programmatic_mode=programmatic_mode,
+ search_original_query=search_original_query,
)
# Override default settings with user-provided values
@@ -152,6 +155,7 @@ def quick_summary(
max_search_results: Optional[int] = None,
settings: Optional[Dict[str, Any]] = None,
settings_override: Optional[Dict[str, Any]] = None,
+ search_original_query: bool = True,
**kwargs: Any,
) -> Dict[str, Any]:
"""
@@ -168,6 +172,8 @@ def quick_summary(
max_search_results: Maximum number of search results to return. For programmatic API only.
settings: Base settings dict to use instead of defaults. For programmatic API only.
settings_override: Dictionary of settings to override (e.g., {"llm.max_tokens": 4000}). For programmatic API only.
+ search_original_query: Whether to include the original query in the first iteration of search.
+ Set to False for news searches to avoid sending long subscription prompts to search engines.
**kwargs: Additional configuration for the search system. Will be forwarded to
`_init_search_system()`.
@@ -266,6 +272,7 @@ def quick_summary(
init_kwargs["username"] = username
init_kwargs["research_id"] = research_id
init_kwargs["research_context"] = search_context
+ init_kwargs["search_original_query"] = search_original_query
system = _init_search_system(llms=llms, **init_kwargs)
# Perform the search and analysis
diff --git a/src/local_deep_research/news/subscription_manager/scheduler.py b/src/local_deep_research/news/subscription_manager/scheduler.py
index eae64039df..627211db72 100644
--- a/src/local_deep_research/news/subscription_manager/scheduler.py
+++ b/src/local_deep_research/news/subscription_manager/scheduler.py
@@ -593,6 +593,7 @@ class NewsScheduler:
provider=subscription.get("model_provider"),
iterations=1, # Single iteration for news
metadata=metadata,
+ search_original_query=False, # Don't send long subscription prompts to search engines
)
logger.info(
diff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.py
index 05fdeb1bc3..3b362c72ae 100644
--- a/src/local_deep_research/search_system.py
+++ b/src/local_deep_research/search_system.py
@@ -37,6 +37,7 @@ class AdvancedSearchSystem:
research_id: str | None = None,
research_context: dict | None = None,
programmatic_mode: bool = False,
+ search_original_query: bool = True,
):
"""Initialize the advanced search system.
@@ -74,6 +75,9 @@ class AdvancedSearchSystem:
complex queries when using the source-based strategy.
programmatic_mode: If True, disables database operations and metrics tracking.
This is useful for running searches without database dependencies.
+ search_original_query: Whether to include the original query in the first iteration
+ of search. Set to False for news searches to avoid sending long subscription
+ prompts to search engines.
"""
# Store research context for strategies
@@ -91,6 +95,9 @@ class AdvancedSearchSystem:
# Store programmatic mode
self.programmatic_mode = programmatic_mode
+ # Store search original query setting
+ self.search_original_query = search_original_query
+
# Log if running in programmatic mode
if self.programmatic_mode:
logger.warning(
@@ -165,6 +172,7 @@ class AdvancedSearchSystem:
all_links_of_system=[],
settings_snapshot=self.settings_snapshot,
knowledge_accumulation_mode=True,
+ search_original_query=self.search_original_query,
)
# Create the contextual follow-up strategy with the delegate
@@ -201,6 +209,8 @@ class AdvancedSearchSystem:
max_search_iterations=self.max_iterations,
# Special parameters for focused iteration
use_browsecomp_optimization=True,
+ # Pass search original query parameter
+ search_original_query=self.search_original_query,
)
# Log the actual strategy class
diff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.py
index 5f7ec3eaf2..cf6a6e29af 100644
--- a/src/local_deep_research/search_system_factory.py
+++ b/src/local_deep_research/search_system_factory.py
@@ -56,6 +56,7 @@ def create_strategy(
all_links_of_system=all_links_of_system,
use_atomic_facts=kwargs.get("use_atomic_facts", False),
settings_snapshot=settings_snapshot,
+ search_original_query=kwargs.get("search_original_query", True),
)
# Focused iteration strategy
@@ -640,4 +641,5 @@ def create_strategy(
all_links_of_system=all_links_of_system,
use_atomic_facts=False,
settings_snapshot=settings_snapshot,
+ search_original_query=kwargs.get("search_original_query", True),
)