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.

Added tests to see if searxng is working and additionally added very fast search that does not generate links but just provides the right sources.

LearningCircuitdb7567e6f940
diff --git a/src/local_deep_research/advanced_search_system/findings/repository.py b/src/local_deep_research/advanced_search_system/findings/repository.py
index ae6cc7bf0b..11ef754972 100644
--- a/src/local_deep_research/advanced_search_system/findings/repository.py
+++ b/src/local_deep_research/advanced_search_system/findings/repository.py
@@ -256,8 +256,8 @@ class FindingsRepository(BaseFindingsRepository):
current_knowledge = f"{first_part}\n\n[...content truncated due to length...]\n\n{last_part}"
logger.info("Knowledge truncated to fit within token limits")
- prompt = f"""Synthesize the following accumulated knowledge into a comprehensive answer for the original query.
-Format the response with clear sections, citations, and a concise summary, following the structure provided below.
+ prompt = f"""Use IEEE style citations [1], [2], etc. Never make up your own citations. Synthesize the following accumulated knowledge into a comprehensive answer for the original query.
+Format the response with clear sections, citations, and a concise summary.
Original Query: {query}
@@ -270,14 +270,10 @@ Sub-questions asked (for context):
Generate a well-structured, concise answer that:
1. Starts with a clear explanation of the most important points
2. Organizes information into logical sections with headers if needed
-3. Includes specific, numbered citations like [1], [2], etc. for important claims
-4. Maintains logical flow and prioritizes important information over minor details
-5. Highlights key insights and actionable recommendations
-6. Uses bullet points for lists of techniques or approaches
-7. Avoids repetition and unnecessary detail
-
-Format your response in a clean, succinct style that prioritizes readability while maintaining depth of information.
-Use numbered citations [1], [2], etc. for important sources - these will be linked to the actual sources after generation.
+3. Maintains logical flow and prioritizes important information over minor details
+4. Avoids repetition and unnecessary detail
+
+Use IEEE style citations [1], [2], etc. Never make up your own citations.
"""
logger.info(
diff --git a/src/local_deep_research/advanced_search_system/strategies/parallel_search_strategy.py b/src/local_deep_research/advanced_search_system/strategies/parallel_search_strategy.py
index a0c64bfe93..9e280ad767 100644
--- a/src/local_deep_research/advanced_search_system/strategies/parallel_search_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/parallel_search_strategy.py
@@ -23,14 +23,32 @@ class ParallelSearchStrategy(BaseSearchStrategy):
simultaneously for maximum speed.
"""
- def __init__(self, search=None, model=None, citation_handler=None):
- """Initialize with optional dependency injection for testing."""
+ def __init__(
+ self,
+ search=None,
+ model=None,
+ citation_handler=None,
+ include_text_content: bool = True,
+ ):
+ """Initialize with optional dependency injection for testing.
+
+ Args:
+ search: Optional search engine instance
+ model: Optional LLM model instance
+ citation_handler: Optional citation handler instance
+ include_text_content: If False, only includes metadata and links in search results
+ """
super().__init__()
self.search = search or get_search()
self.model = model or get_llm()
self.progress_callback = None
self.all_links_of_system = list()
self.questions_by_iteration = {}
+ self.include_text_content = include_text_content
+
+ # Set include_full_content on the search engine if it supports it
+ if hasattr(self.search, "include_full_content"):
+ self.search.include_full_content = include_text_content
# Use provided citation_handler or create one
self.citation_handler = citation_handler or CitationHandler(self.model)
@@ -42,6 +60,9 @@ class ParallelSearchStrategy(BaseSearchStrategy):
def analyze_topic(self, query: str) -> Dict:
"""
Parallel implementation that generates questions and searches all at once.
+
+ Args:
+ query: The research query to analyze
"""
logger.info(f"Starting parallel research on topic: {query}")
@@ -51,7 +72,11 @@ class ParallelSearchStrategy(BaseSearchStrategy):
self._update_progress(
"Initializing parallel research",
5,
- {"phase": "init", "strategy": "parallel"},
+ {
+ "phase": "init",
+ "strategy": "parallel",
+ "include_text_content": self.include_text_content,
+ },
)
# Check search engine
@@ -65,12 +90,6 @@ class ParallelSearchStrategy(BaseSearchStrategy):
"error": "No search engine available",
}
- # Force snippet-only mode
- original_snippet_mode = None
- if hasattr(self.search, "include_full_content"):
- original_snippet_mode = self.search.include_full_content
- self.search.include_full_content = False
-
try:
# Step 1: Generate questions first
self._update_progress(
@@ -137,24 +156,65 @@ class ParallelSearchStrategy(BaseSearchStrategy):
self.all_links_of_system.extend(links)
all_search_results.extend(search_results)
- # Step 3: Single analysis of all collected search results
+ # Step 3: Analysis of collected search results
self._update_progress(
"Analyzing all collected search results",
70,
{"phase": "final_analysis"},
)
- # Use citation handler for analysis of all results together
- result = self.citation_handler.analyze_initial(query, all_search_results)
+ if self.include_text_content:
+ # Use citation handler for analysis of all results together
+ result = self.citation_handler.analyze_initial(
+ query, all_search_results
+ )
+
+ if result:
+ synthesized_content = result["content"]
+ finding = {
+ "phase": "Final synthesis",
+ "content": synthesized_content,
+ "question": query,
+ "search_results": all_search_results,
+ "documents": result.get("documents", []),
+ }
+ findings.append(finding)
+
+ # Transfer questions to repository
+ self.findings_repository.set_questions_by_iteration(
+ self.questions_by_iteration
+ )
+
+ # Format findings
+ formatted_findings = (
+ self.findings_repository.format_findings_to_text(
+ findings, synthesized_content
+ )
+ )
- if result:
- synthesized_content = result["content"]
+ # Add documents to repository
+ if "documents" in result:
+ self.findings_repository.add_documents(result["documents"])
+ else:
+ synthesized_content = "No relevant results found."
+ formatted_findings = synthesized_content
+ finding = {
+ "phase": "Error",
+ "content": "No relevant results found.",
+ "question": query,
+ "search_results": all_search_results,
+ "documents": [],
+ }
+ findings.append(finding)
+ else:
+ # Skip LLM analysis, just format the raw search results
+ synthesized_content = "LLM analysis skipped"
finding = {
- "phase": "Final synthesis",
- "content": synthesized_content,
+ "phase": "Raw search results",
+ "content": "LLM analysis was skipped. Displaying raw search results with links.",
"question": query,
"search_results": all_search_results,
- "documents": result.get("documents", []),
+ "documents": [],
}
findings.append(finding)
@@ -163,26 +223,11 @@ class ParallelSearchStrategy(BaseSearchStrategy):
self.questions_by_iteration
)
- # Format findings
+ # Format findings without synthesis
formatted_findings = self.findings_repository.format_findings_to_text(
- findings, synthesized_content
+ findings, "Raw search results (LLM analysis skipped)"
)
- # Add documents to repository
- if "documents" in result:
- self.findings_repository.add_documents(result["documents"])
- else:
- synthesized_content = "No relevant results found."
- formatted_findings = synthesized_content
- finding = {
- "phase": "Error",
- "content": "No relevant results found.",
- "question": query,
- "search_results": all_search_results,
- "documents": [],
- }
- findings.append(finding)
-
except Exception as e:
import traceback
@@ -200,14 +245,6 @@ class ParallelSearchStrategy(BaseSearchStrategy):
}
findings.append(finding)
- finally:
- # Restore original settings
- if (
- hasattr(self.search, "include_full_content")
- and original_snippet_mode is not None
- ):
- self.search.include_full_content = original_snippet_mode
-
self._update_progress("Research complete", 100, {"phase": "complete"})
return {
diff --git a/src/local_deep_research/citation_handler.py b/src/local_deep_research/citation_handler.py
index 446c624895..49f64ed133 100644
--- a/src/local_deep_research/citation_handler.py
+++ b/src/local_deep_research/citation_handler.py
@@ -61,7 +61,7 @@ Question: {query}
Sources:
{formatted_sources}
-Provide a detailed analysis with citations and always keep URLS. Never make up sources. Example format: "According to the research [1], ..."
+Provide a detailed analysis with citations. Do not create the bibliography, it will be provided automatically. Never make up sources. Never write or create urls. Example format: "According to the research [1], ..."
"""
response = self.llm.invoke(prompt)
diff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.py
index 59814a0b0c..ccf98a8618 100644
--- a/src/local_deep_research/search_system.py
+++ b/src/local_deep_research/search_system.py
@@ -2,12 +2,17 @@
import logging
from typing import Callable, Dict
+from .advanced_search_system.findings.repository import FindingsRepository
+from .advanced_search_system.questions.standard_question import (
+ StandardQuestionGenerator,
+)
from .advanced_search_system.strategies.iterdrag_strategy import IterDRAGStrategy
from .advanced_search_system.strategies.parallel_search_strategy import (
ParallelSearchStrategy,
)
from .advanced_search_system.strategies.rapid_search_strategy import RapidSearchStrategy
from .advanced_search_system.strategies.standard_strategy import StandardSearchStrategy
+from .citation_handler import CitationHandler
from .config.config_files import settings
from .config.llm_config import get_llm
from .config.search_config import get_search
@@ -16,12 +21,18 @@ logger = logging.getLogger(__name__)
class AdvancedSearchSystem:
- def __init__(self, strategy_name: str = "parallel"):
- """
- Initialize the advanced search system.
+ """
+ Advanced search system that coordinates different search strategies.
+ """
+
+ def __init__(
+ self, strategy_name: str = "parallel", include_text_content: bool = True
+ ):
+ """Initialize the advanced search system.
Args:
strategy_name: The name of the search strategy to use ("standard" or "iterdrag")
+ include_text_content: If False, only includes metadata and links in search results
"""
# Get configuration
self.search = get_search()
@@ -34,13 +45,22 @@ class AdvancedSearchSystem:
f"Initializing AdvancedSearchSystem with strategy_name='{strategy_name}'"
)
+ # Initialize components
+ self.citation_handler = CitationHandler(self.model)
+ self.question_generator = StandardQuestionGenerator(self.model)
+ self.findings_repository = FindingsRepository(self.model)
+
# Initialize strategy based on name
if strategy_name.lower() == "iterdrag":
logger.info("Creating IterDRAGStrategy instance")
self.strategy = IterDRAGStrategy(model=self.model, search=self.search)
elif strategy_name.lower() == "parallel":
logger.info("Creating ParallelSearchStrategy instance")
- self.strategy = ParallelSearchStrategy(model=self.model, search=self.search)
+ self.strategy = ParallelSearchStrategy(
+ model=self.model,
+ search=self.search,
+ include_text_content=include_text_content,
+ )
elif strategy_name.lower() == "rapid":
logger.info("Creating RapidSearchStrategy instance")
self.strategy = RapidSearchStrategy(model=self.model, search=self.search)
@@ -60,6 +80,12 @@ class AdvancedSearchSystem:
if hasattr(self, "progress_callback") and self.progress_callback:
self.strategy.set_progress_callback(self.progress_callback)
+ def _progress_callback(self, message: str, progress: int, metadata: dict) -> None:
+ """Handle progress updates from the strategy."""
+ logger.info(f"Progress: {progress}% - {message}")
+ if hasattr(self, "progress_callback"):
+ self.progress_callback(message, progress, metadata)
+
def set_progress_callback(self, callback: Callable[[str, int, dict], None]) -> None:
"""Set a callback function to receive progress updates."""
self.progress_callback = callback
@@ -67,7 +93,11 @@ class AdvancedSearchSystem:
self.strategy.set_progress_callback(callback)
def analyze_topic(self, query: str) -> Dict:
- """Analyze a topic using the current strategy."""
+ """Analyze a topic using the current strategy.
+
+ Args:
+ query: The research query to analyze
+ """
# Use the strategy to analyze the topic
result = self.strategy.analyze_topic(query)
diff --git a/tests/searxgn/test_searxgn_instance.py b/tests/searxgn/test_searxgn_instance.py
new file mode 100644
index 0000000000..f945e36c90
--- /dev/null
+++ b/tests/searxgn/test_searxgn_instance.py
@@ -0,0 +1,39 @@
+import requests
+
+# SearXNG instance URL
+searxng_url = "http://localhost:8080/search"
+
+# Test query
+query = "python programming"
+
+# Parameters for the search - using HTML format instead of JSON
+params = {"q": query, "format": "html"}
+
+# Browser-like headers
+headers = {
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
+ "Accept-Language": "en-US,en;q=0.9",
+ "Referer": "http://localhost:8080/",
+ "Connection": "keep-alive",
+}
+
+try:
+ # First get cookies from the main page
+ session = requests.Session()
+ session.get("http://localhost:8080/")
+
+ # Send the search request with cookies
+ response = session.get(searxng_url, params=params, headers=headers)
+
+ # Check status
+ if response.status_code == 200:
+ print(f"SearXNG is working! Got HTML response of {len(response.text)} bytes")
+ print("Check your SearXNG web interface at http://localhost:8080")
+ else:
+ print(f"Error: Got status code {response.status_code}")
+ print(response.text[:500]) # Show just the first 500 chars
+
+except Exception as e:
+ print(f"Error connecting to SearXNG: {e}")
+ print("\nIs your SearXNG container running? Check with: docker ps | grep searxng")
diff --git a/tests/searxgn/test_searxgn_integration.py b/tests/searxgn/test_searxgn_integration.py
new file mode 100644
index 0000000000..a41a9318f9
--- /dev/null
+++ b/tests/searxgn/test_searxgn_integration.py
@@ -0,0 +1,16 @@
+from local_deep_research.web_search_engines.search_engine_factory import (
+ create_search_engine,
+)
+
+# Create the engine
+engine = create_search_engine("searxng")
+
+# Check if available
+if engine and hasattr(engine, "is_available") and engine.is_available:
+ print(f"SearXNG configured with instance: {engine.instance_url}")
+
+ # Test a simple search
+ results = engine.run("test query")
+ print(f"Found {len(results)} results")
+else:
+ print("SearXNG is not properly configured or is disabled")