~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
chore: strengthen type hints in advanced_search_system base classes (#2065)
LearningCircuit96c84552f7b4
diff --git a/src/local_deep_research/advanced_search_system/candidate_exploration/base_explorer.py b/src/local_deep_research/advanced_search_system/candidate_exploration/base_explorer.pyindex 6ff9514a65..0a6c79aa00 100644--- a/src/local_deep_research/advanced_search_system/candidate_exploration/base_explorer.py+++ b/src/local_deep_research/advanced_search_system/candidate_exploration/base_explorer.py@@ -8,7 +8,7 @@ candidate exploration implementations.from abc import ABC, abstractmethodfrom dataclasses import dataclassfrom enum import Enum-from typing import Dict, List, Optional, Set+from typing import Any, Optionalfrom langchain_core.language_models import BaseChatModelfrom loguru import logger@@ -31,11 +31,11 @@ class ExplorationStrategy(Enum):class ExplorationResult:"""Result of candidate exploration."""- candidates: List[Candidate]+ candidates: list[Candidate]total_searched: intunique_candidates: int- exploration_paths: List[str]- metadata: Dict+ exploration_paths: list[str]+ metadata: dict[str, Any]elapsed_time: floatstrategy_used: ExplorationStrategy@@ -72,14 +72,14 @@ class BaseCandidateExplorer(ABC):self.max_search_time = max_search_time# Tracking- self.explored_queries: Set[str] = set()- self.found_candidates: Dict[str, Candidate] = {}+ self.explored_queries: set[str] = set()+ self.found_candidates: dict[str, Candidate] = {}@abstractmethoddef explore(self,initial_query: str,- constraints: Optional[List[Constraint]] = None,+ constraints: Optional[list[Constraint]] = None,entity_type: Optional[str] = None,) -> ExplorationResult:"""@@ -99,9 +99,9 @@ class BaseCandidateExplorer(ABC):def generate_exploration_queries(self,base_query: str,- found_candidates: List[Candidate],- constraints: Optional[List[Constraint]] = None,- ) -> List[str]:+ found_candidates: list[Candidate],+ constraints: Optional[list[Constraint]] = None,+ ) -> list[str]:"""Generate new queries for continued exploration.@@ -115,7 +115,7 @@ class BaseCandidateExplorer(ABC):"""pass- def _execute_search(self, query: str) -> Dict:+ def _execute_search(self, query: str) -> dict[str, Any]:"""Execute a search query."""try:# Mark query as explored@@ -150,10 +150,10 @@ class BaseCandidateExplorer(ABC):def _extract_candidates_from_results(self,- results: Dict,+ results: dict[str, Any],original_query: str = None,entity_type: Optional[str] = None,- ) -> List[Candidate]:+ ) -> list[Candidate]:"""Generate answer candidates directly from search results using LLM."""candidates = []@@ -192,7 +192,7 @@ class BaseCandidateExplorer(ABC):def _generate_answer_candidates(self, question: str, search_content: str- ) -> List[str]:+ ) -> list[str]:"""Generate multiple answer candidates from search results."""prompt = f"""Question: {question}@@ -226,7 +226,7 @@ Give me multiple possible answers, one per line:def _extract_entity_names(self, text: str, entity_type: Optional[str] = None- ) -> List[str]:+ ) -> list[str]:"""Extract entity names from text using LLM."""if not text.strip():return []@@ -287,8 +287,8 @@ Names:return Truedef _deduplicate_candidates(- self, candidates: List[Candidate]- ) -> List[Candidate]:+ self, candidates: list[Candidate]+ ) -> list[Candidate]:"""Remove duplicate candidates based on name similarity."""unique_candidates = []seen_names = set()@@ -303,8 +303,8 @@ Names:return unique_candidatesdef _rank_candidates_by_relevance(- self, candidates: List[Candidate], query: str- ) -> List[Candidate]:+ self, candidates: list[Candidate], query: str+ ) -> list[Candidate]:"""Rank candidates by relevance to original query."""if not candidates:return candidatesdiff --git a/src/local_deep_research/advanced_search_system/constraint_checking/base_constraint_checker.py b/src/local_deep_research/advanced_search_system/constraint_checking/base_constraint_checker.pyindex d0a246b8ec..ad510c6e78 100644--- a/src/local_deep_research/advanced_search_system/constraint_checking/base_constraint_checker.py+++ b/src/local_deep_research/advanced_search_system/constraint_checking/base_constraint_checker.py@@ -7,7 +7,7 @@ constraint checking implementations.from abc import ABC, abstractmethodfrom dataclasses import dataclass-from typing import Dict, List, Optional, Tuple+from typing import Any, Optionalfrom langchain_core.language_models import BaseChatModelfrom loguru import logger@@ -22,10 +22,10 @@ class ConstraintCheckResult:candidate: Candidatetotal_score: float- constraint_scores: Dict[str, Dict]+ constraint_scores: dict[str, dict[str, Any]]should_reject: boolrejection_reason: Optional[str]- detailed_results: List[Dict]+ detailed_results: list[dict[str, Any]]class BaseConstraintChecker(ABC):@@ -55,7 +55,7 @@ class BaseConstraintChecker(ABC):@abstractmethoddef check_candidate(- self, candidate: Candidate, constraints: List[Constraint]+ self, candidate: Candidate, constraints: list[Constraint]) -> ConstraintCheckResult:"""Check a candidate against all constraints.@@ -71,8 +71,8 @@ class BaseConstraintChecker(ABC):@abstractmethoddef should_reject_candidate(- self, candidate: Candidate, constraint: Constraint, evidence_data: any- ) -> Tuple[bool, str]:+ self, candidate: Candidate, constraint: Constraint, evidence_data: Any+ ) -> tuple[bool, str]:"""Determine if a candidate should be rejected for a specific constraint.@@ -88,7 +88,7 @@ class BaseConstraintChecker(ABC):def _gather_evidence_for_constraint(self, candidate: Candidate, constraint: Constraint- ) -> List[Dict]:+ ) -> list[dict[str, Any]]:"""Gather evidence for a constraint using the provided evidence gatherer."""if self.evidence_gatherer:return self.evidence_gatherer(candidate, constraint)@@ -103,7 +103,7 @@ class BaseConstraintChecker(ABC):candidate: Candidate,constraint: Constraint,score: float,- details: Dict,+ details: dict[str, Any],):"""Log constraint evaluation result."""symbol = "✓" if score >= 0.8 else "○" if score >= 0.5 else "✗"@@ -112,7 +112,7 @@ class BaseConstraintChecker(ABC):)def _calculate_weighted_score(- self, constraint_scores: List[float], weights: List[float]+ self, constraint_scores: list[float], weights: list[float]) -> float:"""Calculate weighted average score."""if not constraint_scores or not weights:diff --git a/src/local_deep_research/advanced_search_system/constraint_checking/threshold_checker.py b/src/local_deep_research/advanced_search_system/constraint_checking/threshold_checker.pyindex a766f54b6c..4dd9276222 100644--- a/src/local_deep_research/advanced_search_system/constraint_checking/threshold_checker.py+++ b/src/local_deep_research/advanced_search_system/constraint_checking/threshold_checker.py@@ -5,7 +5,7 @@ This implementation uses simple yes/no threshold checking for constraints,making it faster but less nuanced than dual confidence checking."""-from typing import Dict, List, Tuple+from typing import Anyfrom loguru import logger@@ -46,7 +46,7 @@ class ThresholdChecker(BaseConstraintChecker):self.required_satisfaction_rate = required_satisfaction_ratedef check_candidate(- self, candidate: Candidate, constraints: List[Constraint]+ self, candidate: Candidate, constraints: list[Constraint]) -> ConstraintCheckResult:"""Check candidate using simple threshold analysis."""logger.info(f"Checking candidate: {candidate.name} (threshold)")@@ -149,8 +149,8 @@ class ThresholdChecker(BaseConstraintChecker):self,candidate: Candidate,constraint: Constraint,- evidence_data: List[Dict],- ) -> Tuple[bool, str]:+ evidence_data: list[dict[str, Any]],+ ) -> tuple[bool, str]:"""Simple rejection based on evidence availability and quality."""if not evidence_data:return (@@ -174,7 +174,7 @@ class ThresholdChecker(BaseConstraintChecker):self,candidate: Candidate,constraint: Constraint,- evidence_list: List[Dict],+ evidence_list: list[dict[str, Any]],) -> float:"""Check if constraint is satisfied using simple LLM prompt."""# Combine evidence textsdiff --git a/src/local_deep_research/advanced_search_system/filters/base_filter.py b/src/local_deep_research/advanced_search_system/filters/base_filter.pyindex b5e8676cda..1ed0af6a87 100644--- a/src/local_deep_research/advanced_search_system/filters/base_filter.py+++ b/src/local_deep_research/advanced_search_system/filters/base_filter.py@@ -4,7 +4,7 @@ Base class for search result filters."""from abc import ABC, abstractmethod-from typing import Dict, List+from typing import Anyfrom langchain_core.language_models.chat_models import BaseChatModel@@ -23,8 +23,8 @@ class BaseFilter(ABC):@abstractmethoddef filter_results(- self, results: List[Dict], query: str, **kwargs- ) -> List[Dict]:+ self, results: list[dict[str, Any]], query: str, **kwargs+ ) -> list[dict[str, Any]]:"""Filter search results by relevance to the query.diff --git a/src/local_deep_research/advanced_search_system/questions/base_question.py b/src/local_deep_research/advanced_search_system/questions/base_question.pyindex 3abb057a6e..c01dde6e12 100644--- a/src/local_deep_research/advanced_search_system/questions/base_question.py+++ b/src/local_deep_research/advanced_search_system/questions/base_question.py@@ -4,7 +4,6 @@ Defines the common interface and shared functionality for different question gen"""from abc import ABC, abstractmethod-from typing import Dict, Listclass BaseQuestionGenerator(ABC):@@ -25,8 +24,8 @@ class BaseQuestionGenerator(ABC):current_knowledge: str,query: str,questions_per_iteration: int,- questions_by_iteration: Dict[int, List[str]],- ) -> List[str]:+ questions_by_iteration: dict[int, list[str]],+ ) -> list[str]:"""Generate questions based on the current state of research.@@ -37,12 +36,12 @@ class BaseQuestionGenerator(ABC):questions_by_iteration: Questions generated in previous iterationsReturns:- List[str]: Generated questions+ list[str]: Generated questions"""passdef _format_previous_questions(- self, questions_by_iteration: Dict[int, List[str]]+ self, questions_by_iteration: dict[int, list[str]]) -> str:"""Format previous questions for context.diff --git a/src/local_deep_research/advanced_search_system/questions/entity_aware_question.py b/src/local_deep_research/advanced_search_system/questions/entity_aware_question.pyindex 99d2cc6906..0391a2aba0 100644--- a/src/local_deep_research/advanced_search_system/questions/entity_aware_question.py+++ b/src/local_deep_research/advanced_search_system/questions/entity_aware_question.py@@ -3,7 +3,6 @@ Entity-aware question generation for improved entity identification."""from datetime import datetime, UTC-from typing import Listfrom loguru import logger@@ -18,8 +17,8 @@ class EntityAwareQuestionGenerator(BaseQuestionGenerator):current_knowledge: str,query: str,questions_per_iteration: int = 2,- questions_by_iteration: dict = None,- ) -> List[str]:+ questions_by_iteration: dict[int, list[str]] | None = None,+ ) -> list[str]:"""Generate questions with entity-aware search patterns."""now = datetime.now(UTC)current_time = now.strftime("%Y-%m-%d")@@ -116,7 +115,7 @@ Q: question2def generate_sub_questions(self, query: str, context: str = ""- ) -> List[str]:+ ) -> list[str]:"""Generate sub-questions with entity focus when appropriate."""# Check if this is an entity identification queryentity_keywords = [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.pyindex a0f5f9b311..86d6335148 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@@ -4,7 +4,7 @@ Defines the common interface and shared functionality for different search appro"""from abc import ABC, abstractmethod-from typing import Callable, Dict, List, Optional+from typing import Any, Callable, Optionalfrom loguru import logger@@ -57,7 +57,7 @@ class BaseSearchStrategy(ABC):return defaultdef set_progress_callback(- self, callback: Callable[[str, int, dict], None]+ self, callback: Callable[[str, int, dict[str, Any]], None]) -> None:"""Set a callback function to receive progress updates."""self.progress_callback = callback@@ -66,14 +66,14 @@ class BaseSearchStrategy(ABC):self,message: str,progress_percent: Optional[int] = None,- metadata: Optional[dict] = None,+ metadata: Optional[dict[str, Any]] = None,) -> None:"""Send a progress update via the callback if available."""if self.progress_callback:self.progress_callback(message, progress_percent, metadata or {})@abstractmethod- def analyze_topic(self, query: str) -> Dict:+ def analyze_topic(self, query: str) -> dict[str, Any]:"""Analyze a topic using the strategy's specific approach.@@ -114,7 +114,7 @@ class BaseSearchStrategy(ABC):def _handle_search_error(self, error: Exception, question: str, progress_base: int- ) -> List:+ ) -> list:"""Handle errors during search execution.@@ -200,7 +200,7 @@ class BaseSearchStrategy(ABC):def _emit_searching_progress(self,iteration: int,- questions: List[str],+ questions: list[str],progress_percent: int,) -> None:"""