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.

further verification of sources

LearningCircuitbf2c66fd0ab3
diff --git a/citation_handler.py b/citation_handler.py
index 63d982220c..b23ef631a2 100644
--- a/citation_handler.py
+++ b/citation_handler.py
@@ -71,19 +71,35 @@ Provide a detailed analysis with citations and always keep URLS. Example format:
"""Process follow-up analysis with citations."""
documents = self._create_documents(search_results)
formatted_sources = self._format_sources(documents)
+ # Add fact-checking step
+ fact_check_prompt = f"""Analyze these sources for factual consistency:
+ 1. Cross-reference major claims between sources
+ 2. Identify and flag any contradictions
+ 3. Verify basic facts (dates, company names, ownership)
+ 4. Note when sources disagree
+
+ Previous Knowledge:
+ {previous_knowledge}
+
+ New Sources:
+ {formatted_sources}
+
+ Return any inconsistencies or conflicts found."""
+
+ fact_check_response = remove_think_tags(self.llm.invoke(fact_check_prompt).content)
prompt = f"""Using the previous knowledge and new sources, answer the question. Include citations using numbers in square brackets [1], [2], etc. When citing, use the source number provided at the start of each source. Always keep URLS. Reflect information from sources critically.
-Previous Knowledge:
-{previous_knowledge}
+ Previous Knowledge:
+ {previous_knowledge}
-Question: {question}
+ Question: {question}
-New Sources:
-{formatted_sources}
-Reflect information from sources critically.
-Provide a detailed answer with citations. Example format: "According to [1], ..."
-"""
+ New Sources:
+ {formatted_sources}
+ Reflect information from sources critically based on: {fact_check_response}.
+ Provide a detailed answer with citations. Example format: "According to [1], ..."
+ """
response = self.llm.invoke(prompt)
diff --git a/config.py b/config.py
index 25ebbf5b26..f4032d8ded 100644
--- a/config.py
+++ b/config.py
@@ -13,11 +13,16 @@ load_dotenv()
# LLM Configuration
DEFAULT_MODEL = "deepseek-r1:14b"
DEFAULT_TEMPERATURE = 0.7
-MAX_TOKENS = 2000
+MAX_TOKENS = 8000
# Search System Settings
-SEARCH_ITERATIONS = 3
-QUESTIONS_PER_ITERATION = 2
+SEARCH_ITERATIONS = 5
+QUESTIONS_PER_ITERATION = 3
+
+# Report settings
+SEARCHES_PER_SECTION = 5
+CONTEXT_CUT_OFF = 10000
+
# Search Configuration
MAX_SEARCH_RESULTS = 40 # DuckDuckGoSearch seems to return only 4 results anyways.
diff --git a/full_duck_duck_go_search_results.py b/full_duck_duck_go_search_results.py
index c4aa108fcc..55d9a4364f 100644
--- a/full_duck_duck_go_search_results.py
+++ b/full_duck_duck_go_search_results.py
@@ -55,13 +55,24 @@ class FullDuckDuckGoSearchResults:
now = datetime.now()
current_time = now.strftime("%Y-%m-%d")
- prompt = f"""ONLY Return a JSON array. The response contains no letters. Be very strict. Evaluate these URLs and their content for timeliness (today: {current_time}) known reliable near-academic sources (e.g., academic or government sources) and query relevance. query: {query}
+ prompt = f"""ONLY Return a JSON array. The response contains no letters. Evaluate these URLs for:
+ 1. Timeliness (today: {current_time})
+ 2. Factual accuracy (cross-reference major claims)
+ 3. Source reliability (prefer official company websites, established news outlets)
+ 4. Direct relevance to query: {query}
-URLs to evaluate:
-{urls_text}
+ For each source, analyze:
+ - Publication date (if available)
+ - Author/organization credibility
+ - Whether claims are supported by other reliable sources
+ - Primary vs secondary source status
-ONLY Return a JSON array of indices (0-based) and nothing else. No letters.
-Example response: \n[0, 2, 4]\n\n"""
+ URLs to evaluate:
+ {urls_text}
+
+ Return a JSON array of indices (0-based) for sources that meet ALL criteria.
+ ONLY Return a JSON array of indices (0-based) and nothing else. No letters.
+ Example response: \n[0, 2, 4]\n\n"""
try:
# Get LLM's evaluation
@@ -73,7 +84,7 @@ Example response: \n[0, 2, 4]\n\n"""
return [r for i, r in enumerate(results) if i in good_indices]
except Exception as e:
print(f"URL filtering error: {e}")
- return results # Return original results if filtering fails
+ return []
def remove_boilerplate(self, html: str) -> str:
if not html or not html.strip():
@@ -86,6 +97,7 @@ Example response: \n[0, 2, 4]\n\n"""
nr_full_text = 0
# Step 1: Get search results from DuckDuckGo
search_results = self.ddg_search.invoke(query)
+ print(type(search_results))
if not isinstance(search_results, list):
raise ValueError("Expected the search results in list format.")
@@ -94,9 +106,10 @@ Example response: \n[0, 2, 4]\n\n"""
# Extract URLs from filtered results
urls = [result.get("link") for result in filtered_results if result.get("link")]
+ print(urls)
if not urls:
print("\n === NO VALID LINKS ===\n")
- return filtered_results
+ return []
# Step 3: Download the full HTML pages for filtered URLs
loader = AsyncChromiumLoader(urls)
diff --git a/search_system.py b/search_system.py
index 56cf74fce0..9e1d299d58 100644
--- a/search_system.py
+++ b/search_system.py
@@ -29,9 +29,9 @@ class AdvancedSearchSystem:
Past questions: {str(self.questions_by_iteration)}
Knowledge: {current_knowledge}
Include questions that critically reflect current knowledge.
- \n\n\nFormat: One question per line, e.g. \n Q: question1\n\n"""
+ \n\n\nFormat: One question per line, e.g. \n Q: question1 \n Q: question2\n\n"""
else:
- prompt = f" You will have follow up questions. First, identify if your knowledge is outdated (high chance). Today: {current_time}. Generate {self.questions_per_iteration} high-quality internet search questions to exactly answer: {query}\n\n\nFormat: One question per line, e.g. \n Q: question1\n\n"
+ prompt = f" You will have follow up questions. First, identify if your knowledge is outdated (high chance). Today: {current_time}. Generate {self.questions_per_iteration} high-quality internet search questions to exactly answer: {query}\n\n\nFormat: One question per line, e.g. \n Q: question1 \n Q: question2\n\n"
response = self.model.invoke(prompt)
return [
@@ -77,16 +77,17 @@ class AdvancedSearchSystem:
result = self.citation_handler.analyze_followup(
question, search_results, limited_knowledge
)
- findings.append(
- {
- "phase": f"Follow-up {iteration}.{questions.index(question) + 1}",
- "content": result["content"],
- "question": question,
- "search_results": search_results,
- "documents": result["documents"],
- }
- )
- current_knowledge += f"\n\n{result['content']}"
+ if result is not None:
+ findings.append(
+ {
+ "phase": f"Follow-up {iteration}.{questions.index(question) + 1}",
+ "content": result["content"],
+ "question": question,
+ "search_results": search_results,
+ "documents": result["documents"],
+ }
+ )
+ current_knowledge += f"\n\n{result['content']}"
iteration += 1
current_knowledge = self._compress_knowledge(current_knowledge, query)