~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: remove hardcoded keyword matching from strategy files (#2628)
LearningCircuit13d3d6db5cb9
diff --git a/src/local_deep_research/advanced_search_system/strategies/concurrent_dual_confidence_strategy.py b/src/local_deep_research/advanced_search_system/strategies/concurrent_dual_confidence_strategy.pyindex c2778b1523..902cda3587 100644--- a/src/local_deep_research/advanced_search_system/strategies/concurrent_dual_confidence_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/concurrent_dual_confidence_strategy.py@@ -135,56 +135,15 @@ class ConcurrentDualConfidenceStrategy(DualConfidenceWithRejectionStrategy):def _classify_constraint_difficulty(self):"""Rate constraints by how difficult they are to search for."""- difficulty_keywords = {- # Abstract/subjective (very hard)- "complex": 0.9,- "deep": 0.9,- "emotional": 0.9,- "acclaimed": 0.8,- "understanding": 0.9,- "sophisticated": 0.9,- "nuanced": 0.9,- # Relative terms (hard)- "famous": 0.7,- "popular": 0.7,- "well-known": 0.7,- "notable": 0.7,- # Time ranges (medium)- "between": 0.5,- "during": 0.5,- "era": 0.5,- "period": 0.5,- # Specific facts (easy)- "aired": 0.2,- "released": 0.2,- "episode": 0.1,- "season": 0.1,- "character": 0.2,- "show": 0.2,- "movie": 0.2,- "series": 0.2,- # Named entities (easiest)- "hbo": 0.1,- "netflix": 0.1,- "disney": 0.1,- "marvel": 0.1,- }-for constraint in self.state.remaining_constraints:difficulty = 0.5 # Default medium difficulty- constraint_lower = constraint.value.lower()- for keyword, score in difficulty_keywords.items():- if keyword in constraint_lower:- difficulty = max(difficulty, score)-- # Constraint type also affects difficulty+ # Constraint type affects difficultyif constraint.type == ConstraintType.PROPERTY:difficulty = min(difficulty, 0.6)elif constraint.type == ConstraintType.EVENT:difficulty = max(difficulty, 0.7)- # Store difficulty as attributeconstraint.search_difficulty = difficulty# Sort constraints by difficulty (hardest first, so we can drop them first)diff --git a/src/local_deep_research/advanced_search_system/strategies/parallel_constrained_strategy.py b/src/local_deep_research/advanced_search_system/strategies/parallel_constrained_strategy.pyindex 03a0c21003..685b8c4023 100644--- a/src/local_deep_research/advanced_search_system/strategies/parallel_constrained_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/parallel_constrained_strategy.py@@ -48,48 +48,17 @@ class ParallelConstrainedStrategy(ConstrainedSearchStrategy):self.parallel_workers = parallel_workersself.min_results_threshold = min_results_threshold- # Define hard constraints that must be satisfied- self.hard_constraint_keywords = [- "aired between",- "aired during",- "air date",- "broadcast",- "episodes",- "season",- "year",- "decade",- "male",- "female",- "gender",- "tv show",- "series",- "program",- ]-def _classify_constraints(self):"""Classify constraints into hard (must satisfy) and soft (scoring) categories."""self.hard_constraints = []self.soft_constraints = []for constraint in self.constraint_ranking:- # Check if constraint is hard based on keywords and type- is_hard = False-- # Temporal and statistic constraints are usually hard+ # Temporal and statistic constraints are hardif constraint.type in [ConstraintType.TEMPORAL,ConstraintType.STATISTIC,]:- is_hard = True-- # Check for hard constraint keywords- constraint_text = constraint.value.lower()- for keyword in self.hard_constraint_keywords:- if keyword in constraint_text:- is_hard = True- break-- if is_hard:self.hard_constraints.append(constraint)else:self.soft_constraints.append(constraint)diff --git a/tests/advanced_search_system/strategies/test_concurrent_dual_confidence_high_value.py b/tests/advanced_search_system/strategies/test_concurrent_dual_confidence_high_value.pyindex b14971ae87..5c3a77ad61 100644--- a/tests/advanced_search_system/strategies/test_concurrent_dual_confidence_high_value.py+++ b/tests/advanced_search_system/strategies/test_concurrent_dual_confidence_high_value.py@@ -3,7 +3,7 @@ High-value tests for ConcurrentDualConfidenceStrategy.Covers pure logic paths:- SearchState dataclass defaults and field types-- _classify_constraint_difficulty: keyword matching, constraint type adjustment, sorting+- _classify_constraint_difficulty: constraint type adjustment, sorting- _build_combined_query: multi-word quoting, already-quoted passthrough, concatenation- _should_stop_search: all 7 stopping criteria- _is_candidate_evaluated: thread-safe duplicate check@@ -160,40 +160,30 @@ class TestBuildCombinedQuery:class TestClassifyConstraintDifficulty:"""Tests for constraint difficulty rating and sorting."""- def test_abstract_keyword_gets_high_difficulty_with_event_type(self):- """EVENT type doesn't cap, so keyword difficulty of 0.9 is preserved."""+ def test_event_type_gets_0_7(self):+ """EVENT type raises difficulty to 0.7."""strategy = _make_strategy()c = _make_constraint(value="complex emotional narrative", type_name="EVENT")strategy.state = SearchState(remaining_constraints=[c])strategy._classify_constraint_difficulty()- assert c.search_difficulty >= 0.9-- def test_specific_keyword_with_event_type(self):- """'episode aired' has keyword difficulty ~0.2 but EVENT raises to 0.7."""- strategy = _make_strategy()- c = _make_constraint(value="episode aired in 2020", type_name="EVENT")- strategy.state = SearchState(remaining_constraints=[c])- strategy._classify_constraint_difficulty()- assert c.search_difficulty >= 0.7+ assert c.search_difficulty == 0.7def test_default_difficulty_is_0_5(self):strategy = _make_strategy()c = _make_constraint(value="something generic xyz")strategy.state = SearchState(remaining_constraints=[c])strategy._classify_constraint_difficulty()- # PROPERTY type caps at 0.6, so 0.5 default stays as 0.5+ # PROPERTY type: min(0.5, 0.6) = 0.5assert c.search_difficulty == 0.5- def test_named_entity_with_property_type(self):- """PROPERTY type caps at 0.6; 'netflix' keyword gives 0.1 -> min(0.5, 0.6) = 0.5."""+ def test_property_type_gets_0_5(self):+ """PROPERTY type: min(0.5, 0.6) = 0.5."""strategy = _make_strategy()c = _make_constraint(value="netflix original")strategy.state = SearchState(remaining_constraints=[c])strategy._classify_constraint_difficulty()- # Default 0.5 with 'netflix' keyword max = max(0.5, 0.1) = 0.5- # Then PROPERTY: min(0.5, 0.6) = 0.5assert c.search_difficulty == 0.5def test_property_type_caps_difficulty(self):@@ -217,33 +207,28 @@ class TestClassifyConstraintDifficulty:def test_sorted_by_difficulty_descending(self):"""Constraints are sorted hardest-first after classification."""strategy = _make_strategy()- easy = _make_constraint(value="episode aired")- hard = _make_constraint(value="complex emotional narrative")- strategy.state = SearchState(remaining_constraints=[easy, hard])+ prop = _make_constraint(value="some property", type_name="PROPERTY")+ event = _make_constraint(value="some event", type_name="EVENT")+ strategy.state = SearchState(remaining_constraints=[prop, event])strategy._classify_constraint_difficulty()- assert strategy.state.remaining_constraints[0] is hard- assert strategy.state.remaining_constraints[1] is easy+ assert strategy.state.remaining_constraints[0] is event+ assert strategy.state.remaining_constraints[1] is prop- def test_multiple_keywords_max_difficulty_wins(self):- """When multiple keywords match, the highest keyword difficulty wins.- But PROPERTY type caps at 0.6."""+ def test_statistic_gets_default_0_5(self):+ """STATISTIC type has no special handling, gets default 0.5."""strategy = _make_strategy()- # 'complex' = 0.9, 'released' = 0.2 -> max keyword = 0.9- # PROPERTY type: min(0.9, 0.6) = 0.6- c = _make_constraint(- value="complex movie released", type_name="PROPERTY"- )+ c = _make_constraint(value="84.5x ratio", type_name="STATISTIC")strategy.state = SearchState(remaining_constraints=[c])strategy._classify_constraint_difficulty()- assert c.search_difficulty == 0.6+ assert c.search_difficulty == 0.5- def test_multiple_keywords_max_difficulty_with_event_type(self):- """EVENT type: keyword max 0.9 -> max(0.9, 0.7) = 0.9."""+ def test_location_gets_default_0_5(self):+ """LOCATION type has no special handling, gets default 0.5."""strategy = _make_strategy()- c = _make_constraint(value="complex movie released", type_name="EVENT")+ c = _make_constraint(value="New York City", type_name="LOCATION")strategy.state = SearchState(remaining_constraints=[c])strategy._classify_constraint_difficulty()- assert c.search_difficulty >= 0.9+ assert c.search_difficulty == 0.5# ---------------------------------------------------------------------------diff --git a/tests/advanced_search_system/strategies/test_parallel_constrained_high_value.py b/tests/advanced_search_system/strategies/test_parallel_constrained_high_value.pyindex 2c8c7f7cc8..51460d087a 100644--- a/tests/advanced_search_system/strategies/test_parallel_constrained_high_value.py+++ b/tests/advanced_search_system/strategies/test_parallel_constrained_high_value.py@@ -65,22 +65,6 @@ def strategy():s = ParallelConstrainedStrategy.__new__(ParallelConstrainedStrategy)s.parallel_workers = 100s.min_results_threshold = 10- s.hard_constraint_keywords = [- "aired between",- "aired during",- "air date",- "broadcast",- "episodes",- "season",- "year",- "decade",- "male",- "female",- "gender",- "tv show",- "series",- "program",- ]return s@@ -100,28 +84,14 @@ class TestClassifyConstraints:strategy._classify_constraints()assert len(strategy.hard_constraints) == 1- def test_keyword_makes_hard(self, strategy):- strategy.constraint_ranking = [- make_constraint(- ConstraintType.PROPERTY, "aired between 2010 and 2015"- ),- ]- strategy._classify_constraints()- assert len(strategy.hard_constraints) == 1-- def test_season_keyword_hard(self, strategy):- strategy.constraint_ranking = [- make_constraint(ConstraintType.PROPERTY, "season 3 episode"),- ]- strategy._classify_constraints()- assert len(strategy.hard_constraints) == 1-- def test_gender_keyword_hard(self, strategy):+ def test_property_is_soft(self, strategy):+ """PROPERTY constraints are always soft (no keyword matching)."""strategy.constraint_ranking = [make_constraint(ConstraintType.PROPERTY, "female character"),]strategy._classify_constraints()- assert len(strategy.hard_constraints) == 1+ assert len(strategy.soft_constraints) == 1+ assert len(strategy.hard_constraints) == 0def test_property_without_keyword_is_soft(self, strategy):strategy.constraint_ranking = [@@ -131,14 +101,14 @@ class TestClassifyConstraints:assert len(strategy.soft_constraints) == 1assert len(strategy.hard_constraints) == 0- def test_mixed_hard_and_soft(self, strategy):+ def test_mixed_types_hard_and_soft(self, strategy):+ """TEMPORAL → hard, PROPERTY → soft."""strategy.constraint_ranking = [make_constraint(ConstraintType.TEMPORAL, "in 2020"),make_constraint(ConstraintType.PROPERTY, "has blue eyes"),- make_constraint(ConstraintType.PROPERTY, "aired during 2019"),]strategy._classify_constraints()- assert len(strategy.hard_constraints) == 2+ assert len(strategy.hard_constraints) == 1assert len(strategy.soft_constraints) == 1