~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
refactor(engines): route search-engine LLM utilities through the shared sync helper — tranche 6 of #5854 (#6286)
LearningCircuit939b51b7f074
diff --git a/changelog.d/6286.misc.md b/changelog.d/6286.misc.mdnew file mode 100644index 0000000000..d9a4b30923--- /dev/null+++ b/changelog.d/6286.misc.md@@ -0,0 +1 @@+Search-engine query optimizers, the full-text search URL quality filter, report generation, domain classification and in-process document analysis now use the shared synchronous LLM dispatcher. Prompt forwarding, response parsing and exception handling are preserved.diff --git a/docs/developing/resource-cleanup.md b/docs/developing/resource-cleanup.mdindex f7cf0fc30c..d7a0f1fd07 100644--- a/docs/developing/resource-cleanup.md+++ b/docs/developing/resource-cleanup.md@@ -408,8 +408,9 @@ the underlying `ollama` / `httpx` clients, so dropping the Pythonreference does not release the FDs.`_close_base_llm` already handled the shape — its module-prefix checks-(`type(...).__module__.startswith("ollama")` at-`src/local_deep_research/utilities/llm_utils.py:97,114`) match+(`type(...).__module__.startswith("ollama")` in+`src/local_deep_research/utilities/llm_utils.py`, in the sync-side and+async-side branches of `_close_base_llm`) match`ollama.Client` / `ollama.AsyncClient` regardless of which langchainwrapper holds them. The function just wasn't called on embeddingsinstances — `LocalEmbeddingManager.close()` and `LibraryRAGService.close()`diff --git a/src/local_deep_research/api/research_functions.py b/src/local_deep_research/api/research_functions.pyindex b1f6cdc6ac..bbf124248d 100644--- a/src/local_deep_research/api/research_functions.py+++ b/src/local_deep_research/api/research_functions.py@@ -17,6 +17,7 @@ from ..search_system import AdvancedSearchSystemfrom ..utilities.db_utils import no_db_settingsfrom ..utilities.thread_context import clear_search_context, set_search_contextfrom .settings_utils import create_settings_snapshot+from ..utilities.llm_utils import invoke_llm_syncdef _close_system(system):@@ -728,7 +729,7 @@ def analyze_documents(f"Starting LLM summary generation (prompt length: {len(summary_prompt)} chars)...")- summary_response = llm.invoke(summary_prompt)+ summary_response = invoke_llm_sync(llm, summary_prompt)llm_elapsed = time.time() - llm_start_timelogger.info(f"LLM summary generation completed in {llm_elapsed:.2f}s")diff --git a/src/local_deep_research/domain_classifier/classifier.py b/src/local_deep_research/domain_classifier/classifier.pyindex e05477fe5c..edf9b227c7 100644--- a/src/local_deep_research/domain_classifier/classifier.py+++ b/src/local_deep_research/domain_classifier/classifier.py@@ -12,6 +12,7 @@ from ..database.session_context import get_user_db_sessionfrom ..utilities.sql_utils import escape_like as _escape_likefrom ..utilities.json_utils import extract_json, get_llm_response_textfrom .models import DomainClassification+from ..utilities.llm_utils import invoke_llm_sync# Predefined categories for domain classification@@ -237,7 +238,7 @@ JSON Response:"""prompt = self._build_classification_prompt(domain, samples)llm = self._get_llm()- response = llm.invoke(prompt)+ response = invoke_llm_sync(llm, prompt)response_text = get_llm_response_text(response)result = extract_json(response_text, expected_type=dict)diff --git a/src/local_deep_research/report_generator.py b/src/local_deep_research/report_generator.pyindex f57ce069fa..feb41bee9a 100644--- a/src/local_deep_research/report_generator.py+++ b/src/local_deep_research/report_generator.py@@ -14,6 +14,7 @@ from .text_optimization.citation_formatter import (LDR_APPENDED_SOURCES_SENTINEL,)from .utilities.json_utils import get_llm_response_text+from .utilities.llm_utils import invoke_llm_sync# Default constants for context accumulation to avoid repetition# These are used as fallbacks when settings are not available@@ -452,7 +453,7 @@ class IntegratedReportGenerator:DO NOT include sections about sources, citations, references, or methodology."""- response = get_llm_response_text(self.model.invoke(prompt))+ response = get_llm_response_text(invoke_llm_sync(self.model, prompt))# Parse the structurestructure: List[Dict[str, Any]] = []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 c8b9f33da0..06f6180828 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@@ -15,6 +15,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.llm_utils import invoke_llm_sync@runtime_checkable@@ -170,7 +171,9 @@ class FullSearchResults:try:if self.llm is None:return results- return self._keep_selected(results, self.llm.invoke(prompt))+ return self._keep_selected(+ results, invoke_llm_sync(self.llm, prompt)+ )except PolicyDeniedError:# The URL-quality LLM was denied by egress policy (e.g. a cloud# LLM under require_local / PRIVATE_ONLY). Do NOT fall through todiff --git a/src/local_deep_research/web_search_engines/engines/search_engine_github.py b/src/local_deep_research/web_search_engines/engines/search_engine_github.pyindex 6547ba56c0..d38dd039b7 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_github.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_github.py@@ -11,6 +11,7 @@ from ...constants import USER_AGENTfrom ...security.safe_requests import safe_getfrom ...utilities.json_utils import extract_json, get_llm_response_textfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivity+from ...utilities.llm_utils import invoke_llm_sync_VALID_SEARCH_TYPES = frozenset({"repositories", "code", "issues", "users"})@@ -161,7 +162,7 @@ class GitHubSearchEngine(BaseSearchEngine):Return ONLY the optimized query, ready for GitHub's search API. Do not include explanations or additional text."""try:- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)optimized_query = get_llm_response_text(response).strip()@@ -918,7 +919,7 @@ Example: [0, 2, 1, 3]Do not include any other text or explanation."""try:- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)response_text = get_llm_response_text(response)ranked_indices = extract_json(response_text, expected_type=list)diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.pyindex dcb48af1c8..5aa630ff74 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py@@ -8,6 +8,7 @@ from ...utilities.search_utilities import remove_think_tagsfrom ...security.safe_requests import safe_getfrom ..rate_limiting import RateLimitErrorfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivity+from ...utilities.llm_utils import invoke_llm_syncclass GuardianSearchEngine(BaseSearchEngine):@@ -139,7 +140,7 @@ Return ONLY the extremely brief search query."""# Get response from LLM- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)optimized_query = remove_think_tags(str(response.content)if hasattr(response, "content")@@ -209,7 +210,7 @@ ONE WORD ANSWER ONLY:ONE WORD ONLY:"""- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)answer = (remove_think_tags(str(response.content)diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_paperless.py b/src/local_deep_research/web_search_engines/engines/search_engine_paperless.pyindex 1834322db2..cbfab60113 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_paperless.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_paperless.py@@ -16,6 +16,7 @@ from ...security.secure_logging import loggerfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivityfrom ...security import redact_url_for_log, safe_get+from ...utilities.llm_utils import invoke_llm_syncclass PaperlessSearchEngine(BaseSearchEngine):@@ -217,7 +218,7 @@ IMPORTANT: Output ONLY the search query. No explanations, no additional text."""logger.debug(f"Sending query expansion prompt to LLM ({len(query)} chars)")- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)expanded = (str(response.content)if hasattr(response, "content")diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.pyindex 4164a4d562..3ce2fbc9c6 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py@@ -10,6 +10,7 @@ from ...security.safe_requests import safe_getfrom ...security.secure_logging import loggerfrom ..rate_limiting import RateLimitErrorfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivity+from ...utilities.llm_utils import invoke_llm_syncclass PubMedSearchEngine(BaseSearchEngine):@@ -270,7 +271,7 @@ Return ONLY the search query without any explanations."""# Get response from LLM- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)raw_response = (str(response.content)if hasattr(response, "content")@@ -497,7 +498,7 @@ Answer ONLY "no" if the query is asking about recent, current, or new informatioThe default assumption should be that medical and scientific queries want RECENT information unless clearly specified otherwise."""- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)answer = ((str(response.content)diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.pyindex 28bba2fe45..6e991ecde1 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py@@ -11,6 +11,7 @@ from ...constants import SNIPPET_LENGTH_SHORTfrom ..rate_limiting import RateLimitErrorfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivityfrom ...security import SafeSession+from ...utilities.llm_utils import invoke_llm_syncclass SemanticScholarSearchEngine(BaseSearchEngine):@@ -291,7 +292,7 @@ EXAMPLE TRANSFORMATIONS:Return ONLY the optimized search query with no explanation."""- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)optimized_query = (str(response.content)if hasattr(response, "content")@@ -432,7 +433,7 @@ Please provide THREE alternative search queries that:Format each query on a new line with no numbering or explanation. Keep each query under 8 words and very focused."""# Get the LLM's response- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)# Extract the alternative queriesalt_queries = []diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py b/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.pyindex 3dc645deea..dd371cd473 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_wikinews.py@@ -13,6 +13,7 @@ from ...utilities.json_utils import extract_json, get_llm_response_textfrom ...utilities.search_utilities import remove_think_tags, LANGUAGE_CODE_MAPfrom ..search_engine_base import BaseSearchEngine, Exposure, Sensitivityfrom ...security import safe_get+from ...utilities.llm_utils import invoke_llm_syncHEADERS = {"User-Agent": USER_AGENT}WIKINEWS_LANGUAGES = [@@ -168,7 +169,7 @@ EXAMPLES:NOW RETURN ONLY THE JSON OBJECT."""# Get response from LLM- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)response_text = get_llm_response_text(response)data = extract_json(response_text, expected_type=dict)@@ -231,7 +232,7 @@ Classification rules:Respond with ONE WORD ONLY: CURRENT, HISTORICAL, or UNCLEAR"""# Get response from LLM- response = self.llm.invoke(prompt)+ response = invoke_llm_sync(self.llm, prompt)response_text = (getattr(response, "content", None)or getattr(response, "text", None)diff --git a/tests/web_search_engines/test_search_engine_base_query_logging.py b/tests/web_search_engines/test_search_engine_base_query_logging.pyindex be3135f438..4aa1650fd8 100644--- a/tests/web_search_engines/test_search_engine_base_query_logging.py+++ b/tests/web_search_engines/test_search_engine_base_query_logging.py@@ -171,7 +171,7 @@ def test_semantic_scholar_fallback_ladder_omits_every_query_term():Revert that fails this test: restore``logger.info("Trying with single key term: {}", longest_word)`` at- ``search_engine_semantic_scholar.py:494``.+ ``search_engine_semantic_scholar.py:495``."""engine = SemanticScholarSearchEngine.__new__(SemanticScholarSearchEngine)# No LLM: _optimize_query returns the raw user query unchanged, which is