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(searxng): expose engines setting to restrict searches to specific SearXNG engines (#5622)

LearningCircuit7d06671431b2
diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md
index 9221b99aaf..8ac3ed409a 100644
--- a/docs/CONFIGURATION.md
+++ b/docs/CONFIGURATION.md
@@ -439,6 +439,7 @@ They are not available in the Web UI because they are needed to start the applic
| `search.engine.web.searxng.agent_enabled` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_AGENT_ENABLED` | `true` | Include SearXNG as a specialized tool for the langgraph research agent. The engine selected as `search.tool` always keeps its generic web_search tool — this flag only controls additional specialized tools. Independent of egress; the per-collection 'available to the research agent' toggle still wins for collections. | SEARCH |
| `search.engine.web.searxng.default_params.categories` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_CATEGORIES` | ``["general"]`` | SearXNG search categories to use (general, images, videos, news, music, files, etc.). | SEARCH |
| `search.engine.web.searxng.default_params.delay_between_requests` | `SEARXNG_DELAY` | `0` | Seconds to wait between SearXNG requests. Set higher values to avoid rate limiting on public instances. | SEARCH |
+| `search.engine.web.searxng.default_params.engines` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_ENGINES` | ``[]`` | Optional list of SearXNG engines to restrict searches to (e.g. ["kagi", "brave", "wikipedia", "arxiv"] — this field is JSON, so the names must be double-quoted). When empty (default), SearXNG uses all of its own configured engines. Names must match the engines enabled on your SearXNG instance — see /engines on the instance for the full list. | SEARCH |
| `search.engine.web.searxng.default_params.include_full_content` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INCLUDE_FULL_CONTENT` | `true` | Fetch full webpage content for SearXNG results, not just snippets. | SEARCH |
| `search.engine.web.searxng.default_params.instance_url` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL` | `http://localhost:8080` | The SearXNG API endpoint URL. A private / loopback / link-local URL (including the default http://localhost:8080) is only fetched when the operator lists its origin in LDR_SEARCH_PRIVATE_ENGINE_URL_ALLOWLIST, sets LDR_SEARCH_ALLOW_PRIVATE_ENGINE_URLS=true, or env-locks this URL via LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_INSTANCE_URL; otherwise the engine disables itself. Cloud-metadata addresses are always blocked. | SEARCH |
| `search.engine.web.searxng.default_params.language` | `LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_LANGUAGE` | `en` | Language code for SearXNG results (e.g., 'en', 'de', 'fr'). | SEARCH |
diff --git a/docs/SearXNG-Setup.md b/docs/SearXNG-Setup.md
index 68754bc236..506cbaddea 100644
--- a/docs/SearXNG-Setup.md
+++ b/docs/SearXNG-Setup.md
@@ -65,6 +65,19 @@ You have two ways to configure the SearXNG instance URL:
`LDR_SEARCH_ALLOW_PRIVATE_ENGINE_URLS=true` (see the callout at the top
of this page).
+### Restricting to Specific SearXNG Engines
+
+By default SearXNG queries all engines enabled on your instance. If you want LDR to only use a subset (for example, only `kagi`, `brave`, `wikipedia`, and `arxiv`), set the `engines` parameter via the web UI **Settings → SearXNG → Engines** or via environment variable:
+
+```bash
+# Comma-separated engine names matching your SearXNG instance's /engines list
+LDR_SEARCH_ENGINE_WEB_SEARXNG_DEFAULT_PARAMS_ENGINES='["kagi", "brave", "wikipedia", "arxiv"]'
+```
+
+LDR forwards this list as SearXNG's `engines` query parameter for every search. Leave it empty (the default) to use all engines configured on the instance. Engine names must match those listed at `<your-searxng-instance>/engines`; unknown names are ignored by SearXNG and yield no results from that engine.
+
+This is useful for splitting research across engine profiles (e.g. a free-only profile for routine queries and a premium-engines profile for important research) — change the setting before starting a research session to switch profiles.
+
## Self-Hosting SearXNG (Recommended)
For the most ethical usage, we strongly recommend self-hosting your own SearXNG instance:
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 8822626459..a60f72a5bd 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -2674,6 +2674,20 @@
"value": 0,
"visible": true
},
+ "search.engine.web.searxng.default_params.engines": {
+ "category": "searxng",
+ "description": "Optional list of SearXNG engines to restrict searches to (e.g. [\"kagi\", \"brave\", \"wikipedia\", \"arxiv\"] — this field is JSON, so the names must be double-quoted). When empty (default), SearXNG uses all of its own configured engines. Names must match the engines enabled on your SearXNG instance — see /engines on the instance for the full list.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Engines",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "json",
+ "value": [],
+ "visible": true
+ },
"search.engine.web.searxng.default_params.include_full_content": {
"category": "searxng",
"description": "Fetch full webpage content for SearXNG results, not just snippets.",
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py
index 16293efb0d..2deceeb8b5 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py
@@ -54,13 +54,22 @@ class SearXNGSearchEngine(BaseSearchEngine):
url_setting = "search.engine.web.searxng.default_params.instance_url"
@staticmethod
- def _normalize_list(value):
+ def _normalize_list(value, *, setting_name: str = "list setting"):
"""Ensure *value* is a ``list[str]`` or ``None``.
Settings saved via the web UI may arrive as raw JSON strings
(e.g. ``'[\\r\\n "general"\\r\\n]'``) instead of parsed lists.
This helper decodes such strings so that ``",".join()`` later
works on list items rather than individual characters (issue #1030).
+
+ Input that is neither valid JSON nor a plain comma-separated list
+ still produces a list, because the comma fallback splits whatever it
+ is given. That is right for ``kagi,brave`` and wrong for
+ ``['kagi', 'brave']``, which yields ``["['kagi'", "'brave']"]`` --
+ names no engine matches, so the filter silently selects nothing while
+ looking configured. Warn when the input was evidently meant to be
+ JSON, so the failure is visible rather than inferred from empty
+ results.
"""
if value is None:
return None
@@ -74,7 +83,18 @@ class SearXNGSearchEngine(BaseSearchEngine):
if isinstance(parsed, list):
return [str(item) for item in parsed]
except (json.JSONDecodeError, ValueError, RecursionError):
- pass
+ # Only a bracketed/braced value was *trying* to be JSON.
+ # Genuine comma-separated input takes this path too and
+ # is not a mistake, so it must not warn.
+ if stripped[0] in "[{":
+ logger.warning(
+ "{} is not valid JSON ({!r}); falling back to "
+ "comma-splitting, which keeps brackets and quotes "
+ "as part of each entry. Use double-quoted JSON, "
+ 'e.g. ["kagi", "brave"].',
+ setting_name,
+ stripped[:100],
+ )
# Comma-separated fallback
return [
item.strip() for item in stripped.split(",") if item.strip()
@@ -249,8 +269,12 @@ class SearXNGSearchEngine(BaseSearchEngine):
)
self.max_results = max_results
- self.categories = self._normalize_list(categories) or ["general"]
- self.engines = self._normalize_list(engines)
+ self.categories = self._normalize_list(
+ categories, setting_name="SearXNG categories"
+ ) or ["general"]
+ self.engines = self._normalize_list(
+ engines, setting_name="SearXNG engines"
+ )
self.language = language
try:
# Handle both string names and integer values
diff --git a/tests/settings/golden_master_settings.json b/tests/settings/golden_master_settings.json
index 7a20dde509..7bbaf3dcce 100644
--- a/tests/settings/golden_master_settings.json
+++ b/tests/settings/golden_master_settings.json
@@ -6030,6 +6030,20 @@
"value": 0,
"visible": true
},
+ "search.engine.web.searxng.default_params.engines": {
+ "category": "searxng",
+ "description": "Optional list of SearXNG engines to restrict searches to (e.g. [\"kagi\", \"brave\", \"wikipedia\", \"arxiv\"] — this field is JSON, so the names must be double-quoted). When empty (default), SearXNG uses all of its own configured engines. Names must match the engines enabled on your SearXNG instance — see /engines on the instance for the full list.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Engines",
+ "options": null,
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "json",
+ "value": [],
+ "visible": true
+ },
"search.engine.web.searxng.default_params.include_full_content": {
"category": "searxng",
"description": "Fetch full webpage content for SearXNG results, not just snippets.",
diff --git a/tests/web_search_engines/engines/test_search_engine_searxng.py b/tests/web_search_engines/engines/test_search_engine_searxng.py
index 60065a9fe0..a54faf26c5 100644
--- a/tests/web_search_engines/engines/test_search_engine_searxng.py
+++ b/tests/web_search_engines/engines/test_search_engine_searxng.py
@@ -1034,6 +1034,238 @@ class TestGetSearchResults:
== expected_count_param
)
+ def test_engines_param_sent_to_searxng(self):
+ """Engines list is forwarded to SearXNG as the ``engines`` query param."""
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ html_content = """
+ <html>
+ <body>
+ <article class="result">
+ <h3><a href="https://example.com/page1">Result 1</a></h3>
+ <p class="content">First valid result.</p>
+ </article>
+ </body>
+ </html>
+ """
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.safe_get"
+ ) as mock_get:
+ mock_response_init = Mock()
+ mock_response_init.status_code = 200
+ mock_response_init.cookies = {}
+
+ mock_response_search = Mock()
+ mock_response_search.status_code = 200
+ mock_response_search.text = html_content
+ mock_response_search.cookies = {}
+
+ mock_get.side_effect = [
+ mock_response_init,
+ mock_response_init,
+ mock_response_search,
+ ]
+
+ engine = SearXNGSearchEngine(
+ instance_url="http://localhost:8080",
+ engines=["kagi", "brave"],
+ )
+
+ engine._get_search_results("test query")
+
+ search_params = mock_get.call_args_list[-1].kwargs["params"]
+ assert search_params["engines"] == "kagi,brave"
+
+ def test_no_engines_param_when_unset(self):
+ """When engines is empty (default), the ``engines`` key is omitted."""
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ html_content = """
+ <html>
+ <body>
+ <article class="result">
+ <h3><a href="https://example.com/page1">Result 1</a></h3>
+ <p class="content">First valid result.</p>
+ </article>
+ </body>
+ </html>
+ """
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.safe_get"
+ ) as mock_get:
+ mock_response_init = Mock()
+ mock_response_init.status_code = 200
+ mock_response_init.cookies = {}
+
+ mock_response_search = Mock()
+ mock_response_search.status_code = 200
+ mock_response_search.text = html_content
+ mock_response_search.cookies = {}
+
+ mock_get.side_effect = [
+ mock_response_init,
+ mock_response_init,
+ mock_response_search,
+ ]
+
+ engine = SearXNGSearchEngine(instance_url="http://localhost:8080")
+
+ engine._get_search_results("test query")
+
+ search_params = mock_get.call_args_list[-1].kwargs["params"]
+ assert "engines" not in search_params
+
+ def test_engines_accepts_json_string_from_settings(self):
+ """JSON-encoded string (as saved via the settings UI) is normalized to a list.
+
+ ``ui_element: 'json'`` settings are stored as JSON text in the DB;
+ ``_normalize_list`` must parse that form so the value reaches the
+ SearXNG ``engines`` query param correctly via the factory.
+ """
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.safe_get"
+ ) as mock_get:
+ mock_response = Mock()
+ mock_response.status_code = 200
+ mock_get.return_value = mock_response
+
+ engine = SearXNGSearchEngine(
+ instance_url="http://localhost:8080",
+ engines='["kagi", "brave", "wikipedia"]',
+ )
+
+ assert engine.engines == ["kagi", "brave", "wikipedia"]
+
+ def test_single_quoted_engines_do_not_silently_filter_nothing(self):
+ """Python-style quoting must not become four junk engine names.
+
+ ``ui_element: 'json'`` means the field is parsed with ``json.loads``,
+ which rejects single quotes. ``_normalize_list`` then falls through to
+ its comma-separated branch, which splits the raw text on commas and
+ keeps the brackets and quotes as part of each name -- so
+ ``['kagi', 'brave']`` becomes ``["['kagi'", "'brave']"]`` and SearXNG
+ matches none of them. The user believes they restricted the search and
+ instead every engine is queried. ``_normalize_list`` now warns when
+ the input was evidently meant to be JSON -- see
+ ``test_json_shaped_input_warns_before_falling_back`` -- but the
+ parsed value is deliberately unchanged.
+
+ This pins the failure mode rather than the fix: the setting's own
+ description used to show the single-quoted form, so this was the
+ documented path. If ``_normalize_list`` is ever taught to accept the
+ Python form, or to reject unparseable input loudly, this test should
+ change deliberately -- not silently.
+ """
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ # The safe_get patch is required, not decorative: __init__ performs an
+ # availability probe, so an unpatched construction would reach the
+ # network.
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.safe_get"
+ ) as mock_get:
+ mock_response = Mock()
+ mock_response.status_code = 200
+ mock_get.return_value = mock_response
+
+ engine = SearXNGSearchEngine(
+ instance_url="http://localhost:8080",
+ engines="['kagi', 'brave']",
+ )
+
+ # Not a useful engine list -- every entry carries stray punctuation.
+ assert engine.engines == ["['kagi'", "'brave']"]
+ assert not any(name in ("kagi", "brave") for name in engine.engines)
+
+ def test_documented_example_parses_to_real_engine_names(self):
+ """The example in the setting description must actually work.
+
+ Guards the description itself: this is the exact string the settings
+ UI and CONFIGURATION.md tell the user to paste.
+ """
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.safe_get"
+ ) as mock_get:
+ mock_response = Mock()
+ mock_response.status_code = 200
+ mock_get.return_value = mock_response
+
+ engine = SearXNGSearchEngine(
+ instance_url="http://localhost:8080",
+ engines='["kagi", "brave", "wikipedia", "arxiv"]',
+ )
+
+ assert engine.engines == ["kagi", "brave", "wikipedia", "arxiv"]
+
+ def test_json_shaped_input_warns_before_falling_back(self):
+ """A value that tried to be JSON and failed must not fail silently.
+
+ The comma fallback turns ``['kagi', 'brave']`` into names carrying
+ brackets and quotes, which no engine matches -- so the search is
+ silently unrestricted. Warning is the whole point: without it the only
+ symptom is results that look untouched.
+ """
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.logger"
+ ) as mock_logger:
+ result = SearXNGSearchEngine._normalize_list(
+ "['kagi', 'brave']", setting_name="SearXNG engines"
+ )
+
+ assert result == ["['kagi'", "'brave']"]
+ assert mock_logger.warning.called
+ message = mock_logger.warning.call_args.args[0]
+ assert "not valid JSON" in message
+ assert "SearXNG engines" in mock_logger.warning.call_args.args
+
+ @pytest.mark.parametrize(
+ "value",
+ [
+ "kagi,brave", # genuine comma-separated input
+ "kagi", # a single bare name
+ '["kagi", "brave"]', # valid JSON
+ ],
+ )
+ def test_valid_input_does_not_warn(self, value):
+ """Only JSON-shaped failures warn.
+
+ Comma-separated input is a supported form, not a mistake. Warning on
+ it would train operators to ignore the message, which costs more than
+ the warning is worth.
+ """
+ from local_deep_research.web_search_engines.engines.search_engine_searxng import (
+ SearXNGSearchEngine,
+ )
+
+ with patch(
+ "local_deep_research.web_search_engines.engines.search_engine_searxng.logger"
+ ) as mock_logger:
+ SearXNGSearchEngine._normalize_list(
+ value, setting_name="SearXNG engines"
+ )
+
+ assert not mock_logger.warning.called
+
class TestGetPreviews:
"""Tests for _get_previews method."""