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 multiple issues with search strategy persistence and benchmarks

LearningCircuit9a8b36c19b86
diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_routes.py b/src/local_deep_research/benchmarks/web_api/benchmark_routes.py
index c41f11b3cf..45dfbea493 100644
--- a/src/local_deep_research/benchmarks/web_api/benchmark_routes.py
+++ b/src/local_deep_research/benchmarks/web_api/benchmark_routes.py
@@ -72,6 +72,17 @@ def start_benchmark():
from flask import session as flask_session
username = flask_session.get("username")
+ session_id = flask_session.get("session_id")
+
+ # Try to get password from session store for background thread
+ from ...database.session_passwords import session_password_store
+
+ user_password = None
+ if session_id:
+ user_password = session_password_store.get_session_password(
+ username, session_id
+ )
+
search_config = {}
evaluation_config = {}
datasets_config = data.get("datasets_config", {})
@@ -95,7 +106,7 @@ def start_benchmark():
),
"search_strategy": settings_manager.get_setting(
"search.search_strategy", "focused_iteration"
- ),
+ ).replace("-", "_"), # Normalize hyphen to underscore
"model_name": settings_manager.get_setting("llm.model"),
"provider": settings_manager.get_setting("llm.provider"),
"temperature": float(
@@ -183,10 +194,13 @@ def start_benchmark():
evaluation_config=evaluation_config,
datasets_config=datasets_config,
username=username,
+ user_password=user_password,
)
# Start benchmark
- success = benchmark_service.start_benchmark(benchmark_run_id, username)
+ success = benchmark_service.start_benchmark(
+ benchmark_run_id, username, user_password
+ )
if success:
return jsonify(
@@ -660,7 +674,18 @@ def start_benchmark_simple():
from flask import session as flask_session
username = flask_session.get("username")
- with get_user_db_session(username) as session:
+ session_id = flask_session.get("session_id")
+
+ # Try to get password from session store for background thread
+ from ...database.session_passwords import session_password_store
+
+ user_password = None
+ if session_id:
+ user_password = session_password_store.get_session_password(
+ username, session_id
+ )
+
+ with get_user_db_session(username, user_password) as session:
# For benchmarks, use a default test username
settings_manager = SettingsManager(session, "benchmark_user")
@@ -679,7 +704,7 @@ def start_benchmark_simple():
),
"search_strategy": settings_manager.get_setting(
"search.search_strategy", "focused_iteration"
- ),
+ ).replace("-", "_"), # Normalize hyphen to underscore
"model_name": settings_manager.get_setting("llm.model"),
"provider": settings_manager.get_setting("llm.provider"),
"temperature": float(
@@ -751,9 +776,12 @@ def start_benchmark_simple():
evaluation_config=evaluation_config,
datasets_config=datasets_config,
username=username,
+ user_password=user_password,
)
- success = benchmark_service.start_benchmark(benchmark_run_id, username)
+ success = benchmark_service.start_benchmark(
+ benchmark_run_id, username, user_password
+ )
if success:
return jsonify(
diff --git a/src/local_deep_research/benchmarks/web_api/benchmark_service.py b/src/local_deep_research/benchmarks/web_api/benchmark_service.py
index 3a7972ad86..86a84226d8 100644
--- a/src/local_deep_research/benchmarks/web_api/benchmark_service.py
+++ b/src/local_deep_research/benchmarks/web_api/benchmark_service.py
@@ -75,11 +75,12 @@ class BenchmarkService:
evaluation_config: Dict[str, Any],
datasets_config: Dict[str, Dict],
username: str = None,
+ user_password: str = None,
) -> int:
"""Create a new benchmark run in the database."""
from ...database.session_context import get_user_db_session
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
try:
config_hash = self.generate_config_hash(search_config)
@@ -114,12 +115,12 @@ class BenchmarkService:
raise
def get_existing_results(
- self, config_hash: str, username: str = None
+ self, config_hash: str, username: str = None, user_password: str = None
) -> Dict[str, Dict]:
"""Get existing results with compatible configuration."""
from ...database.session_context import get_user_db_session
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
try:
# Find compatible runs
compatible_runs = (
@@ -167,7 +168,10 @@ class BenchmarkService:
return {}
def start_benchmark(
- self, benchmark_run_id: int, username: str = None
+ self,
+ benchmark_run_id: int,
+ username: str = None,
+ user_password: str = None,
) -> bool:
"""Start a benchmark run in a background thread."""
from ...database.session_context import get_user_db_session
@@ -175,7 +179,7 @@ class BenchmarkService:
try:
# Get all data from the database in the main thread
# This avoids database access from the background thread
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
# Get benchmark run details
benchmark_run = (
session.query(BenchmarkRun)
@@ -218,7 +222,7 @@ class BenchmarkService:
"search_config": benchmark_run.search_config,
"evaluation_config": benchmark_run.evaluation_config,
"existing_results": self.get_existing_results(
- benchmark_run.config_hash, username
+ benchmark_run.config_hash, username, user_password
),
"settings_snapshot": settings_snapshot, # Add settings snapshot
}
@@ -252,7 +256,7 @@ class BenchmarkService:
except Exception as e:
logger.exception(f"Error starting benchmark {benchmark_run_id}")
# Update status using user database
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
benchmark_run = (
session.query(BenchmarkRun)
.filter(BenchmarkRun.id == benchmark_run_id)
@@ -748,15 +752,32 @@ class BenchmarkService:
if not username:
username = run_data.get("data", {}).get("username")
+ user_password = run_data.get("data", {}).get("user_password")
+
saved_count = 0
from ...database.session_context import get_user_db_session
from ...database.models.benchmark import BenchmarkResult
try:
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
# Save any results that haven't been saved yet
for idx, result in enumerate(results_to_save):
if idx not in saved_indices:
+ # Check if this result already exists in the database
+ existing = (
+ session.query(BenchmarkResult)
+ .filter_by(
+ benchmark_run_id=benchmark_run_id,
+ query_hash=result["query_hash"],
+ )
+ .first()
+ )
+
+ if existing:
+ # Skip if already exists
+ saved_indices.add(idx)
+ continue
+
benchmark_result = BenchmarkResult(
benchmark_run_id=benchmark_run_id,
example_id=result["example_id"],
@@ -793,6 +814,11 @@ class BenchmarkService:
logger.exception(
f"Error syncing pending results for benchmark {benchmark_run_id}"
)
+ # Roll back the session on error to prevent PendingRollbackError
+ try:
+ session.rollback()
+ except:
+ pass
return saved_count
@@ -806,10 +832,11 @@ class BenchmarkService:
return
username = run_data.get("data", {}).get("username")
+ user_password = run_data.get("data", {}).get("user_password")
from ...database.session_context import get_user_db_session
try:
- with get_user_db_session(username) as session:
+ with get_user_db_session(username, user_password) as session:
# Update benchmark run status
benchmark_run = (
session.query(BenchmarkRun)
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 5cf290aa6d..36bbfe0467 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -661,6 +661,20 @@
"value": 3,
"visible": true
},
+ "search.search_strategy": {
+ "category": "search_parameters",
+ "description": "Search strategy to use for research",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Search Strategy",
+ "options": ["source-based", "focused-iteration"],
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "select",
+ "value": "source-based",
+ "visible": true
+ },
"search.region": {
"category": "search_parameters",
"description": "Geographic region for search results",
diff --git a/src/local_deep_research/news/web.py b/src/local_deep_research/news/web.py
index c4dbd03829..fabb0ef020 100644
--- a/src/local_deep_research/news/web.py
+++ b/src/local_deep_research/news/web.py
@@ -80,7 +80,9 @@ def create_news_blueprint():
# Only try to get settings if user is logged in
if username != "anonymous":
# Load user settings using the extracted function
- from ...database.session_context import get_user_db_session
+ from local_deep_research.database.session_context import (
+ get_user_db_session,
+ )
with get_user_db_session(username) as db_session:
load_user_settings(default_settings, db_session, username)
@@ -130,7 +132,9 @@ def create_news_blueprint():
# Load user's default settings if logged in
if username != "anonymous":
# Load user settings using the extracted function
- from ...database.session_context import get_user_db_session
+ from local_deep_research.database.session_context import (
+ get_user_db_session,
+ )
with get_user_db_session(username) as db_session:
load_user_settings(default_settings, db_session, username)
diff --git a/src/local_deep_research/search_system_factory.py b/src/local_deep_research/search_system_factory.py
index bd9b25d21b..5f7ec3eaf2 100644
--- a/src/local_deep_research/search_system_factory.py
+++ b/src/local_deep_research/search_system_factory.py
@@ -68,9 +68,6 @@ def create_strategy(
model=model,
search=search,
all_links_of_system=all_links_of_system,
- knowledge_accumulation_mode=kwargs.get(
- "knowledge_accumulation_mode", True
- ),
settings_snapshot=settings_snapshot,
)
diff --git a/src/local_deep_research/web/app_factory.py b/src/local_deep_research/web/app_factory.py
index 88ac13ce1c..74120cdc85 100644
--- a/src/local_deep_research/web/app_factory.py
+++ b/src/local_deep_research/web/app_factory.py
@@ -380,6 +380,9 @@ def register_blueprints(app):
"search_questions_per_iteration": settings_manager.get_setting(
"search.questions_per_iteration", 3
),
+ "search_strategy": settings_manager.get_setting(
+ "search.search_strategy", "source-based"
+ ),
}
# Debug logging
diff --git a/src/local_deep_research/web/static/js/components/settings_sync.js b/src/local_deep_research/web/static/js/components/settings_sync.js
index 45d373e6aa..b8bcd5315e 100644
--- a/src/local_deep_research/web/static/js/components/settings_sync.js
+++ b/src/local_deep_research/web/static/js/components/settings_sync.js
@@ -97,6 +97,15 @@ function connectMenuSettings() {
});
}
+ // Handle search strategy dropdown changes
+ const strategySelect = document.getElementById('strategy');
+ if (strategySelect) {
+ strategySelect.addEventListener('change', function(e) {
+ console.log('Search strategy changed to:', this.value);
+ saveMenuSettings('search.search_strategy', this.value);
+ });
+ }
+
console.log('Menu settings handlers initialized');
}
diff --git a/src/local_deep_research/web/static/js/pages/subscriptions.js b/src/local_deep_research/web/static/js/pages/subscriptions.js
index 6f5150987e..84c85ca5dc 100644
--- a/src/local_deep_research/web/static/js/pages/subscriptions.js
+++ b/src/local_deep_research/web/static/js/pages/subscriptions.js
@@ -83,6 +83,11 @@ function setupEventListeners() {
// Add folder button
document.getElementById('add-folder-btn').addEventListener('click', createNewFolder);
+
+ // Create subscription button - redirect to form page
+ document.getElementById('create-subscription-btn').addEventListener('click', () => {
+ window.location.href = '/news/subscriptions/new';
+ });
}
// Load subscriptions from API
diff --git a/src/local_deep_research/web/static/js/research_form.js b/src/local_deep_research/web/static/js/research_form.js
index dac4e8e865..8adf7e16f1 100644
--- a/src/local_deep_research/web/static/js/research_form.js
+++ b/src/local_deep_research/web/static/js/research_form.js
@@ -174,26 +174,8 @@ function setupWarningListeners() {
const strategySelect = document.getElementById('strategy');
if (strategySelect) {
strategySelect.addEventListener('change', function() {
-
- // Save strategy to localStorage
- // Strategy saved to database via API
-
- // Save strategy to database
- const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content;
- fetch('/settings/api/search.search_strategy', {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- 'X-CSRFToken': csrfToken
- },
- body: JSON.stringify({ value: strategySelect.value })
- })
- .then(response => response.json())
- .then(data => {
- })
- .catch(error => {
- });
-
+ // Strategy is saved via settings_sync.js handler
+ // Just update warnings after change
setTimeout(checkAndDisplayWarnings, 100);
});
}
diff --git a/src/local_deep_research/web/templates/pages/news-subscription-form.html b/src/local_deep_research/web/templates/pages/news-subscription-form.html
index a57b9c5ad3..a6422b2f7e 100644
--- a/src/local_deep_research/web/templates/pages/news-subscription-form.html
+++ b/src/local_deep_research/web/templates/pages/news-subscription-form.html
@@ -689,7 +689,7 @@ async function handleSubscriptionSubmit(e) {
'X-CSRFToken': getCSRFToken()
},
body: JSON.stringify({
- user_id: 'default_user', // TODO: Get from session
+ user_id: localStorage.getItem('userId') || 'anonymous',
query: query,
name: name,
subscription_type: 'search',
@@ -890,7 +890,7 @@ async function handleCreateAndRun(event) {
'X-CSRFToken': getCSRFToken()
},
body: JSON.stringify({
- user_id: 'default_user',
+ user_id: localStorage.getItem('userId') || 'anonymous',
query: query,
name: name,
subscription_type: 'search',
diff --git a/src/local_deep_research/web/templates/pages/research.html b/src/local_deep_research/web/templates/pages/research.html
index 7e2972136b..4923aed1d9 100644
--- a/src/local_deep_research/web/templates/pages/research.html
+++ b/src/local_deep_research/web/templates/pages/research.html
@@ -147,8 +147,8 @@
<div class="form-group half">
<label for="strategy">Search Strategy</label>
<select id="strategy" name="strategy" class="form-control">
- <option value="source-based">Source-Based (~70% SimpleQA, Comprehensive Research & Text Creation)</option>
- <option value="focused-iteration">Focused Iteration (~95% SimpleQA, Fast & Precise Q&A)</option>
+ <option value="source-based" {% if settings.search_strategy == 'source-based' %}selected{% endif %}>Source-Based (~70% SimpleQA, Comprehensive Research & Text Creation)</option>
+ <option value="focused-iteration" {% if settings.search_strategy == 'focused-iteration' %}selected{% endif %}>Focused Iteration (~95% SimpleQA, Fast & Precise Q&A)</option>
</select>
<span class="input-help">Source-Based: Proven strategy for detailed research. Focused Iteration: 2x faster for direct answers. Performance varies with LLM and configuration.</span>
</div>