~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): honour snippets_only for library and collection searches (#6325)
Ehsanea72b0b8646d
diff --git a/changelog.d/6179.bugfix.md b/changelog.d/6179.bugfix.mdnew file mode 100644index 0000000000..aa1f9e700d--- /dev/null+++ b/changelog.d/6179.bugfix.md@@ -0,0 +1,13 @@+Turning off "Snippets Only" now takes effect for library and collection+searches. `get_search` never forwarded that setting to the RAG engines, and+`create_search_engine` would have dropped it anyway: it filters its parameters+against each engine class's own `__init__` signature, and neither+`LibraryRAGSearchEngine` nor `CollectionSearchEngine` named the flag, so it+went in through `**kwargs` and out through the filter. `BaseSearchEngine`+defaults it to snippet-only, so those engines never retrieved full content+whatever the setting said. Both constructors now declare and forward it.++The retrieved chunk or document text is also published under `full_content`,+the key the citation handler reads. It previously landed under `content` only,+so the handler fell back to `snippet` and the analysis step saw the first 500+characters of each chunk even when full content had been fetched.diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_collection.py b/src/local_deep_research/web_search_engines/engines/search_engine_collection.pyindex be4320ebab..d941edc347 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_collection.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_collection.py@@ -42,6 +42,7 @@ class CollectionSearchEngine(LibraryRAGSearchEngine):max_filtered_results: Optional[int] = None,max_results: int = 10,settings_snapshot: Optional[Dict[str, Any]] = None,+ search_snippets_only: bool = True,**kwargs,):"""@@ -54,6 +55,8 @@ class CollectionSearchEngine(LibraryRAGSearchEngine):max_filtered_results: Maximum number of results to keep after filteringmax_results: Maximum number of search resultssettings_snapshot: Settings snapshot from thread context+ search_snippets_only: named explicitly because create_search_engine+ filters its params against this signature and drops the rest**kwargs: Additional engine-specific parameters"""super().__init__(@@ -61,6 +64,7 @@ class CollectionSearchEngine(LibraryRAGSearchEngine):max_filtered_results=max_filtered_results,max_results=max_results,settings_snapshot=settings_snapshot,+ search_snippets_only=search_snippets_only,**kwargs,)self.collection_id = collection_iddiff --git a/src/local_deep_research/web_search_engines/engines/search_engine_library.py b/src/local_deep_research/web_search_engines/engines/search_engine_library.pyindex 908a88e8f7..427292e079 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_library.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_library.py@@ -58,6 +58,7 @@ class LibraryRAGSearchEngine(BaseSearchEngine):max_filtered_results: Optional[int] = None,max_results: int = 10,settings_snapshot: Optional[Dict[str, Any]] = None,+ search_snippets_only: bool = True,**kwargs,):"""@@ -68,6 +69,8 @@ class LibraryRAGSearchEngine(BaseSearchEngine):max_filtered_results: Maximum number of results to keep after filteringmax_results: Maximum number of search resultssettings_snapshot: Settings snapshot from thread context+ search_snippets_only: named explicitly because create_search_engine+ filters its params against this signature and drops the rest**kwargs: Additional engine-specific parameters"""super().__init__(@@ -75,6 +78,7 @@ class LibraryRAGSearchEngine(BaseSearchEngine):max_filtered_results=max_filtered_results,max_results=max_results,settings_snapshot=settings_snapshot,+ search_snippets_only=search_snippets_only,**kwargs,)self.username = (@@ -616,6 +620,9 @@ class LibraryRAGSearchEngine(BaseSearchEngine):text = f"Chunk {chunk_idx} not found for document {doc_id}."item["content"] = text+ # BaseCitationHandler reads "full_content" and falls+ # back to the truncated "snippet".+ item["full_content"] = textitem["snippet"] = (text[:SNIPPET_LENGTH_LONG] + "..."if len(text) > SNIPPET_LENGTH_LONG@@ -634,6 +641,7 @@ class LibraryRAGSearchEngine(BaseSearchEngine):if document and document.text_content:# Replace snippet with full contentitem["content"] = document.text_content+ item["full_content"] = document.text_contentitem["snippet"] = (document.text_content[:SNIPPET_LENGTH_LONG]+ "..."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 c2d7ab5320..1b89d98f57 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@@ -5,6 +5,7 @@ from ..security.egress.policy import PolicyDeniedErrorfrom ..security.log_sanitizer import scrub_errorfrom ..security.module_whitelist import get_safe_module_classfrom ..security.secure_logging import logger+from .engine_groups import is_collection_enginefrom .retriever_registry import retriever_registryfrom .search_engine_base import BaseSearchEnginefrom .search_engines_config import search_config@@ -740,6 +741,11 @@ def get_search(.get("value", True))+ if is_collection_engine(search_tool):+ # BaseSearchEngine defaults this to True, so the RAG engines stay+ # snippet-only unless the setting is forwarded here.+ params["search_snippets_only"] = search_snippets_only+if search_tool in TIME_PERIOD_ENGINES:params["time_period"] = time_perioddiff --git a/tests/web_search_engines/engines/test_search_engine_library.py b/tests/web_search_engines/engines/test_search_engine_library.pyindex 8c3a3e8aec..ecb58a4781 100644--- a/tests/web_search_engines/engines/test_search_engine_library.py+++ b/tests/web_search_engines/engines/test_search_engine_library.py@@ -532,6 +532,55 @@ class TestGetFullContent:assert result[0]["content"] == "Specific chunk text content"assert result[0]["snippet"] == "Specific chunk text content"+ def test_get_full_content_publishes_whole_chunk_under_full_content(self):+ """The retrieved chunk reaches the key BaseCitationHandler reads.++ The handler takes result["full_content"] and falls back to the+ truncated result["snippet"], so a chunk longer than SNIPPET_LENGTH_LONG+ is only delivered whole if this key is populated.+ """+ from local_deep_research.constants import SNIPPET_LENGTH_LONG+ from local_deep_research.web_search_engines.engines.search_engine_library import (+ LibraryRAGSearchEngine,+ )++ settings = {"_username": "testuser"}+ engine = LibraryRAGSearchEngine(settings_snapshot=settings)++ chunk_text = "sentence. " * 120+ assert len(chunk_text) > SNIPPET_LENGTH_LONG++ chunk = Mock()+ chunk.chunk_text = chunk_text++ with patch(+ "local_deep_research.database.session_context.get_user_db_session"+ ) as mock_session_cm:+ mock_session = Mock()+ query_mock = Mock()+ mock_session.query.return_value = query_mock+ query_mock.filter.return_value = query_mock+ query_mock.order_by.return_value = query_mock+ query_mock.first.return_value = chunk+ mock_session_cm.return_value.__enter__.return_value = mock_session++ items = [+ {+ "source_id": "doc123",+ "metadata": {"chunk_index": 5, "document_id": "doc123"},+ "content": "old snippet",+ }+ ]+ result = engine._get_full_content(items)++ assert result[0]["full_content"] == chunk_text+ assert len(result[0]["snippet"]) == SNIPPET_LENGTH_LONG + 3++ from local_deep_research.citation_handler import CitationHandler++ documents = CitationHandler(Mock())._create_documents(result)+ assert documents[0].page_content == chunk_text+def test_get_full_content_falls_back_to_document_when_no_chunk_index(self):"""When no chunk index exists in metadata, full document text is retrieved."""from local_deep_research.web_search_engines.engines.search_engine_library import (@@ -562,6 +611,7 @@ class TestGetFullContent:assert len(result) == 1assert result[0]["content"] == "Full document body text"+ assert result[0]["full_content"] == "Full document body text"def test_get_full_content_scopes_by_collection_id(self):"""When collection_id is present in metadata, chunk query is scoped by collection_name.diff --git a/tests/web_search_engines/test_search_engine_factory.py b/tests/web_search_engines/test_search_engine_factory.pyindex 61df5c8f23..cbab03d724 100644--- a/tests/web_search_engines/test_search_engine_factory.py+++ b/tests/web_search_engines/test_search_engine_factory.py@@ -383,6 +383,126 @@ class TestGetSearch:call_kwargs = mock_create.call_args[1]assert call_kwargs["use_full_search"] is False+ @pytest.mark.parametrize(+ "search_tool", ["library", "collection_7f3a1c02-collection"]+ )+ def test_get_search_forwards_snippets_only_to_rag_engines(+ self, search_tool+ ):+ """The RAG engines are told whether to fetch full content.++ BaseSearchEngine defaults search_snippets_only to True, so an engine+ the factory never tells is snippet-only whatever the user configured.+ """+ mock_llm = Mock()++ with patch(+ "local_deep_research.web_search_engines.search_engine_factory.create_search_engine"+ ) as mock_create:+ mock_create.return_value = Mock()++ from local_deep_research.web_search_engines.search_engine_factory import (+ get_search,+ )++ get_search(+ search_tool=search_tool,+ llm_instance=mock_llm,+ max_results=10,+ search_snippets_only=False,+ settings_snapshot={"test": "value"},+ )++ call_kwargs = mock_create.call_args[1]+ assert call_kwargs["search_snippets_only"] is False++ @pytest.mark.parametrize("snippets_only", [False, True])+ @pytest.mark.parametrize(+ "search_tool,module_path,class_name,default_params",+ [+ (+ "library",+ ".engines.search_engine_library",+ "LibraryRAGSearchEngine",+ {},+ ),+ (+ "collection_7f3a1c02-collection",+ ".engines.search_engine_collection",+ "CollectionSearchEngine",+ {+ "collection_id": "7f3a1c02",+ "collection_name": "collection",+ },+ ),+ ],+ )+ def test_snippets_only_survives_real_create_search_engine(+ self,+ search_tool,+ module_path,+ class_name,+ default_params,+ snippets_only,+ ):+ """The flag reaches the built engine through the unmocked factory.++ create_search_engine filters its parameters against the engine+ class's own __init__ signature, so anything the class does not name+ is dropped before construction and BaseSearchEngine keeps its True+ default. That filter is what this exercises: get_search runs into+ the real create_search_engine, which loads the real engine class and+ inspects the real signature. Building the engine directly from+ get_search's arguments bypasses the filter and passes either way.+ """+ settings = {"_username": "testuser"}++ from local_deep_research.web_search_engines.search_engine_factory import (+ get_search,+ )++ engine_config = {+ search_tool: {+ "module_path": module_path,+ "class_name": class_name,+ "default_params": default_params,+ }+ }++ with (+ patch(+ "local_deep_research.web_search_engines.search_engine_factory.retriever_registry"+ ) as mock_registry,+ patch(+ "local_deep_research.web_search_engines.search_engine_factory.search_config",+ return_value=engine_config,+ ),+ patch(+ "local_deep_research.security.egress.policy.evaluate_engine"+ ) as mock_evaluate,+ patch(+ "local_deep_research.web_search_engines.engines.search_engine_library.get_setting_from_snapshot",+ return_value=None,+ ),+ patch(+ "local_deep_research.web_search_engines.engines.search_engine_library.get_server_url",+ return_value="http://localhost:5000",+ ),+ ):+ mock_registry.get.return_value = None+ mock_evaluate.return_value = Mock(allowed=True, reason="test")++ engine = get_search(+ search_tool=search_tool,+ llm_instance=Mock(),+ max_results=10,+ search_snippets_only=snippets_only,+ settings_snapshot=settings,+ )++ assert engine is not None+ assert engine.search_snippets_only is snippets_only+def test_get_search_returns_none(self):"""Test get_search when engine creation fails."""mock_llm = Mock()