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.

trying to improve filtering

LearningCircuit13b52007889d
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 1644741a74..38e7132cd5 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
@@ -1,12 +1,12 @@
import json
import logging
from abc import ABC, abstractmethod
+from datetime import datetime
from typing import Any, Dict, List, Optional
from langchain_core.language_models import BaseLLM
from ..config import search_config
-from ..utilties.search_utilities import remove_think_tags
logger = logging.getLogger(__name__)
@@ -35,9 +35,29 @@ class BaseSearchEngine(ABC):
"""
if max_filtered_results is None:
max_filtered_results = 5
+ if max_results is None:
+ max_results = 10
+
self.llm = llm # LLM for relevance filtering
- 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
+ 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
+
+ @property
+ def max_filtered_results(self) -> int:
+ """Get the maximum number of filtered results."""
+ return self._max_filtered_results
+
+ @property
+ def max_results(self) -> int:
+ """Get the maximum number of search results."""
+ return self._max_results
+
+ def get_max_results(self) -> int:
+ """
+ Get the maximum number of results this engine should return.
+ This method should be used by derived classes when making API calls.
+ """
+ return self._max_results
def run(self, query: str) -> List[Dict[str, Any]]:
"""
@@ -120,35 +140,37 @@ class BaseSearchEngine(ABC):
preview_context.append(f"[{i}] Title: {title}\nSnippet: {snippet}")
# Set a reasonable limit on context length
- max_context_items = min(10, len(preview_context))
- context = "\n\n".join(preview_context[:max_context_items])
-
- prompt = f"""You are a search result filter. Your task is to rank search results by relevance to a query.
+ current_date = datetime.now().strftime("%Y-%m-%d")
+ prompt = f"""Analyze these search results and provide a ranked list of the most relevant ones.
-Query: "{query}"
+IMPORTANT: Evaluate and rank based on these criteria (in order of importance):
+1. Timeliness - current/recent information as of {current_date}
+2. Direct relevance to query: "{query}"
+3. Source reliability (prefer official sources, established websites)
+4. Factual accuracy (cross-reference major claims)
-Search Results:
-{context}
+Search results to evaluate:
+{json.dumps(previews, indent=2)}
-Return the search results as a JSON array of indices, ranked from most to least relevant to the query.
-Only include indices of results that are actually relevant to the query.
-For example: [3, 0, 7, 1]
+Return ONLY a JSON array of indices (0-based) ranked from most to least relevant.
+Include ONLY indices that meet ALL criteria, with the most relevant first.
+Example response: [4, 0, 2]
-If no results seem relevant to the query, return an empty array: []"""
+Respond with ONLY the JSON array, no other text."""
try:
# Get LLM's evaluation
response = self.llm.invoke(prompt)
# Log the raw response for debugging
- logger.debug(f"Raw LLM response for relevance filtering: {response}")
+ logger.info(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)
+ response_text = response.content
else:
- response_text = remove_think_tags(str(response))
+ response_text = str(response)
# Clean up response
response_text = response_text.strip()