~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
fix(strategy): do not search a long query verbatim in focused iteration (#6384)
Lukasae13ec1685df
diff --git a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.pyindex e38f621e62..3557432631 100644--- a/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/focused_iteration_strategy.py@@ -220,11 +220,25 @@ class FocusedIterationStrategy(BaseSearchStrategy):questions_by_iteration=self.questions_by_iteration,)- # Always include original query in first iteration, but respect question limit+ # Include the original query verbatim in the first iteration so an+ # ambiguous topic still gets one search that hits it. A long query+ # (a detailed-report subsection prompt embeds the whole task) is a+ # research brief, not a search string: sent literally it full-text+ # matches stray words such as an author surname (#6383). Same guard+ # and setting as the source-based strategy.if iteration == 1 and query not in questions:- questions = [query] + questions- # Trim to respect questions_per_iteration limit- questions = questions[: self.questions_per_iteration]+ max_query_length = self.get_setting(+ "app.max_user_query_length", 300+ )+ if len(query.strip()) > max_query_length:+ logger.warning(+ f"Long user query detected ({len(query.strip())} chars > {max_query_length} limit), "+ "using LLM questions only for search"+ )+ else:+ questions = [query] + questions+ # Trim to respect questions_per_iteration limit+ questions = questions[: self.questions_per_iteration]self.questions_by_iteration[iteration] = questionslogger.info(f"Iteration {iteration} questions: {questions}")diff --git a/tests/advanced_search_system/strategies/test_focused_iteration_strategy.py b/tests/advanced_search_system/strategies/test_focused_iteration_strategy.pyindex 42f041aa3b..bf996886d1 100644--- a/tests/advanced_search_system/strategies/test_focused_iteration_strategy.py+++ b/tests/advanced_search_system/strategies/test_focused_iteration_strategy.py@@ -741,6 +741,78 @@ class TestAnalyzeTopic:first_iter_questions = strategy.questions_by_iteration[1]assert first_iter_questions[0] == "my original query"+ def test_long_original_query_is_not_searched_verbatim(self):+ """A query longer than app.max_user_query_length (a detailed-report+ subsection prompt embeds the whole task) is not sent to the search+ engine as a literal string; only the LLM questions are searched (#6383)."""+ from local_deep_research.advanced_search_system.strategies.focused_iteration_strategy import (+ FocusedIterationStrategy,+ )++ mock_search = Mock()+ mock_search.run.return_value = []+ long_query = (+ "Research task: Create content for subsection 'History' in a report "+ "about 'Hay et al. (2018) and juvenile justice'. " * 20+ )+ assert len(long_query) > 300++ strategy = FocusedIterationStrategy(+ model=Mock(),+ search=mock_search,+ max_iterations=1,+ questions_per_iteration=3,+ use_browsecomp_optimization=False,+ )++ with patch.object(+ strategy.question_generator,+ "generate_questions",+ return_value=["Other Q1", "Other Q2"],+ ):+ with patch.object(+ strategy.citation_handler,+ "analyze_followup",+ return_value={"content": "Done", "documents": []},+ ):+ strategy.analyze_topic(long_query)++ assert strategy.questions_by_iteration[1] == ["Other Q1", "Other Q2"]+ searched = [call.args[0] for call in mock_search.run.call_args_list]+ assert long_query not in searched+ assert searched == ["Other Q1", "Other Q2"]++ def test_query_length_limit_follows_the_setting(self):+ """The cutoff is app.max_user_query_length, shared with the source-based strategy."""+ from local_deep_research.advanced_search_system.strategies.focused_iteration_strategy import (+ FocusedIterationStrategy,+ )++ mock_search = Mock()+ mock_search.run.return_value = []+ strategy = FocusedIterationStrategy(+ model=Mock(),+ search=mock_search,+ max_iterations=1,+ questions_per_iteration=3,+ use_browsecomp_optimization=False,+ settings_snapshot={"app.max_user_query_length": 10},+ )++ with patch.object(+ strategy.question_generator,+ "generate_questions",+ return_value=["Other Q1"],+ ):+ with patch.object(+ strategy.citation_handler,+ "analyze_followup",+ return_value={"content": "Done", "documents": []},+ ):+ strategy.analyze_topic("short query") # 11 chars > 10++ assert strategy.questions_by_iteration[1] == ["Other Q1"]+def test_exception_returns_error_response(self):"""Exception during analysis returns error response."""from local_deep_research.advanced_search_system.strategies.focused_iteration_strategy import (