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 additional info to UI

LearningCircuite7fcbeb3f7d2
diff --git a/src/local_deep_research/search_system.py b/src/local_deep_research/search_system.py
index 0bbae2ca80..fcc095e171 100644
--- a/src/local_deep_research/search_system.py
+++ b/src/local_deep_research/search_system.py
@@ -102,13 +102,59 @@ class AdvancedSearchSystem:
Args:
query: The research query to analyze
"""
+
+ # Send progress message with LLM info
+ self.progress_callback(
+ f"Using {settings.llm.provider.upper()} model: {settings.llm.model}",
+ 1, # Low percentage to show this as an early step
+ {
+ "phase": "setup",
+ "llm_info": {
+ "name": settings.llm.model,
+ "provider": settings.llm.provider,
+ },
+ },
+ )
+ # Send progress message with search strategy info
+ search_tool = settings.SEARCH.TOOL
+ search_strategy_name = type(self.strategy).__name__
+
+ self.progress_callback(
+ f"Using search tool: {search_tool}",
+ 1.5, # Between setup and processing steps
+ {
+ "phase": "setup",
+ "search_info": {
+ "strategy": search_strategy_name,
+ "tool": search_tool,
+ "iterations": settings.SEARCH.ITERATIONS,
+ "questions_per_iteration": settings.SEARCH.QUESTIONS_PER_ITERATION,
+ "max_results": settings.SEARCH.MAX_RESULTS,
+ "max_filtered_results": settings.SEARCH.MAX_FILTERED_RESULTS,
+ "snippets_only": settings.SEARCH.SNIPPETS_ONLY,
+ },
+ },
+ )
+
# Use the strategy to analyze the topic
result = self.strategy.analyze_topic(query)
# Update our attributes for backward compatibility
if hasattr(self.strategy, "questions_by_iteration"):
self.questions_by_iteration = self.strategy.questions_by_iteration
-
+ # Send progress message with search info
+ self.progress_callback(
+ f"Processed questions: {self.strategy.questions_by_iteration}",
+ 2, # Low percentage to show this as an early step
+ {
+ "phase": "setup",
+ "search_info": {
+ "questions_by_iteration": len(
+ self.strategy.questions_by_iteration
+ )
+ },
+ },
+ )
if hasattr(self.strategy, "all_links_of_system"):
self.all_links_of_system = self.strategy.all_links_of_system
diff --git a/src/local_deep_research/web_search_engines/search_engine_base.py b/src/local_deep_research/web_search_engines/search_engine_base.py
index a93083ebc9..b2984eb094 100644
--- a/src/local_deep_research/web_search_engines/search_engine_base.py
+++ b/src/local_deep_research/web_search_engines/search_engine_base.py
@@ -36,13 +36,8 @@ class BaseSearchEngine(ABC):
if max_filtered_results is None:
max_filtered_results = 5
self.llm = llm # LLM for relevance filtering
- self.max_filtered_results = max_filtered_results # Limit filtered results
-
- # Ensure max_results is never None and is a positive integer
- if max_results is None:
- self.max_results = 25 # Default if None
- else:
- self.max_results = max(1, int(max_results))
+ self.max_filtered_results = int(max_filtered_results) # Ensure it's an integer
+ self.max_results = max(1, int(max_results)) # Ensure it's a positive integer
def run(self, query: str) -> List[Dict[str, Any]]:
"""
@@ -145,62 +140,84 @@ If no results seem relevant to the query, return an empty array: []"""
# Get LLM's evaluation
response = self.llm.invoke(prompt)
- # Handle different response formats (string or object with content attribute)
+ # Log the raw response for debugging
+ logger.debug(f"Raw LLM response for relevance filtering: {response}")
+
+ # Handle different response formats
response_text = ""
if hasattr(response, "content"):
response_text = remove_think_tags(response.content)
else:
- # Handle string responses
response_text = remove_think_tags(str(response))
- # Clean up response to handle potential formatting issues
+ # Clean up response
response_text = response_text.strip()
+ logger.debug(f"Cleaned response text: {response_text}")
- # Find the first occurrence of '[' and the last occurrence of ']'
+ # Find JSON array in response
start_idx = response_text.find("[")
end_idx = response_text.rfind("]")
if start_idx >= 0 and end_idx > start_idx:
array_text = response_text[start_idx : end_idx + 1]
- ranked_indices = json.loads(array_text)
-
- # Return the results in ranked order
- ranked_results = []
- for idx in ranked_indices:
- if idx < len(previews):
- ranked_results.append(previews[idx])
-
- # If we filtered out all results, return at least some of the originals
- if not ranked_results and previews:
- logger.info(
- "Filtering removed all results, returning top 3 originals instead"
- )
- return previews[: min(3, len(previews))]
-
- # Limit to max_filtered_results if specified
- if (
- self.max_filtered_results
- and len(ranked_results) > self.max_filtered_results
- ):
- logger.info(
- f"Limiting filtered results to top {self.max_filtered_results}"
- )
- return ranked_results[: self.max_filtered_results]
-
- return ranked_results
+ try:
+ ranked_indices = json.loads(array_text)
+
+ # Validate that ranked_indices is a list of integers
+ if not isinstance(ranked_indices, list):
+ logger.warning(
+ "LLM response is not a list, returning original results"
+ )
+ return previews[: min(5, len(previews))]
+
+ if not all(isinstance(idx, int) for idx in ranked_indices):
+ logger.warning(
+ "LLM response contains non-integer indices, returning original results"
+ )
+ return previews[: min(5, len(previews))]
+
+ # Return the results in ranked order
+ ranked_results = []
+ for idx in ranked_indices:
+ if idx < len(previews):
+ ranked_results.append(previews[idx])
+ else:
+ logger.warning(f"Index {idx} out of range, skipping")
+
+ # If we filtered out all results, return at least some of the originals
+ if not ranked_results and previews:
+ logger.info(
+ "Filtering removed all results, returning top 3 originals instead"
+ )
+ return previews[: min(3, len(previews))]
+
+ # Limit to max_filtered_results if specified
+ if (
+ self.max_filtered_results
+ and len(ranked_results) > self.max_filtered_results
+ ):
+ logger.info(
+ f"Limiting filtered results to top {self.max_filtered_results}"
+ )
+ return ranked_results[: self.max_filtered_results]
+
+ return ranked_results
+
+ except json.JSONDecodeError as e:
+ logger.warning(f"Failed to parse JSON from LLM response: {e}")
+ logger.debug(f"Problematic JSON text: {array_text}")
+ return previews[: min(5, len(previews))]
else:
- logger.info(
+ logger.warning(
"Could not find JSON array in response, returning original previews"
)
- # Return at least the top few results instead of nothing
- max_results = min(5, len(previews))
- return previews[:max_results]
+ logger.debug(f"Response text without JSON array: {response_text}")
+ return previews[: min(5, len(previews))]
except Exception as e:
- logger.info(f"Relevance filtering error: {e}")
+ logger.error(f"Relevance filtering error: {e}", exc_info=True)
# Fall back to returning top results on error
- max_results = min(5, len(previews))
- return previews[:max_results]
+ return previews[: min(5, len(previews))]
@abstractmethod
def _get_previews(self, query: str) -> List[Dict[str, Any]]: