~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(egress): route RAG-indexing + SBERT embeddings PEPs through resolve_run_primary_engine (#4753)
LearningCircuitfb785edacb9c
diff --git a/src/local_deep_research/embeddings/providers/implementations/sentence_transformers.py b/src/local_deep_research/embeddings/providers/implementations/sentence_transformers.pyindex 860c799199..70d01e5ea9 100644--- a/src/local_deep_research/embeddings/providers/implementations/sentence_transformers.py+++ b/src/local_deep_research/embeddings/providers/implementations/sentence_transformers.py@@ -7,7 +7,6 @@ from loguru import loggerfrom ....config.thread_settings import get_setting_from_snapshotfrom ..base import BaseEmbeddingProvider-from ....constants import DEFAULT_SEARCH_TOOLclass SentenceTransformersProvider(BaseEmbeddingProvider):@@ -108,29 +107,24 @@ class SentenceTransformersProvider(BaseEmbeddingProvider):require_local = Falseif settings_snapshot is not None:try:- from ....security.egress.policy import context_from_snapshot-- _primary = (- get_setting_from_snapshot(- "search.tool",- default=DEFAULT_SEARCH_TOOL,- settings_snapshot=settings_snapshot,- )- or DEFAULT_SEARCH_TOOL+ from ....security.egress.policy import (+ context_from_snapshot,+ resolve_run_primary_engine,)++ # Single source of truth for the primary (was: search.tool ++ # searxng fallback, a fail-OPEN that could permit a remote model+ # download for a primary-less private run).+ _primary = resolve_run_primary_engine(settings_snapshot)require_local = context_from_snapshot(settings_snapshot, _primary).require_local_embeddingsexcept ValueError:- # No usable snapshot for context construction; fall back to- # the raw flag (still honours an explicit opt-in).- require_local = bool(- get_setting_from_snapshot(- "embeddings.require_local",- default=False,- settings_snapshot=settings_snapshot,- )- )+ # No usable primary / invalid scope: fail CLOSED to local-only+ # (block any remote model download) rather than reading the raw+ # opt-in flag. The get_embeddings PEP already refuses a+ # primary-less snapshot upstream, so this is defense-in-depth.+ require_local = Truemodel_kwargs = {"device": device}if require_local:if not cls._is_model_cached_locally(model):diff --git a/src/local_deep_research/research_library/services/library_rag_service.py b/src/local_deep_research/research_library/services/library_rag_service.pyindex f86caffb75..41e2904ce2 100644--- a/src/local_deep_research/research_library/services/library_rag_service.py+++ b/src/local_deep_research/research_library/services/library_rag_service.py@@ -41,7 +41,6 @@ from faiss import IndexFlatL2, IndexFlatIP, IndexHNSWFlatfrom langchain_community.vectorstores import FAISSfrom langchain_community.docstore.in_memory import InMemoryDocstorefrom .faiss_safe_load import safe_load_faiss-from ...constants import DEFAULT_SEARCH_TOOL# Module-level locks serialise the FAISS save+record critical section and the@@ -209,22 +208,20 @@ class LibraryRAGService:PolicyDeniedError,context_from_snapshot,evaluate_embeddings,- _get_setting_value,+ resolve_run_primary_engine,)# Build the context from the ACTUAL scope (not a hardcoded# BOTH) so PRIVATE_ONLY forces local embeddings even when the# raw embeddings.require_local flag is at its default False —- # context_from_snapshot applies that coupling. The previous- # code both hardcoded scope=BOTH and gated on the raw flag, so- # a PRIVATE_ONLY corpus could be embedded by a cloud provider.- primary = (- _get_setting_value(- settings_snapshot, "search.tool", DEFAULT_SEARCH_TOOL- )- or DEFAULT_SEARCH_TOOL- )+ # context_from_snapshot applies that coupling. Resolve the primary+ # via the shared helper (single source of truth) instead of the old+ # search.tool + searxng fallback, which was a fail-OPEN: a missing+ # primary defaulted to the public searxng so the scope relaxed and a+ # cloud embedder could be admitted. A missing primary now raises ->+ # fail closed via the ValueError handler below.try:+ primary = resolve_run_primary_engine(settings_snapshot)policy_ctx = context_from_snapshot(settings_snapshot, primary, username=username)diff --git a/tests/embeddings/test_sentence_transformers.py b/tests/embeddings/test_sentence_transformers.pyindex 7620b7121f..cf24df9b86 100644--- a/tests/embeddings/test_sentence_transformers.py+++ b/tests/embeddings/test_sentence_transformers.py@@ -222,7 +222,13 @@ class TestSentenceTransformersProviderCreateEmbeddings:)mock_embeddings = MagicMock()- settings = {"embeddings.sentence_transformers.model": "custom-model"}+ # search.tool present => a public primary resolves PUBLIC_ONLY+ # => require_local stays off, so this model-reading test is not+ # diverted into the require-local download guard.+ settings = {+ "embeddings.sentence_transformers.model": "custom-model",+ "search.tool": "searxng",+ }def mock_get_setting(key, default=None, settings_snapshot=None):if key == "embeddings.sentence_transformers.model":diff --git a/tests/research_library/services/test_library_rag_service.py b/tests/research_library/services/test_library_rag_service.pyindex 4571499827..e9449f1770 100644--- a/tests/research_library/services/test_library_rag_service.py+++ b/tests/research_library/services/test_library_rag_service.py@@ -24,7 +24,9 @@ class TestLibraryRAGServiceInit:# Mock settings managermock_settings_manager = Mock()- mock_settings_manager.get_settings_snapshot.return_value = {}+ mock_settings_manager.get_settings_snapshot.return_value = {+ "search.tool": "searxng"+ }mocker.patch("local_deep_research.settings.manager.SettingsManager",return_value=mock_settings_manager,@@ -80,7 +82,9 @@ class TestLibraryRAGServiceInit:# Mock settings managermock_settings_manager = Mock()- mock_settings_manager.get_settings_snapshot.return_value = {}+ mock_settings_manager.get_settings_snapshot.return_value = {+ "search.tool": "searxng"+ }mocker.patch("local_deep_research.settings.manager.SettingsManager",return_value=mock_settings_manager,