~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 TV-domain terms from _validate_search_results (#2598)
LearningCircuit5b477f164395
diff --git a/src/local_deep_research/advanced_search_system/strategies/constrained_search_strategy.py b/src/local_deep_research/advanced_search_system/strategies/constrained_search_strategy.pyindex 18e9bdf391..16b578de85 100644--- a/src/local_deep_research/advanced_search_system/strategies/constrained_search_strategy.py+++ b/src/local_deep_research/advanced_search_system/strategies/constrained_search_strategy.py@@ -180,7 +180,8 @@ class ConstrainedSearchStrategy(EvidenceBasedStrategy):elif constraint.type == ConstraintType.PROPERTY:score += 4 # Properties are less restrictive- # Specificity scoring+ # NOTE: constraint.value is always a str from+ # ConstraintAnalyzer. The truthiness guard is intentional.if constraint.value:# Check for specific markersif any(char.isdigit() for char in constraint.value):@@ -661,7 +662,11 @@ Return one {entity_type} name per line. Only include names that could satisfy thcontext_quality = 0.0candidate_lower = candidate.name.lower()- value_lower = constraint.value.lower()+ # NOTE: constraint.value is always a str from ConstraintAnalyzer.+ # The truthiness guard handles empty strings correctly. Do NOT+ # change to "is not None" — for hypothetical value=0, "0"+ # would match nearly all content and inflate scores.+ value_lower = str(constraint.value).lower() if constraint.value else ""content_lower = content.lower()# Check candidate name presence@@ -672,7 +677,7 @@ Return one {entity_type} name per line. Only include names that could satisfy th) # More occurrences = higher confidence# Check constraint value presence- if value_lower in content_lower:+ if value_lower and value_lower in content_lower:value_count = content_lower.count(value_lower)constraint_presence = min(0.3 + (value_count * 0.05), 0.4)@@ -721,8 +726,10 @@ Return one {entity_type} name per line. Only include names that could satisfy thsnippet = result.get("snippet", "").lower()if (- candidate_lower in title or candidate_lower in snippet- ) and (value_lower in title or value_lower in snippet):+ (candidate_lower in title or candidate_lower in snippet)+ and value_lower+ and (value_lower in title or value_lower in snippet)+ ):relevant_results += 1context_quality = min(relevant_results * 0.05, 0.2)@@ -908,7 +915,8 @@ Return one {entity_type} name per line. Only include names that could satisfy thelif constraint.type == ConstraintType.PROPERTY:score += 4- # Specificity scoring+ # NOTE: constraint.value is always a str from+ # ConstraintAnalyzer. The truthiness guard is intentional.if constraint.value:if any(char.isdigit() for char in constraint.value):score += 5@@ -993,7 +1001,7 @@ Return one {entity_type} name per line. Only include names that could satisfy thchange = count - prev_count if stage > 0 else countchange_str = f" ({change:+d})" if stage > 0 else ""- summary += f"\nStage {stage + 1} [{constraint.type.value}]: {constraint.value[:40]}\n"+ summary += f"\nStage {stage + 1} [{constraint.type.value}]: {str(constraint.value)[:40]}\n"summary += f" Results: {count} candidates{change_str}\n"if candidates:@@ -1229,32 +1237,17 @@ Return one {entity_type} name per line. Only include names that could satisfy thlogger.debug("No results found")return False- # For stats/numeric constraints, check for related terms- if constraint.type == ConstraintType.STATISTIC:- # Look for related terms about TV shows, episodes, etc- relevant_terms = [- "tv",- "show",- "series",- "episode",- "season",- "program",- "character",- "fiction",- ]- content_lower = content.lower()-- term_found = any(term in content_lower for term in relevant_terms)- if not term_found:- logger.debug(- "No relevant TV/show terms found for statistic constraint"- )- return False- else:- # Check for relevance to constraint using key terms+ # NOTE: constraint.value is always a str from ConstraintAnalyzer+ # (constraint_analyzer.py:91). Do NOT change this to+ # "is not None" — for hypothetical non-string falsy values+ # like 0.0, that would reject content missing the literal+ # string "0.0". The truthiness guard correctly skips empty+ # values, falling through to the quality check below.+ if constraint.value:+ value_str = str(constraint.value).lower()constraint_terms = [term- for term in constraint.value.lower().split()+ for term in value_str.split()if len(term) > 2and termnot in ["the", "and", "with", "for", "had", "his", "her"]diff --git a/tests/advanced_search_system/strategies/test_constrained_search_high_value.py b/tests/advanced_search_system/strategies/test_constrained_search_high_value.pyindex a3e0085fb9..e59ef2e115 100644--- a/tests/advanced_search_system/strategies/test_constrained_search_high_value.py+++ b/tests/advanced_search_system/strategies/test_constrained_search_high_value.py@@ -422,6 +422,122 @@ class TestValidateSearchResults:}assert strat._validate_search_results(results, c) is True+ def test_accepts_statistic_with_matching_terms(self):+ """STATISTIC constraint with matching terms in content is accepted."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.STATISTIC,+ value="population density growth",+ )+ results = {+ "current_knowledge": (+ "The population of the region saw significant density "+ "increases and growth over the past decade due to urban "+ "expansion and migration patterns."+ ),+ "search_results": [{"title": "Stats", "snippet": "data"}],+ }+ assert strat._validate_search_results(results, c) is True++ def test_rejects_statistic_with_no_matching_terms(self):+ """STATISTIC constraint rejected when content has no matching terms."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.STATISTIC,+ value="revenue quarterly earnings",+ )+ results = {+ "current_knowledge": (+ "The weather forecast for tomorrow shows sunny skies "+ "with temperatures reaching thirty degrees in most areas."+ ),+ "search_results": [{"title": "Weather", "snippet": "sun"}],+ }+ assert strat._validate_search_results(results, c) is False++ def test_accepts_statistic_non_tv_domain(self):+ """STATISTIC constraint works for non-TV domains (no TV coupling)."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.STATISTIC,+ value="4000 meter elevation",+ )+ results = {+ "current_knowledge": (+ "The mountain peak reaches an elevation of over four "+ "thousand meter above sea level, making it one of the "+ "tallest in the range."+ ),+ "search_results": [{"title": "Peak", "snippet": "altitude"}],+ }+ assert strat._validate_search_results(results, c) is True++ def test_statistic_none_value_skips_term_check(self):+ """STATISTIC with None value skips term check, falls to quality."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.STATISTIC,+ value=None,+ )+ results = {+ "current_knowledge": (+ "Sufficient content that passes the length check easily "+ "and does not contain error or no results messages."+ ),+ "search_results": [{"title": "Info", "snippet": "data"}],+ }+ assert strat._validate_search_results(results, c) is True++ def test_statistic_numeric_value_no_crash(self):+ """STATISTIC with numeric value does not crash."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.STATISTIC,+ value=42,+ )+ results = {+ "current_knowledge": (+ "This content is long enough and contains the number 42 "+ "somewhere in the text for validation purposes."+ ),+ "search_results": [],+ }+ # str(42) = "42", len == 2, filtered by len > 2,+ # so constraint_terms is empty and validation passes.+ assert strat._validate_search_results(results, c) is True++ def test_none_value_non_statistic_no_crash(self):+ """PROPERTY with None value does not crash."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.PROPERTY,+ value=None,+ )+ results = {+ "current_knowledge": (+ "Sufficient content that passes the length check easily "+ "and does not contain error or no results messages."+ ),+ "search_results": [{"title": "Info", "snippet": "data"}],+ }+ assert strat._validate_search_results(results, c) is True++ def test_short_numeric_value_passes_validation(self):+ """PROPERTY with short numeric value '42' passes (no terms > 2 chars)."""+ strat = _make_strategy()+ c = _make_constraint(+ ctype=ConstraintType.PROPERTY,+ value="42",+ )+ results = {+ "current_knowledge": (+ "This content is long enough to pass the minimum length "+ "check and has valid search results attached to it."+ ),+ "search_results": [{"title": "Info", "snippet": "data"}],+ }+ assert strat._validate_search_results(results, c) is True+# ---------------------------------------------------------------------------# Tests: _quick_evidence_check scoring@@ -507,3 +623,15 @@ class TestQuickEvidenceCheck:}evidence = strat._quick_evidence_check(results, candidate, constraint)assert evidence.confidence <= 1.0++ def test_none_constraint_value_no_crash(self):+ """None constraint value does not crash _quick_evidence_check."""+ strat = _make_strategy()+ candidate = Candidate(name="Test Entity")+ constraint = _make_constraint(value=None)+ results = {+ "current_knowledge": "Some content about various topics.",+ "search_results": [],+ }+ evidence = strat._quick_evidence_check(results, candidate, constraint)+ assert isinstance(evidence, Evidence)