~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: deduplicate Ollama close logic into shared _close_base_llm helper
LearningCircuit57800e1a33fe
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.pyindex fab453f336..73e36333e7 100644--- a/src/local_deep_research/config/llm_config.py+++ b/src/local_deep_research/config/llm_config.py@@ -1032,23 +1032,11 @@ def wrap_llm_without_think_tags(return getattr(self.base_llm, name)def close(self):- """Close underlying HTTP clients held by this LLM. Idempotent.-- Only ChatOllama creates per-instance httpx.Client objects that- need explicit close(). ChatAnthropic uses @lru_cache'd shared- httpx clients that must NOT be closed.- """+ """Close underlying HTTP clients held by this LLM. Idempotent."""try:- base = self.base_llm- ollama_client = getattr(base, "_client", None)- if ollama_client is not None:- if not type(ollama_client).__module__.startswith("ollama"):- return- httpx_client = getattr(ollama_client, "_client", None)- if httpx_client is not None and hasattr(- httpx_client, "close"- ):- httpx_client.close()+ from ..utilities.llm_utils import _close_base_llm++ _close_base_llm(self.base_llm)except Exception:passdiff --git a/src/local_deep_research/utilities/llm_utils.py b/src/local_deep_research/utilities/llm_utils.pyindex e8a400b84a..c31ab9e72f 100644--- a/src/local_deep_research/utilities/llm_utils.py+++ b/src/local_deep_research/utilities/llm_utils.py@@ -12,6 +12,28 @@ from typing import Any, Optional, Dictfrom ..config.thread_settings import get_setting_from_snapshot+def _close_base_llm(llm):+ """Close per-instance HTTP clients on a raw LLM. Internal use only.++ Only ChatOllama creates per-instance httpx.Client objects.+ ChatAnthropic and ChatOpenAI use @lru_cache'd shared httpx clients+ that must NOT be closed.+ """+ # If the llm is another wrapper with its own close(), delegate+ if hasattr(type(llm), "close"):+ llm.close()+ return+ # Otherwise introspect for Ollama's per-instance httpx client+ ollama_client = getattr(llm, "_client", None)+ if ollama_client is None:+ return+ if not type(ollama_client).__module__.startswith("ollama"):+ return+ httpx_client = getattr(ollama_client, "_client", None)+ if httpx_client is not None and hasattr(httpx_client, "close"):+ httpx_client.close()++def get_ollama_base_url(settings_snapshot: Optional[Dict[str, Any]] = None,) -> str:diff --git a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.pyindex 21a74852ca..660bb35f30 100644--- a/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py+++ b/src/local_deep_research/web_search_engines/rate_limiting/llm/wrapper.py@@ -199,23 +199,11 @@ def create_rate_limited_llm_wrapper(base_llm, provider: Optional[str] = None):return getattr(self.base_llm, name)def close(self):- """Close underlying HTTP clients held by this LLM. Idempotent.-- Only ChatOllama creates per-instance httpx.Client objects that- need explicit close(). ChatAnthropic uses @lru_cache'd shared- httpx clients that must NOT be closed.- """+ """Close underlying HTTP clients held by this LLM. Idempotent."""try:- base = self.base_llm- ollama_client = getattr(base, "_client", None)- if ollama_client is not None:- if not type(ollama_client).__module__.startswith("ollama"):- return- httpx_client = getattr(ollama_client, "_client", None)- if httpx_client is not None and hasattr(- httpx_client, "close"- ):- httpx_client.close()+ from ....utilities.llm_utils import _close_base_llm++ _close_base_llm(self.base_llm)except Exception:pass