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.

important bugfixes

LearningCircuit7b2307bcee8d
diff --git a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py b/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
index 969a5e7a59..42c11eb07a 100644
--- a/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/base_strategy.py
@@ -13,11 +13,11 @@ logger = logging.getLogger(__name__)
class BaseSearchStrategy(ABC):
"""Abstract base class for all search strategies."""
- def __init__(self):
+ def __init__(self, all_links_of_system=[]):
"""Initialize the base strategy with common attributes."""
self.progress_callback = None
self.questions_by_iteration = {}
- self.all_links_of_system = []
+ self.all_links_of_system = all_links_of_system
def set_progress_callback(self, callback: Callable[[str, int, dict], None]) -> None:
"""Set a callback function to receive progress updates."""
diff --git a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
index 98a7ff4806..e02afe9a31 100644
--- a/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/source_based_strategy.py
@@ -6,7 +6,6 @@ from ...citation_handler import CitationHandler
from ...config.llm_config import get_llm
from ...config.search_config import get_search
from ...utilities.db_utils import get_db_setting
-from ...utilities.search_utilities import extract_links_from_search_results
from ..filters.cross_engine_filter import CrossEngineFilter
from ..findings.repository import FindingsRepository
from ..questions.standard_question import StandardQuestionGenerator
@@ -31,9 +30,10 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
filter_reorder: bool = True,
filter_reindex: bool = True,
filter_max_results: int = 20,
+ all_links_of_system: list = [],
):
"""Initialize with optional dependency injection for testing."""
- super().__init__()
+ super().__init__(all_links_of_system=all_links_of_system)
self.search = search or get_search()
self.model = model or get_llm()
self.progress_callback = None
@@ -118,6 +118,8 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
logger.debug("Selected amount of iterations: " + str(iterations_to_run))
iterations_to_run = int(iterations_to_run)
try:
+ filtered_search_results = []
+ total_citation_count_before_this_search = len(self.all_links_of_system)
# Run each iteration
for iteration in range(1, iterations_to_run + 1):
iteration_progress_base = 5 + (iteration - 1) * (70 / iterations_to_run)
@@ -161,7 +163,7 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
else:
# For subsequent iterations, generate questions based on previous search results
source_context = self._format_search_results_as_context(
- self.all_links_of_system
+ filtered_search_results
)
if iteration != 1:
context = f"""Previous search results:\n{source_context}\n\nIteration: {iteration} of {iterations_to_run}"""
@@ -236,10 +238,8 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
},
)
- # Collect all search results for this iteration
iteration_search_results.extend(search_results)
- # Step 3: Apply cross-engine filtering if enabled
if False and self.use_cross_engine_filter:
self._update_progress(
f"Filtering search results for iteration {iteration}",
@@ -247,10 +247,8 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
{"phase": "cross_engine_filtering", "iteration": iteration},
)
- # Get the current link count (for indexing)
existing_link_count = len(self.all_links_of_system)
logger.info(f"Existing link count: {existing_link_count}")
- # Filter the search results
filtered_search_results = self.cross_engine_filter.filter_results(
iteration_search_results,
query,
@@ -268,20 +266,21 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
"links_count": len(self.all_links_of_system),
},
)
+ else:
+ # Use the search results as they are
+ filtered_search_results = iteration_search_results
# Use filtered results
accumulated_search_results_across_all_iterations.extend(
- self.all_links_of_system
+ filtered_search_results
)
- links = extract_links_from_search_results(iteration_search_results)
- self.all_links_of_system.extend(links)
# Create a lightweight finding for this iteration's search metadata (no text content)
finding = {
"phase": f"Iteration {iteration}",
- "content": f"Searched with {len(all_questions)} questions, found {len(iteration_search_results)} results.",
+ "content": f"Searched with {len(all_questions)} questions, found {len(filtered_search_results)} results.",
"question": query,
- "search_results": iteration_search_results,
+ # "search_results": filtered_search_results,
"documents": [],
}
findings.append(finding)
@@ -295,7 +294,7 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
)
# Do we need this filter?
- if False and self.use_cross_engine_filter and iterations_to_run > 1:
+ if self.use_cross_engine_filter:
# Final filtering of all accumulated search results
self._update_progress(
"Performing final filtering of all results",
@@ -319,6 +318,10 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
"links_count": len(self.all_links_of_system),
},
)
+ else:
+ final_filtered_results = filtered_search_results
+ # links = extract_links_from_search_results()
+ self.all_links_of_system.extend(final_filtered_results)
# Final synthesis after all iterations
self._update_progress(
@@ -328,7 +331,7 @@ class SourceBasedSearchStrategy(BaseSearchStrategy):
# Final synthesis
final_citation_result = self.citation_handler.analyze_followup(
query,
- self.all_links_of_system,
+ final_filtered_results,
previous_knowledge="", # Empty string as we don't need previous knowledge here
nr_of_links=total_citation_count_before_this_search,
)
diff --git a/src/local_deep_research/utilities/search_utilities.py b/src/local_deep_research/utilities/search_utilities.py
index 7c1b82f3e0..25822fa1ea 100644
--- a/src/local_deep_research/utilities/search_utilities.py
+++ b/src/local_deep_research/utilities/search_utilities.py
@@ -43,22 +43,22 @@ def extract_links_from_search_results(search_results: List[Dict]) -> List[Dict]:
return links
-def format_links(links: List[Dict]) -> str:
- formatted_links = format_links_to_markdown(links)
- return formatted_links
-
-
def format_links_to_markdown(all_links: List[Dict]) -> str:
formatted_text = ""
logger.info(f"Formatting {len(all_links)} links to markdown...")
+ # logger.info(f"Following LINKS \n {all_links} ")
if all_links:
# Group links by URL and collect all their indices
url_to_indices = {}
for link in all_links:
url = link.get("url")
+ if url is None:
+ url = link.get("link")
index = link.get("index", "")
+ # logger.info(f"URL \n {str(url)} ")
if url:
+
if url not in url_to_indices:
url_to_indices[url] = []
url_to_indices[url].append(index)
@@ -67,6 +67,8 @@ def format_links_to_markdown(all_links: List[Dict]) -> str:
seen_urls = set() # Initialize the set here
for link in all_links:
url = link.get("url")
+ if url is None:
+ url = link.get("link")
title = link.get("title", "Untitled")
if url and url not in seen_urls:
# Get all indices for this URL
@@ -212,7 +214,7 @@ def format_findings(
links = extract_links_from_search_results(search_results)
if links:
formatted_text += "### SOURCES USED IN THIS SECTION:\n"
- formatted_text += format_links(links) + "\n\n"
+ formatted_text += format_links_to_markdown(links) + "\n\n"
except Exception as link_err:
logger.error(
f"Error processing search results/links for finding {idx}: {link_err}"
@@ -239,5 +241,5 @@ def print_search_results(search_results):
formatted_text = ""
links = extract_links_from_search_results(search_results)
if links:
- formatted_text = format_links(links=links)
+ formatted_text = format_links_to_markdown(links=links)
logger.info(formatted_text)