~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(search): honor search.quality_check_urls setting in FullSearchResults (#6571)
Sd8c8d152962c
diff --git a/changelog.d/6571.bugfix.md b/changelog.d/6571.bugfix.mdnew file mode 100644index 0000000000..f750213091--- /dev/null+++ b/changelog.d/6571.bugfix.md@@ -0,0 +1 @@+Honor `search.quality_check_urls` setting in `FullSearchResults` to allow skipping URL filtering before full-page extraction, forward the settings snapshot into factory-built full-search wrappers so the toggle works through `get_search()`/`create_search_engine()`, and add progress logging (constructors without a settings snapshot continue to fall back to the `QUALITY_CHECK_DDG_URLS` default).diff --git a/src/local_deep_research/utilities/type_utils.py b/src/local_deep_research/utilities/type_utils.pyindex 36611fe941..757033edc2 100644--- a/src/local_deep_research/utilities/type_utils.py+++ b/src/local_deep_research/utilities/type_utils.py@@ -80,6 +80,33 @@ def unwrap_setting(val: Any) -> Any:return val+def resolve_boolean_setting(+ settings_snapshot: Optional[Dict[str, Any]],+ key: str,+ default: Optional[bool] = None,+) -> Optional[bool]:+ """Resolve a boolean setting from a settings snapshot.++ Handles boolean values, dictionary settings envelopes (``{"value": ...}``),+ string encodings ("true"/"false"/"1"/"0"/"yes"/"no"/"on"/"off"), and+ returns ``default`` (None unless specified) when the setting is absent or unset.+ """+ if not settings_snapshot or key not in settings_snapshot:+ return default+ raw = unwrap_setting(settings_snapshot[key])+ if raw is None:+ return default+ if isinstance(raw, bool):+ return raw+ if isinstance(raw, str):+ val = raw.strip().lower()+ if val in ("false", "0", "off", "no"):+ return False+ if val in ("true", "1", "on", "yes"):+ return True+ return bool(raw)++def overlay_snapshot_value(snapshot: dict, key: str, value: Any) -> None:"""Write an override into a settings snapshot without dropping envelope metadata.diff --git a/src/local_deep_research/web_search_engines/engines/full_search.py b/src/local_deep_research/web_search_engines/engines/full_search.pyindex 244b004e0d..d22ff5292c 100644--- a/src/local_deep_research/web_search_engines/engines/full_search.py+++ b/src/local_deep_research/web_search_engines/engines/full_search.py@@ -16,6 +16,7 @@ from ...utilities.js_rendering import (read_js_rendering_setting as _read_js_rendering_setting,)from ...utilities.json_utils import extract_json, get_llm_response_text+from ...utilities.type_utils import resolve_boolean_settingfrom ...utilities.llm_utils import invoke_llm_sync@@ -238,8 +239,16 @@ class FullSearchResults:if not isinstance(search_results, list):raise ValueError("Expected the search results in list format.")- # Step 2: Filter URLs using LLM- if QUALITY_CHECK_DDG_URLS:+ # Step 2: Filter URLs using LLM if enabled+ should_check_urls = resolve_boolean_setting(+ self.settings_snapshot,+ "search.quality_check_urls",+ default=QUALITY_CHECK_DDG_URLS,+ )+ if should_check_urls and self.llm is not None:+ logger.info(+ "Evaluating search result URLs with LLM before fetching full content..."+ )filtered_results = self.check_urls(search_results, query)else:filtered_results = search_results@@ -310,6 +319,9 @@ class FullSearchResults:# every type but arXiv paper URLs, which their downloader owns# outright: for those a failure is terminal and yields no content.# Other arXiv-host pages are not owned and do crawl.+ logger.info(+ f"Full search: fetching and extracting full content for {len(safe_urls)} pages..."+ )url_to_content = batch_fetch_and_extract(safe_urls,language=self.language,diff --git a/src/local_deep_research/web_search_engines/search_engine_factory.py b/src/local_deep_research/web_search_engines/search_engine_factory.pyindex 0bacaf9d61..313d8a5cb3 100644--- a/src/local_deep_research/web_search_engines/search_engine_factory.py+++ b/src/local_deep_research/web_search_engines/search_engine_factory.py@@ -930,6 +930,11 @@ def _create_full_search_wrapper(if "web_search" in wrapper_init_params:wrapper_params["web_search"] = base_engine+ # Always pass settings_snapshot if the wrapper accepts it.+ # `params` is create_search_engine kwargs and never includes this+ # separate factory argument, so signature filtering drops it otherwise.+ if "settings_snapshot" in wrapper_init_params and settings_snapshot:+ wrapper_params["settings_snapshot"] = settings_snapshot# Private result-fetch grant for the wrapper's SSRF validation and# download pipeline. Taken from the base engine's own resolution# only (``BaseSearchEngine.allow_private_result_fetch``, Falsediff --git a/tests/test_advertised_but_dead_sweep.py b/tests/test_advertised_but_dead_sweep.pyindex 11540580a7..f3f2f5a745 100644--- a/tests/test_advertised_but_dead_sweep.py+++ b/tests/test_advertised_but_dead_sweep.py@@ -593,13 +593,6 @@ SETTINGS_OFFERED_BUT_UNREAD = {"number input making the same promise as report.searches_per_section, ""separately documented, equally unread."),- "search.quality_check_urls": (- "checkbox, listed in settings.js tabSpecificSettings['search'] so it "- "definitely renders. The only quality-check gate is the module-level "- "constant config/search_config.py:QUALITY_CHECK_DDG_URLS = True, "- "consumed by engines/full_search.py. Unchecking the box changes "- "nothing."- ),# --- the news settings block ------------------------------------------"news.display.default_headline_max_length": "number input, no reader.","news.display.max_query_length": (diff --git a/tests/utilities/test_type_utils.py b/tests/utilities/test_type_utils.pyindex ca7b0442ae..e51e09d1ea 100644--- a/tests/utilities/test_type_utils.py+++ b/tests/utilities/test_type_utils.py@@ -8,6 +8,8 @@ Tests cover:- Edge cases"""+import pytest+class TestToBool:"""Tests for to_bool function."""@@ -494,6 +496,123 @@ class TestToBoolEnvironmentVariableSimulation:assert to_bool("'true'") is False+class TestResolveBooleanSetting:+ """Tests for resolve_boolean_setting helper function."""++ @pytest.mark.parametrize(+ "raw_value,expected",+ [+ (True, True),+ (False, False),+ ("true", True),+ ("True", True),+ ("TRUE", True),+ ("1", True),+ ("yes", True),+ ("on", True),+ ("false", False),+ ("False", False),+ ("FALSE", False),+ ("0", False),+ ("no", False),+ ("off", False),+ ("", False),+ ],+ )+ def test_direct_values(self, raw_value, expected):+ from local_deep_research.utilities.type_utils import (+ resolve_boolean_setting,+ )++ assert (+ resolve_boolean_setting({"my.setting": raw_value}, "my.setting")+ is expected+ )++ @pytest.mark.parametrize(+ "raw_value,expected",+ [+ (True, True),+ (False, False),+ ("true", True),+ ("false", False),+ ("1", True),+ ("0", False),+ ("yes", True),+ ("no", False),+ ("on", True),+ ("off", False),+ ],+ )+ def test_envelope_values(self, raw_value, expected):+ from local_deep_research.utilities.type_utils import (+ resolve_boolean_setting,+ )++ assert (+ resolve_boolean_setting(+ {"my.setting": {"value": raw_value}}, "my.setting"+ )+ is expected+ )++ def test_missing_or_unset_default_none(self):+ from local_deep_research.utilities.type_utils import (+ resolve_boolean_setting,+ )++ assert resolve_boolean_setting(None, "my.setting") is None+ assert resolve_boolean_setting({}, "my.setting") is None+ assert (+ resolve_boolean_setting({"other.key": True}, "my.setting") is None+ )+ assert (+ resolve_boolean_setting({"my.setting": None}, "my.setting") is None+ )+ assert (+ resolve_boolean_setting(+ {"my.setting": {"value": None}}, "my.setting"+ )+ is None+ )++ def test_missing_or_unset_with_custom_default(self):+ from local_deep_research.utilities.type_utils import (+ resolve_boolean_setting,+ )++ assert resolve_boolean_setting(None, "my.setting", default=True) is True+ assert resolve_boolean_setting({}, "my.setting", default=True) is True+ assert (+ resolve_boolean_setting(+ {"other.key": True}, "my.setting", default=True+ )+ is True+ )+ assert (+ resolve_boolean_setting(+ {"my.setting": None}, "my.setting", default=True+ )+ is True+ )+ assert (+ resolve_boolean_setting(+ {"my.setting": {"value": None}}, "my.setting", default=True+ )+ is True+ )+ assert (+ resolve_boolean_setting(None, "my.setting", default=False) is False+ )+ assert resolve_boolean_setting({}, "my.setting", default=False) is False+ assert (+ resolve_boolean_setting(+ {"my.setting": None}, "my.setting", default=False+ )+ is False+ )++class TestOverlaySnapshotValue:def test_preserves_envelope_metadata(self):from local_deep_research.utilities.type_utils import (diff --git a/tests/web_search_engines/engines/test_full_search.py b/tests/web_search_engines/engines/test_full_search.pyindex 626b6f5d34..ca625a2b25 100644--- a/tests/web_search_engines/engines/test_full_search.py+++ b/tests/web_search_engines/engines/test_full_search.py@@ -686,6 +686,296 @@ class TestFullSearchResultsClose:mock_web_search.close.assert_called_once()+class TestFullSearchResultsQualityCheckUrls:+ """Tests for honoring search.quality_check_urls from settings_snapshot."""++ def test_run_skips_url_filtering_when_quality_check_urls_disabled_in_snapshot(+ self,+ ):+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ "https://example.com/2": "Content 2",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot={+ "search.quality_check_urls": {"value": False}+ },+ )+ results = engine.run("test query")++ # check_urls LLM invoke should be skipped entirely+ mock_llm.invoke.assert_not_called()+ assert len(results) == 2++ def test_run_performs_url_filtering_when_quality_check_urls_enabled_in_snapshot(+ self,+ ):+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_llm.invoke.return_value = Mock(content="[0]")+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ False,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot={+ "search.quality_check_urls": {"value": True}+ },+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_called_once()+ assert len(results) == 1++ @pytest.mark.parametrize(+ "raw_value",+ ["false", "False", "FALSE", "0", "no", "off"],+ )+ def test_run_skips_url_filtering_with_falsy_string_values(self, raw_value):+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ for snapshot in [+ {"search.quality_check_urls": raw_value},+ {"search.quality_check_urls": {"value": raw_value}},+ ]:+ mock_llm.reset_mock()+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ "https://example.com/2": "Content 2",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot=snapshot,+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_not_called()+ assert len(results) == 2++ def test_run_skips_url_filtering_via_create_settings_snapshot(self):+ from local_deep_research.api.settings_utils import (+ create_settings_snapshot,+ )+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ snapshot = create_settings_snapshot(+ overrides={"search.quality_check_urls": "false"}+ )++ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ "https://example.com/2": "Content 2",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot=snapshot,+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_not_called()+ assert len(results) == 2++ @pytest.mark.parametrize(+ "raw_value",+ ["true", "True", "1", "yes", "on"],+ )+ def test_run_enables_url_filtering_with_truthy_string_values(+ self, raw_value+ ):+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_llm.invoke.return_value = Mock(content="[0]")+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ for snapshot in [+ {"search.quality_check_urls": raw_value},+ {"search.quality_check_urls": {"value": raw_value}},+ ]:+ mock_llm.reset_mock()+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ False,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot=snapshot,+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_called_once()+ assert len(results) == 1++ def test_run_falls_back_to_quality_check_ddg_urls_without_snapshot(self):+ from local_deep_research.web_search_engines.engines.full_search import (+ FullSearchResults,+ )++ mock_llm = Mock()+ mock_llm.invoke.return_value = Mock(content="[0]")+ mock_web_search = Mock()+ mock_web_search.invoke.return_value = [+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]++ # When QUALITY_CHECK_DDG_URLS is False and settings_snapshot is None -> skip+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ False,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ "https://example.com/2": "Content 2",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot=None,+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_not_called()+ assert len(results) == 2++ # When QUALITY_CHECK_DDG_URLS is True and settings_snapshot is None -> filter+ mock_llm.reset_mock()+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ):+ with patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ },+ ):+ engine = FullSearchResults(+ llm=mock_llm,+ web_search=mock_web_search,+ settings_snapshot=None,+ )+ results = engine.run("test query")++ mock_llm.invoke.assert_called_once()+ assert len(results) == 1++class TestAllowPrivateIps:"""``FullSearchResults`` must accept an ``allow_private_ips`` flag andforward it to every ``validate_url`` call and to the download pipeline,diff --git a/tests/web_search_engines/test_factory_full_search_wrapper.py b/tests/web_search_engines/test_factory_full_search_wrapper.pyindex bf3c045a61..b043cde82a 100644--- a/tests/web_search_engines/test_factory_full_search_wrapper.py+++ b/tests/web_search_engines/test_factory_full_search_wrapper.py@@ -99,6 +99,15 @@ class _FakeWrapperWithApiKey:self.llm = llm+class _FakeWrapperWithSnapshot:+ """Fake wrapper class that accepts settings_snapshot."""++ def __init__(self, llm=None, web_search=None, settings_snapshot=None):+ self.llm = llm+ self.web_search = web_search+ self.settings_snapshot = settings_snapshot++class TestWrapperParameterFiltering:"""Tests for parameter filtering during wrapper creation."""@@ -132,6 +141,32 @@ class TestWrapperParameterFiltering:assert result.llm is mock_llmassert result.web_search is base_engine+ def test_wrapper_forwards_settings_snapshot(self, base_engine, mock_llm):+ """The factory's settings_snapshot argument is forwarded when accepted."""+ engine_config = {+ "full_search_module": ".engines.full_search",+ "full_search_class": "FullSearchResults",+ }+ settings_snapshot = {+ "search.quality_check_urls": {"value": False},+ }++ with patch(+ "local_deep_research.web_search_engines.search_engine_factory.get_safe_module_class",+ return_value=_FakeWrapperWithSnapshot,+ ):+ result = _create_full_search_wrapper(+ "test_engine",+ base_engine,+ engine_config,+ mock_llm,+ {},+ settings_snapshot=settings_snapshot,+ )++ assert isinstance(result, _FakeWrapperWithSnapshot)+ assert result.settings_snapshot is settings_snapshot+class TestApiKeyExtraction:"""Tests for API key extraction from settings snapshots."""@@ -512,6 +547,94 @@ class TestRegistryFullSearchWrapperEndToEnd:assert not isinstance(result, FullSearchResults)+ def _quality_check_disabled_snapshot(self, engine_name):+ return {+ "search.tool": {"value": engine_name},+ "search.snippets_only": {"value": False},+ "search.quality_check_urls": {"value": False},+ f"search.engine.web.{engine_name}.supports_full_search": {+ "value": True,+ "ui_element": "checkbox",+ },+ f"search.engine.web.{engine_name}.api_key": {+ "value": "mock-api-key"+ },+ }++ def _assert_factory_wrapper_skips_url_filter(+ self, wrapper, snapshot, mock_llm+ ):+ """Run the real FullSearchResults path and require the LLM URL filter off."""+ assert isinstance(wrapper, FullSearchResults)+ assert wrapper.settings_snapshot is snapshot++ wrapper.web_search.invoke = Mock(+ return_value=[+ {"link": "https://example.com/1", "title": "Result 1"},+ {"link": "https://example.com/2", "title": "Result 2"},+ ]+ )+ mock_llm.reset_mock()++ with (+ patch(+ "local_deep_research.web_search_engines.engines.full_search.QUALITY_CHECK_DDG_URLS",+ True,+ ),+ patch(+ "local_deep_research.web_search_engines.engines.full_search.validate_url",+ return_value=True,+ ),+ patch(+ "local_deep_research.web_search_engines.engines.full_search.batch_fetch_and_extract",+ return_value={+ "https://example.com/1": "Content 1",+ "https://example.com/2": "Content 2",+ },+ ),+ ):+ results = wrapper.run("test query")++ mock_llm.invoke.assert_not_called()+ assert len(results) == 2++ def test_get_search_quality_check_urls_false_skips_llm_filter(+ self, mock_llm+ ):+ """get_search must forward the snapshot so quality_check_urls=False works."""+ engine_name = "searxng"+ settings_snapshot = self._quality_check_disabled_snapshot(engine_name)++ wrapper = get_search(+ search_tool=engine_name,+ llm_instance=mock_llm,+ search_snippets_only=False,+ settings_snapshot=settings_snapshot,+ programmatic_mode=True,+ )++ self._assert_factory_wrapper_skips_url_filter(+ wrapper, settings_snapshot, mock_llm+ )++ def test_create_search_engine_quality_check_urls_false_skips_llm_filter(+ self, mock_llm+ ):+ """create_search_engine must forward the snapshot so the toggle works."""+ engine_name = "searxng"+ settings_snapshot = self._quality_check_disabled_snapshot(engine_name)++ wrapper = create_search_engine(+ engine_name,+ llm=mock_llm,+ settings_snapshot=settings_snapshot,+ programmatic_mode=True,+ )++ self._assert_factory_wrapper_skips_url_filter(+ wrapper, settings_snapshot, mock_llm+ )+def test_searxng_keeps_provider_code_off_wrapper_language(self, mock_llm):settings_snapshot = {"search.tool": {"value": "searxng"},