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.

fix: improve refinement display in TopicOrganizationStrategy

LearningCircuit656bd79cfd27
diff --git a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
index a05537641f..0d2ee59606 100644
--- a/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
+++ b/src/local_deep_research/advanced_search_system/strategies/topic_organization_strategy.py
@@ -977,10 +977,31 @@ Otherwise, respond with only the follow-up question, nothing else.
generated_text = ""
# Format the topic graph as a structured knowledge representation
+ # Include iteration history if we have refinements
topic_graph_str = self._format_topic_graph_as_knowledge(
relevant_topics, query
)
+ # Add iteration history to the topic graph output
+ if self.iteration_history and len(self.iteration_history) > 1:
+ history_lines = ["\n## Research Refinement History"]
+ for hist in self.iteration_history:
+ if hist["type"] == "initial":
+ history_lines.append(
+ f"\n**Initial Search:** {hist['sources_count']} sources → {hist['topics_count']} topics"
+ )
+ else:
+ history_lines.append(
+ f'\n**Refinement {hist["iteration"]}:** "{hist["question"]}"'
+ )
+ history_lines.append(
+ f" - Added {hist['new_sources']} new sources"
+ )
+ history_lines.append(
+ f" - Topics: {hist['topics_before']} → {hist['topics_after']}"
+ )
+ topic_graph_str += "\n".join(history_lines)
+
self._update_progress(
"Topic organization complete",
100,
@@ -1020,9 +1041,27 @@ Otherwise, respond with only the follow-up question, nothing else.
}
findings.append(topic_finding)
+ # Combine source strategy questions with our refinement questions
+ questions_by_iteration = dict(
+ source_results.get("questions_by_iteration", {})
+ )
+
+ # Add our refinement questions if any
+ if self.refinement_questions:
+ # Find the highest iteration number from source strategy
+ max_iter = (
+ max(questions_by_iteration.keys())
+ if questions_by_iteration
+ else 0
+ )
+
+ # Add refinement questions as subsequent iterations
+ for i, ref_question in enumerate(self.refinement_questions, 1):
+ questions_by_iteration[max_iter + i] = [ref_question]
+
# Set questions by iteration for proper formatting
self.findings_repository.set_questions_by_iteration(
- source_results.get("questions_by_iteration", {})
+ questions_by_iteration
)
# Format findings properly with sources using findings repository
@@ -1041,9 +1080,7 @@ Otherwise, respond with only the follow-up question, nothing else.
"findings": findings,
"iterations": source_results.get("iterations", 0)
+ len(self.refinement_questions),
- "questions_by_iteration": source_results.get(
- "questions_by_iteration", {}
- ),
+ "questions_by_iteration": questions_by_iteration, # Now includes refinement questions
"formatted_findings": formatted_findings,
"current_knowledge": topic_graph_str, # The topic graph structure as knowledge
"all_links_of_system": self.all_links_of_system,
diff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.py
index b10a559163..09728e15c0 100644
--- a/src/local_deep_research/search_system_factory.py
+++ b/src/local_deep_research/search_system_factory.py
@@ -642,7 +642,8 @@ def create_strategy(
similarity_threshold=kwargs.get("similarity_threshold", 0.3),
enable_refinement=kwargs.get("enable_refinement", True),
max_refinement_iterations=kwargs.get(
- "max_refinement_iterations", 5
+ "max_refinement_iterations",
+ 2, # Reduced from 5 to 2
),
generate_text=kwargs.get("generate_text", True),
)