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 critical RAG indexing and user registration issues

LearningCircuit6376fe9422e6
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 1fff042afe..b243d9b26d 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -192,10 +192,8 @@ class DatabaseManager:
sqlcipher3 = get_sqlcipher_module()
# Create tables directly with SQLCipher, bypassing SQLAlchemy DDL
- # Use isolation_level=None to prevent locking issues
- conn = sqlcipher3.connect(
- str(db_path), isolation_level=None, check_same_thread=False
- )
+ # Use standard isolation_level for proper transaction handling
+ conn = sqlcipher3.connect(str(db_path), check_same_thread=False)
# Use centralized SQLCipher setup
set_sqlcipher_key(conn, password)
apply_sqlcipher_pragmas(conn, creation_mode=True)
@@ -239,9 +237,7 @@ class DatabaseManager:
def create_sqlcipher_connection():
"""Create a properly initialized SQLCipher connection."""
- conn = sqlcipher3.connect(
- str(db_path), isolation_level=None, check_same_thread=False
- )
+ conn = sqlcipher3.connect(str(db_path), check_same_thread=False)
cursor = conn.cursor()
# Use centralized SQLCipher setup
@@ -340,9 +336,7 @@ class DatabaseManager:
def create_sqlcipher_connection():
"""Create a properly initialized SQLCipher connection."""
- conn = sqlcipher3.connect(
- str(db_path), isolation_level=None, check_same_thread=False
- )
+ conn = sqlcipher3.connect(str(db_path), check_same_thread=False)
cursor = conn.cursor()
# Use centralized SQLCipher setup
diff --git a/src/local_deep_research/defaults/settings_ollama_embeddings.json b/src/local_deep_research/defaults/settings_ollama_embeddings.json
new file mode 100644
index 0000000000..ff17b865b3
--- /dev/null
+++ b/src/local_deep_research/defaults/settings_ollama_embeddings.json
@@ -0,0 +1,16 @@
+{
+ "embeddings.ollama.url": {
+ "category": "embeddings",
+ "description": "URL of the Ollama endpoint for embedding models. This setting allows you to use a different Ollama server for embeddings than for LLM operations. If not set, the system will fall back to the LLM Ollama URL.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Ollama Embeddings Endpoint URL",
+ "options": null,
+ "step": null,
+ "type": "APP",
+ "ui_element": "text",
+ "value": "http://localhost:11434",
+ "visible": true
+ }
+}
diff --git a/src/local_deep_research/news/subscription_manager/scheduler.py b/src/local_deep_research/news/subscription_manager/scheduler.py
index 08cc0451de..e7af0c396c 100644
--- a/src/local_deep_research/news/subscription_manager/scheduler.py
+++ b/src/local_deep_research/news/subscription_manager/scheduler.py
@@ -692,8 +692,7 @@ class NewsScheduler:
try:
success, error = (
download_service.download_as_text(
- resource.id,
- save_files=False,
+ resource.id
)
)
if success:
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.py
index 8d7300c19f..48a7effd6b 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -543,14 +543,21 @@ def configure_rag():
embedding_provider = data.get("embedding_provider")
chunk_size = data.get("chunk_size")
chunk_overlap = data.get("chunk_overlap")
+ collection_id = data.get("collection_id")
if not all(
- [embedding_model, embedding_provider, chunk_size, chunk_overlap]
+ [
+ embedding_model,
+ embedding_provider,
+ chunk_size,
+ chunk_overlap,
+ collection_id,
+ ]
):
return jsonify(
{
"success": False,
- "error": "All configuration parameters are required",
+ "error": "All configuration parameters are required including collection_id",
}
), 400
@@ -573,7 +580,7 @@ def configure_rag():
)
# Get or create new index with this configuration
- rag_index = new_rag_service._get_or_create_rag_index()
+ rag_index = new_rag_service._get_or_create_rag_index(collection_id)
return jsonify(
{
diff --git a/src/local_deep_research/research_library/services/library_rag_service.py b/src/local_deep_research/research_library/services/library_rag_service.py
index 9c0d5bf7e8..17f13199b5 100644
--- a/src/local_deep_research/research_library/services/library_rag_service.py
+++ b/src/local_deep_research/research_library/services/library_rag_service.py
@@ -78,14 +78,25 @@ class LibraryRAGService:
self.embedding_manager = embedding_manager
else:
# Initialize embedding manager with library collection
- # We'll use a settings snapshot that includes the username and embedding config
- settings_snapshot = {
- "_username": username,
- "embeddings.provider": embedding_provider,
- f"embeddings.{embedding_provider}.model": embedding_model,
- "local_search_chunk_size": chunk_size,
- "local_search_chunk_overlap": chunk_overlap,
- }
+ # Load the complete user settings snapshot from database using the proper method
+ from ...settings.manager import SettingsManager
+
+ # Use proper database session for SettingsManager
+ with get_user_db_session(username) as session:
+ settings_manager = SettingsManager(session)
+ settings_snapshot = settings_manager.get_settings_snapshot()
+
+ # Add the specific settings needed for this RAG service
+ settings_snapshot.update(
+ {
+ "_username": username,
+ "embeddings.provider": embedding_provider,
+ f"embeddings.{embedding_provider}.model": embedding_model,
+ "local_search_chunk_size": chunk_size,
+ "local_search_chunk_overlap": chunk_overlap,
+ }
+ )
+
self.embedding_manager = LocalEmbeddingManager(
embedding_model=embedding_model,
embedding_model_type=embedding_provider,
@@ -346,7 +357,6 @@ class LibraryRAGService:
chunk_count=0,
)
session.add(doc_collection)
- session.flush()
logger.info(
f"Created new DocumentCollection entry for doc={document_id}, coll={collection_id}"
)
@@ -499,11 +509,6 @@ class LibraryRAGService:
doc_collection.chunk_count = len(chunks)
doc_collection.last_indexed_at = datetime.now(UTC)
- # Force immediate flush to execute the UPDATE statement
- # This is necessary because isolation_level=None (autocommit mode)
- # doesn't work well with ORM delayed updates
- session.flush()
-
logger.info(
f"Marked DocumentCollection as indexed: doc_id={document_id}, coll_id={collection_id}, chunks={len(chunks)}"
)
@@ -522,9 +527,8 @@ class LibraryRAGService:
f"Updated RAGIndex stats: chunk_count +{len(chunks)}, total_documents +1"
)
- # Commit and checkpoint WAL to ensure persistence
+ # Commit the transaction
session.commit()
- session.execute(text("PRAGMA wal_checkpoint(FULL)"))
# Verify the update was persisted
session.expire_all()
@@ -539,6 +543,9 @@ class LibraryRAGService:
f"Post-commit verification: doc={document_id}, indexed={verification.indexed if verification else 'NOT_FOUND'}, chunks={verification.chunk_count if verification else 0}"
)
+ # WAL checkpoint after transaction commit to ensure persistence
+ session.execute(text("PRAGMA wal_checkpoint(FULL)"))
+
logger.info(
f"Indexed document {document_id} with {len(chunks)} chunks"
)
diff --git a/src/local_deep_research/settings/manager.py b/src/local_deep_research/settings/manager.py
index 334eba4f32..9e67cbb616 100644
--- a/src/local_deep_research/settings/manager.py
+++ b/src/local_deep_research/settings/manager.py
@@ -404,6 +404,8 @@ class SettingsManager(ISettingsManager):
setting_type = SettingType.SEARCH
elif key.startswith("report."):
setting_type = SettingType.REPORT
+ elif key.startswith("database."):
+ setting_type = SettingType.DATABASE
# Create a new setting
new_setting = Setting(
diff --git a/src/local_deep_research/web/auth/routes.py b/src/local_deep_research/web/auth/routes.py
index 4275f4f7f9..41a9f92763 100644
--- a/src/local_deep_research/web/auth/routes.py
+++ b/src/local_deep_research/web/auth/routes.py
@@ -120,8 +120,8 @@ def login():
logger.warning(
f"Library initialization issue for {username}: {init_results.get('error', 'Unknown error')}"
)
- except Exception as e:
- logger.exception(f"Error initializing library for {username}: {e}")
+ except Exception:
+ logger.exception(f"Error initializing library for {username}")
# Don't block login on library init failure
# Success! Create session
@@ -343,6 +343,25 @@ def register():
logger.info(f"New user registered: {username}")
+ # Initialize library system (source types and default collection)
+ from ...database.library_init import initialize_library_for_user
+
+ try:
+ init_results = initialize_library_for_user(username, password)
+ if init_results.get("success"):
+ logger.info(
+ f"Library system initialized for new user {username}"
+ )
+ else:
+ logger.warning(
+ f"Library initialization issue for {username}: {init_results.get('error', 'Unknown error')}"
+ )
+ except Exception:
+ logger.exception(
+ f"Error initializing library for new user {username}"
+ )
+ # Don't block registration on library init failure
+
return redirect(url_for("index"))
except Exception:
diff --git a/src/local_deep_research/web/models/settings.py b/src/local_deep_research/web/models/settings.py
index aacd29070d..1c802639ee 100644
--- a/src/local_deep_research/web/models/settings.py
+++ b/src/local_deep_research/web/models/settings.py
@@ -11,6 +11,7 @@ class SettingType(str, Enum):
LLM = "llm"
SEARCH = "search"
REPORT = "report"
+ DATABASE = "database"
class BaseSetting(BaseModel):
diff --git a/src/local_deep_research/web/routes/settings_routes.py b/src/local_deep_research/web/routes/settings_routes.py
index 9d21f688ff..bb72d7e7b7 100644
--- a/src/local_deep_research/web/routes/settings_routes.py
+++ b/src/local_deep_research/web/routes/settings_routes.py
@@ -328,6 +328,9 @@ def save_all_settings():
elif key.startswith("report."):
setting_type = SettingType.REPORT
category = "report_parameters"
+ elif key.startswith("database."):
+ setting_type = SettingType.DATABASE
+ category = "database_parameters"
elif key.startswith("app."):
setting_type = SettingType.APP
category = "app_interface"
diff --git a/src/local_deep_research/web/services/settings_manager.py b/src/local_deep_research/web/services/settings_manager.py
index 738e8c232e..144d2d6368 100644
--- a/src/local_deep_research/web/services/settings_manager.py
+++ b/src/local_deep_research/web/services/settings_manager.py
@@ -339,6 +339,8 @@ class SettingsManager:
setting_type = SettingType.SEARCH
elif key.startswith("report."):
setting_type = SettingType.REPORT
+ elif key.startswith("database."):
+ setting_type = SettingType.DATABASE
# Create a new setting
new_setting = Setting(
diff --git a/src/local_deep_research/web/static/js/rag_manager.js b/src/local_deep_research/web/static/js/rag_manager.js
index b2fef86268..bbb5650588 100644
--- a/src/local_deep_research/web/static/js/rag_manager.js
+++ b/src/local_deep_research/web/static/js/rag_manager.js
@@ -452,11 +452,18 @@ function renderStats(stats) {
async function handleConfigSubmit(event) {
event.preventDefault();
+ // Validate that a collection is selected
+ if (!currentCollectionId) {
+ showError('Please select a collection first');
+ return;
+ }
+
const formData = {
embedding_provider: document.getElementById('embedding-provider').value,
embedding_model: document.getElementById('embedding-model').value,
chunk_size: parseInt(document.getElementById('chunk-size').value),
- chunk_overlap: parseInt(document.getElementById('chunk-overlap').value)
+ chunk_overlap: parseInt(document.getElementById('chunk-overlap').value),
+ collection_id: currentCollectionId
};
try {