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.

current status

LearningCircuit8dec00352d56
diff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.py
index b5bcc36045..bbc8027a77 100644
--- a/src/local_deep_research/search_system.py
+++ b/src/local_deep_research/search_system.py
@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
class AdvancedSearchSystem:
- def __init__(self, strategy_name: str = "standard"):
+ def __init__(self, strategy_name: str = "iterdrag"):
"""
Initialize the advanced search system.
diff --git a/src/local_deep_research/utilties/search_utilities.py b/src/local_deep_research/utilties/search_utilities.py
index 71bb3e1a35..023c03fb07 100644
--- a/src/local_deep_research/utilties/search_utilities.py
+++ b/src/local_deep_research/utilties/search_utilities.py
@@ -43,6 +43,38 @@ def format_links(links: List[Dict]) -> str:
return formatted_links
+def format_links_to_markdown(all_links: List[Dict]) -> str:
+ formatted_text = ""
+ if all_links:
+ formatted_text += "## SOURCES:\n"
+ # Group links by URL and collect all their indices
+ url_to_indices = {}
+ for link in all_links:
+ url = link.get("url")
+ index = link.get("index", "")
+ if url:
+ if url not in url_to_indices:
+ url_to_indices[url] = []
+ url_to_indices[url].append(index)
+
+ # Format each unique URL with all its indices
+ seen_urls = set() # Initialize the set here
+ for link in all_links:
+ url = link.get("url")
+ title = link.get("title", "Untitled")
+ if url and url not in seen_urls:
+ # Get all indices for this URL
+ indices = url_to_indices[url]
+ # Format as [1, 3, 5] if multiple indices, or just [1] if single
+ indices_str = f"[{', '.join(map(str, indices))}]"
+ formatted_text += f"{indices_str} {title}\n URL: {url}\n\n"
+ seen_urls.add(url)
+
+ formatted_text += "\n"
+
+ return formatted_text
+
+
def format_findings(
findings_list: List[Dict],
synthesized_content: str,
@@ -78,37 +110,25 @@ def format_findings(
formatted_text += f"{synthesized_content}\n\n"
# Add sources section after synthesized content if sources exist
- if all_links:
- formatted_text += "SOURCES:\n"
- formatted_text += "=" * 80 + "\n\n"
- seen_urls = set()
- link_counter = 1
- for link in all_links:
- url = link.get("url")
- title = link.get("title", "Untitled")
- if url and url not in seen_urls:
- formatted_text += f"[{link_counter}] {title}\n URL: {url}\n\n"
- seen_urls.add(url)
- link_counter += 1
- formatted_text += "\n"
+ formatted_text += format_links_to_markdown(all_links)
- # formatted_text += "=" * 80 + "\n\n" # Separator after synthesized content
+ formatted_text += "\n\n" # Separator after synthesized content
# Add Search Questions by Iteration section
if questions_by_iteration:
- formatted_text += "SEARCH QUESTIONS BY ITERATION:\n"
- formatted_text += "=" * 80 + "\n"
+ formatted_text += "## SEARCH QUESTIONS BY ITERATION:\n"
+ formatted_text += "\n"
for iter_num, questions in questions_by_iteration.items():
formatted_text += f"\nIteration {iter_num}:\n"
for i, q in enumerate(questions, 1):
formatted_text += f"{i}. {q}\n"
- formatted_text += "\n" + "=" * 80 + "\n\n"
+ formatted_text += "\n" + "\n\n"
else:
logger.warning("No questions by iteration found to format.")
# Add Detailed Findings section
if findings_list:
- formatted_text += "DETAILED FINDINGS:\n\n"
+ formatted_text += "## DETAILED FINDINGS:\n\n"
logger.info(f"Formatting {len(findings_list)} detailed finding items.")
for idx, finding in enumerate(findings_list):
@@ -119,9 +139,9 @@ def format_findings(
search_results = finding.get("search_results", [])
# Phase header
- formatted_text += f"{'=' * 80}\n"
- formatted_text += f"PHASE: {phase}\n"
- formatted_text += f"{'=' * 80}\n\n"
+ formatted_text += "\n"
+ formatted_text += f"### {phase}\n"
+ formatted_text += "\n\n"
question_displayed = False
# If this is a follow-up phase, try to show the corresponding question
@@ -137,7 +157,7 @@ def format_findings(
<= question_index
< len(questions_by_iteration[iteration])
):
- formatted_text += f"SEARCH QUESTION:\n{questions_by_iteration[iteration][question_index]}\n\n"
+ formatted_text += f"#### {questions_by_iteration[iteration][question_index]}\n\n"
question_displayed = True
else:
logger.warning(
@@ -160,7 +180,9 @@ def format_findings(
if 0 in questions_by_iteration and query_index < len(
questions_by_iteration[0]
):
- formatted_text += f"SEARCH QUESTION:\n{questions_by_iteration[0][query_index]}\n\n"
+ formatted_text += (
+ f"#### {questions_by_iteration[0][query_index]}\n\n"
+ )
question_displayed = True
else:
logger.warning(
@@ -173,17 +195,17 @@ def format_findings(
# If the question is in the finding itself, display it
if not question_displayed and "question" in finding and finding["question"]:
- formatted_text += f"SEARCH QUESTION:\n{finding['question']}\n\n"
+ formatted_text += f"### SEARCH QUESTION:\n{finding['question']}\n\n"
# Content
- formatted_text += f"CONTENT:\n{content}\n\n"
+ formatted_text += f"\n\n{content}\n\n"
# Search results if they exist
if search_results:
try:
links = extract_links_from_search_results(search_results)
if links:
- formatted_text += "SOURCES USED IN THIS SECTION:\n"
+ formatted_text += "### SOURCES USED IN THIS SECTION:\n"
formatted_text += format_links(links) + "\n\n"
except Exception as link_err:
logger.error(
@@ -198,18 +220,7 @@ def format_findings(
# Add summary of all sources at the end
if all_links:
- formatted_text += "ALL SOURCES USED IN RESEARCH:\n"
- formatted_text += "=" * 80 + "\n\n"
- seen_urls = set()
- link_counter = 1
- for link in all_links:
- url = link.get("url")
- title = link.get("title", "Untitled")
- if url and url not in seen_urls:
- formatted_text += f"{link_counter}. {title}\n URL: {url}\n"
- seen_urls.add(url)
- link_counter += 1
- formatted_text += "\n" + "=" * 80 + "\n"
+ formatted_text += format_links_to_markdown(all_links)
else:
logger.info("No unique sources found across all findings to list.")
diff --git a/src/local_deep_research/web/services/research_service.py b/src/local_deep_research/web/services/research_service.py
index 2e69ded36b..140821f169 100644
--- a/src/local_deep_research/web/services/research_service.py
+++ b/src/local_deep_research/web/services/research_service.py
@@ -119,6 +119,15 @@ def run_research_process(
if research_id in termination_flags and termination_flags[research_id]:
handle_termination(research_id, active_research, termination_flags)
raise Exception("Research was terminated by user")
+ if "SEARCH_PLAN:" in message:
+ engines = message.split("SEARCH_PLAN:")[1].strip()
+ metadata["planned_engines"] = engines
+ metadata["phase"] = "search_planning" # Use existing phase
+
+ if "ENGINE_SELECTED:" in message:
+ engine = message.split("ENGINE_SELECTED:")[1].strip()
+ metadata["selected_engine"] = engine
+ metadata["phase"] = "search" # Use existing 'search' phase
timestamp = datetime.utcnow().isoformat()
diff --git a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py b/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
index 6e91dd9cbb..a6ee9b9699 100644
--- a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
+++ b/src/local_deep_research/web_search_engines/engines/meta_search_engine.py
@@ -3,6 +3,7 @@ import os
from typing import Any, Dict, List, Optional
from ...config import search_config
+from ...web.services.socket_service import emit_socket_event
from ..search_engine_base import BaseSearchEngine
from ..search_engine_factory import create_search_engine
from ..search_engines_config import SEARCH_ENGINES
@@ -26,6 +27,7 @@ class MetaSearchEngine(BaseSearchEngine):
use_api_key_services: bool = True,
max_engines_to_try: int = 3,
max_filtered_results: Optional[int] = None,
+ engine_selection_callback=None,
**kwargs,
):
"""
@@ -184,9 +186,8 @@ Do not include any engines that are not listed above. Only return the comma-sepa
# Limit the number of engines to try
engines_to_try = ranked_engines[: self.max_engines_to_try]
-
logger.info(
- f"Search plan created. Will try these engines in order: {', '.join(engines_to_try)}"
+ f"SEARCH_PLAN: Will try these engines in order: {', '.join(engines_to_try)}"
)
all_errors = []
@@ -208,12 +209,25 @@ Do not include any engines that are not listed above. Only return the comma-sepa
# If search was successful, return results
if previews and len(previews) > 0:
+ logger.info(f"ENGINE_SELECTED: {engine_name}")
logger.info(
f"Successfully got {len(previews)} preview results from {engine_name}"
)
# Store selected engine for later use
self._selected_engine = engine
self._selected_engine_name = engine_name
+
+ # Emit a socket event to inform about the selected engine
+ try:
+ emit_socket_event(
+ "search_engine_selected",
+ {"engine": engine_name, "result_count": len(previews)},
+ )
+ except Exception as socket_error:
+ logger.error(
+ f"Socket emit error (non-critical): {str(socket_error)}"
+ )
+
return previews
logger.info(f"{engine_name} returned no previews")