~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
debug: add detailed logging to diagnose relevance filter index issues
LearningCircuitadb002cb4011
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.pyindex 73302c0b66..4c77d66117 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@@ -448,17 +448,43 @@ class BaseSearchEngine(ABC):if not self.llm or len(previews) <= 1:return previews+ # Log the number of previews we're processing+ logger.info(f"Filtering {len(previews)} previews for relevance")+# Create a simple context for LLMpreview_context = []+ indices_used = []for i, preview in enumerate(previews):title = preview.get("title", "Untitled").strip()snippet = preview.get("snippet", "").strip()+ url = preview.get("url", "").strip()# Clean up snippet if too longif len(snippet) > 300:snippet = snippet[:300] + "..."- preview_context.append(f"[{i}] Title: {title}\nSnippet: {snippet}")+ preview_context.append(+ f"[{i}] Title: {title}\nURL: {url}\nSnippet: {snippet}"+ )+ indices_used.append(i)++ # Log the indices we're presenting to the LLM+ logger.info(+ f"Created preview context with indices 0-{len(previews) - 1}"+ )+ logger.info(+ f"First 5 indices in prompt: {indices_used[:5]}, Last 5: {indices_used[-5:] if len(indices_used) > 5 else 'N/A'}"+ )++ # Join all previews with clear separation+ preview_text = "\n\n".join(preview_context)++ # Log a sample of what we're sending to the LLM+ logger.debug(+ f"First preview in prompt: {preview_context[0] if preview_context else 'None'}"+ )+ if len(preview_context) > 1:+ logger.debug(f"Last preview in prompt: {preview_context[-1]}")# Set a reasonable limit on context lengthcurrent_date = datetime.now(UTC).strftime("%Y-%m-%d")@@ -466,6 +492,7 @@ class BaseSearchEngine(ABC):Query: "{query}"Current date: {current_date}+Total results: {len(previews)}Criteria for selection (in order of importance):1. Direct relevance - MUST directly address the specific query topic, not just mention keywords@@ -473,11 +500,13 @@ Criteria for selection (in order of importance):3. Recency - prefer recent information when relevantSearch results to evaluate:-{json.dumps(previews, indent=2)}+{preview_text}Return a JSON array of indices (0-based) for results that are highly relevant to the query.+Valid indices are 0 to {len(previews) - 1}.Only include results that directly help answer the specific question asked.Be selective - it's better to return fewer high-quality results than many mediocre ones.+Maximum results to return: {self.max_filtered_results or 10}Example response: [4, 0, 2, 7]Respond with ONLY the JSON array, no other text."""@@ -508,6 +537,7 @@ Respond with ONLY the JSON array, no other text."""array_text = response_text[start_idx : end_idx + 1]try:ranked_indices = json.loads(array_text)+ logger.info(f"LLM returned indices: {ranked_indices}")# Validate that ranked_indices is a list of integersif not isinstance(ranked_indices, list):@@ -522,16 +552,33 @@ Respond with ONLY the JSON array, no other text.""")return []+ # Log analysis of the indices+ max_index = max(ranked_indices) if ranked_indices else -1+ min_index = min(ranked_indices) if ranked_indices else -1+ logger.info(+ f"Index analysis: min={min_index}, max={max_index}, "+ f"valid_range=0-{len(previews) - 1}, count={len(ranked_indices)}"+ )+# Return the results in ranked orderranked_results = []+ out_of_range = []for idx in ranked_indices:- if idx < len(previews):+ if 0 <= idx < len(previews):ranked_results.append(previews[idx])else:+ out_of_range.append(idx)logger.warning(- f"Index {idx} out of range, skipping"+ f"Index {idx} out of range (valid: 0-{len(previews) - 1}), skipping")+ if out_of_range:+ logger.error(+ f"Out of range indices: {out_of_range}. "+ f"Total previews: {len(previews)}, "+ f"All returned indices: {ranked_indices}"+ )+# Limit to max_filtered_results if specifiedif (self.max_filtered_results