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: ensure collections use their stored embedding settings

LearningCircuit409e71530602
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 35c31333f0..ccd387a557 100644
--- a/src/local_deep_research/research_library/routes/rag_routes.py
+++ b/src/local_deep_research/research_library/routes/rag_routes.py
@@ -30,31 +30,91 @@ from ...database.models.library import (
Collection,
DocumentCollection,
SourceType,
+ EmbeddingProvider,
)
rag_bp = Blueprint("rag", __name__, url_prefix="/library")
-def get_rag_service() -> LibraryRAGService:
- """Get RAG service instance with current user's settings."""
+def get_rag_service(collection_id: Optional[str] = None) -> LibraryRAGService:
+ """
+ Get RAG service instance with appropriate settings.
+
+ If collection_id is provided:
+ - Uses collection's stored settings if they exist
+ - Uses current defaults for new collections (and stores them)
+
+ If no collection_id:
+ - Uses current default settings
+ """
+ from ...database.session_context import get_user_db_session
+
settings = get_settings_manager()
+ username = session["username"]
- # Get embedding configuration from settings or use defaults
- embedding_model = settings.get_setting(
+ # Get current default settings
+ default_embedding_model = settings.get_setting(
"local_search_embedding_model", "all-MiniLM-L6-v2"
)
- embedding_provider = settings.get_setting(
+ default_embedding_provider = settings.get_setting(
"local_search_embedding_provider", "sentence_transformers"
)
- chunk_size = int(settings.get_setting("local_search_chunk_size", 1000))
- chunk_overlap = int(settings.get_setting("local_search_chunk_overlap", 200))
+ default_chunk_size = int(
+ settings.get_setting("local_search_chunk_size", 1000)
+ )
+ default_chunk_overlap = int(
+ settings.get_setting("local_search_chunk_overlap", 200)
+ )
+
+ # If collection_id provided, check for stored settings
+ if collection_id:
+ with get_user_db_session(username) as db_session:
+ collection = (
+ db_session.query(Collection).filter_by(id=collection_id).first()
+ )
+
+ if collection and collection.embedding_model:
+ # Use collection's stored settings
+ logger.info(
+ f"Using stored settings for collection {collection_id}: "
+ f"{collection.embedding_model_type.value}/{collection.embedding_model}"
+ )
+ return LibraryRAGService(
+ username=username,
+ embedding_model=collection.embedding_model,
+ embedding_provider=collection.embedding_model_type.value,
+ chunk_size=collection.chunk_size or default_chunk_size,
+ chunk_overlap=collection.chunk_overlap
+ or default_chunk_overlap,
+ )
+ elif collection:
+ # New collection - use defaults and store them
+ logger.info(
+ f"New collection {collection_id}, using and storing default settings"
+ )
+
+ # Create service with defaults
+ service = LibraryRAGService(
+ username=username,
+ embedding_model=default_embedding_model,
+ embedding_provider=default_embedding_provider,
+ chunk_size=default_chunk_size,
+ chunk_overlap=default_chunk_overlap,
+ )
+
+ # Store settings on collection (will be done during indexing)
+ # Note: We don't store here because we don't have embedding_dimension yet
+ # It will be stored in index_collection when first document is indexed
+ return service
+
+ # No collection or fallback - use current defaults
return LibraryRAGService(
- username=session["username"],
- embedding_model=embedding_model,
- embedding_provider=embedding_provider,
- chunk_size=chunk_size,
- chunk_overlap=chunk_overlap,
+ username=username,
+ embedding_model=default_embedding_model,
+ embedding_provider=default_embedding_provider,
+ chunk_size=default_chunk_size,
+ chunk_overlap=default_chunk_overlap,
)
@@ -302,7 +362,7 @@ def get_index_info():
f"Getting RAG index info for collection_id: {collection_id}"
)
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
info = rag_service.get_current_index_info(collection_id)
if info is None:
@@ -334,7 +394,7 @@ def get_rag_stats():
if not collection_id:
collection_id = get_default_library_id(session["username"])
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
stats = rag_service.get_rag_stats(collection_id)
return jsonify({"success": True, "stats": stats})
@@ -366,7 +426,7 @@ def index_document():
if not collection_id:
collection_id = get_default_library_id(session["username"])
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
result = rag_service.index_document(
text_doc_id, collection_id, force_reindex
)
@@ -404,7 +464,7 @@ def remove_document():
if not collection_id:
collection_id = get_default_library_id(session["username"])
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
result = rag_service.remove_document_from_rag(
text_doc_id, collection_id
)
@@ -442,7 +502,7 @@ def index_all():
)
# Create RAG service in request context before generator runs
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
def generate():
"""Generator function for SSE progress updates."""
@@ -1464,10 +1524,37 @@ def get_collection_documents(collection_id):
documents = []
for link, doc in doc_links:
+ # Check if PDF file is stored
+ has_pdf = bool(
+ doc.file_path
+ and doc.file_path != "metadata_only"
+ and doc.file_path != "text_only_not_stored"
+ )
+ has_text_db = bool(doc.text_content)
+
+ # Use title if available, otherwise filename
+ display_title = doc.title or doc.filename or "Untitled"
+
+ # Get source type name
+ source_type_name = (
+ doc.source_type.name if doc.source_type else "unknown"
+ )
+
+ # Check if document is in other collections
+ other_collections_count = (
+ db_session.query(DocumentCollection)
+ .filter(
+ DocumentCollection.document_id == doc.id,
+ DocumentCollection.collection_id != collection_id,
+ )
+ .count()
+ )
+
documents.append(
{
"id": doc.id,
- "filename": doc.filename,
+ "filename": display_title,
+ "title": display_title,
"file_type": doc.file_type,
"file_size": doc.file_size,
"uploaded_at": doc.created_at.isoformat()
@@ -1478,6 +1565,11 @@ def get_collection_documents(collection_id):
"last_indexed_at": link.last_indexed_at.isoformat()
if link.last_indexed_at
else None,
+ "has_pdf": has_pdf,
+ "has_text_db": has_text_db,
+ "source_type": source_type_name,
+ "in_other_collections": other_collections_count > 0,
+ "other_collections_count": other_collections_count,
}
)
@@ -1488,6 +1580,13 @@ def get_collection_documents(collection_id):
"id": collection.id,
"name": collection.name,
"description": collection.description,
+ "embedding_model": collection.embedding_model,
+ "embedding_model_type": collection.embedding_model_type.value
+ if collection.embedding_model_type
+ else None,
+ "embedding_dimension": collection.embedding_dimension,
+ "chunk_size": collection.chunk_size,
+ "chunk_overlap": collection.chunk_overlap,
},
"documents": documents,
}
@@ -1510,7 +1609,7 @@ def index_collection(collection_id):
username = session["username"]
# Create RAG service
- rag_service = get_rag_service()
+ rag_service = get_rag_service(collection_id)
def generate():
"""Generator for SSE progress updates."""
@@ -1544,7 +1643,7 @@ def index_collection(collection_id):
# Store the embedding configuration used for this collection
collection.embedding_model = rag_service.embedding_model
- collection.embedding_model_type = (
+ collection.embedding_model_type = EmbeddingProvider(
rag_service.embedding_provider
)
collection.embedding_dimension = embedding_dim
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index 67b02afb83..85ce002250 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -536,17 +536,31 @@ class LibraryService:
# Get RAG indexing status across all collections
doc_collections = (
- session.query(DocumentCollection)
+ session.query(DocumentCollection, Collection)
+ .join(Collection)
.filter(DocumentCollection.document_id == doc_id)
.all()
)
# Check if indexed in any collection
- has_rag_indexed = any(dc.indexed for dc in doc_collections)
+ has_rag_indexed = any(
+ dc.indexed for dc, coll in doc_collections
+ )
total_chunks = sum(
- dc.chunk_count for dc in doc_collections if dc.indexed
+ dc.chunk_count for dc, coll in doc_collections if dc.indexed
)
+ # Build collections list
+ collections_list = [
+ {
+ "id": coll.id,
+ "name": coll.name,
+ "indexed": dc.indexed,
+ "chunk_count": dc.chunk_count,
+ }
+ for dc, coll in doc_collections
+ ]
+
# Calculate word count from text content
word_count = (
len(doc.text_content.split()) if doc.text_content else 0
@@ -612,6 +626,7 @@ class LibraryService:
"has_rag_indexed": has_rag_indexed,
"rag_chunk_count": total_chunks,
"word_count": word_count,
+ "collections": collections_list,
}
# Not found
diff --git a/src/local_deep_research/web/static/css/collection_details.css b/src/local_deep_research/web/static/css/collection_details.css
index 32df872dd4..58d7194ef7 100644
--- a/src/local_deep_research/web/static/css/collection_details.css
+++ b/src/local_deep_research/web/static/css/collection_details.css
@@ -417,6 +417,7 @@
transition: all 0.3s ease;
position: relative;
overflow: hidden;
+ cursor: pointer;
}
.ldr-document-item .ldr-document-title {
diff --git a/src/local_deep_research/web/static/css/collections.css b/src/local_deep_research/web/static/css/collections.css
index 207ea4f6ed..9876c4091c 100644
--- a/src/local_deep_research/web/static/css/collections.css
+++ b/src/local_deep_research/web/static/css/collections.css
@@ -219,6 +219,35 @@
animation: pulse 2s infinite;
}
+/* Collection View Link */
+.ldr-collection-view-link {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ gap: 0.5rem;
+ margin-top: auto;
+ padding-top: 1rem;
+ color: var(--text-secondary);
+ font-size: 0.9rem;
+ font-weight: 500;
+ opacity: 0.7;
+ transition: all 0.3s ease;
+}
+
+.ldr-collection-view-link i {
+ font-size: 0.85rem;
+ transition: transform 0.3s ease;
+}
+
+.ldr-collection-card:hover .ldr-collection-view-link {
+ opacity: 1;
+ color: var(--accent-primary);
+}
+
+.ldr-collection-card:hover .ldr-collection-view-link i {
+ transform: translateX(4px);
+}
+
/* Collection Actions */
.ldr-collection-actions {
display: flex;
diff --git a/src/local_deep_research/web/static/js/collection_details.js b/src/local_deep_research/web/static/js/collection_details.js
index cd884ec22d..da73aeee11 100644
--- a/src/local_deep_research/web/static/js/collection_details.js
+++ b/src/local_deep_research/web/static/js/collection_details.js
@@ -25,7 +25,6 @@ async function safeFetch(url, options = {}) {
*/
document.addEventListener('DOMContentLoaded', function() {
loadCollectionDetails();
- loadDefaultEmbeddingSettings();
// Setup button handlers
document.getElementById('index-collection-btn').addEventListener('click', () => indexCollection(false));
@@ -52,6 +51,9 @@ async function loadCollectionDetails() {
// Update statistics
updateStatistics();
+ // Display collection's embedding settings
+ displayCollectionEmbeddingSettings();
+
// Render documents
renderDocuments();
} else {
@@ -79,47 +81,42 @@ function updateStatistics() {
}
/**
- * Load default embedding settings
+ * Display collection's embedding settings
*/
-async function loadDefaultEmbeddingSettings() {
- try {
- const response = await safeFetch('/library/api/rag/settings');
- const data = await response.json();
-
- if (data.success && data.settings) {
- const settings = data.settings;
- const infoContainer = document.getElementById('default-embedding-info');
-
- infoContainer.innerHTML = `
- <div class="ldr-info-item">
- <span class="ldr-info-label">Provider:</span>
- <span class="ldr-info-value">${getProviderLabel(settings.embedding_provider)}</span>
- </div>
- <div class="ldr-info-item">
- <span class="ldr-info-label">Model:</span>
- <span class="ldr-info-value">${getModelLabel(settings.embedding_model, settings.embedding_provider)}</span>
- </div>
- <div class="ldr-info-item">
- <span class="ldr-info-label">Chunk Size:</span>
- <span class="ldr-info-value">${settings.chunk_size} characters</span>
- </div>
- <div class="ldr-info-item">
- <span class="ldr-info-label">Chunk Overlap:</span>
- <span class="ldr-info-value">${settings.chunk_overlap} characters</span>
- </div>
- `;
- } else {
- document.getElementById('default-embedding-info').innerHTML = `
- <div class="ldr-alert ldr-alert-warning">
- <i class="fas fa-exclamation-triangle"></i> No default embedding settings configured
- </div>
- `;
- }
- } catch (error) {
- console.error('Error loading default embedding settings:', error);
- document.getElementById('default-embedding-info').innerHTML = `
- <div class="ldr-alert ldr-alert-danger">
- <i class="fas fa-exclamation-triangle"></i> Failed to load default settings
+function displayCollectionEmbeddingSettings() {
+ const infoContainer = document.getElementById('collection-embedding-info');
+
+ if (collectionData.embedding_model) {
+ // Collection has stored settings - display them
+ infoContainer.innerHTML = `
+ <div class="ldr-info-item">
+ <span class="ldr-info-label">Provider:</span>
+ <span class="ldr-info-value">${getProviderLabel(collectionData.embedding_model_type)}</span>
+ </div>
+ <div class="ldr-info-item">
+ <span class="ldr-info-label">Model:</span>
+ <span class="ldr-info-value">${collectionData.embedding_model}</span>
+ </div>
+ <div class="ldr-info-item">
+ <span class="ldr-info-label">Chunk Size:</span>
+ <span class="ldr-info-value">${collectionData.chunk_size || 'Not set'} ${collectionData.chunk_size ? 'characters' : ''}</span>
+ </div>
+ <div class="ldr-info-item">
+ <span class="ldr-info-label">Chunk Overlap:</span>
+ <span class="ldr-info-value">${collectionData.chunk_overlap || 'Not set'} ${collectionData.chunk_overlap ? 'characters' : ''}</span>
+ </div>
+ ${collectionData.embedding_dimension ? `
+ <div class="ldr-info-item">
+ <span class="ldr-info-label">Embedding Dimension:</span>
+ <span class="ldr-info-value">${collectionData.embedding_dimension}</span>
+ </div>
+ ` : ''}
+ `;
+ } else {
+ // Collection not yet indexed - no settings stored
+ infoContainer.innerHTML = `
+ <div class="ldr-alert ldr-alert-info">
+ <i class="fas fa-info-circle"></i> This collection hasn't been indexed yet. Settings will be stored when you index documents.
</div>
`;
}
@@ -175,11 +172,17 @@ function renderDocuments() {
noDocsMessage.style.display = 'none';
container.innerHTML = filteredDocs.map(doc => `
- <div class="ldr-document-item ${doc.indexed ? 'indexed' : 'unindexed'}">
+ <a href="/library/document/${doc.id}" class="ldr-document-item ${doc.indexed ? 'indexed' : 'unindexed'}" style="text-decoration: none; color: inherit; display: block;">
<div class="document-info">
- <div class="ldr-document-title">${escapeHtml(doc.filename)}</div>
+ <div class="ldr-document-title">
+ ${escapeHtml(doc.filename)}
+ ${doc.has_pdf ? '<i class="fas fa-file-pdf" style="color: #dc3545; margin-left: 8px;" title="PDF stored"></i>' : ''}
+ ${doc.has_text_db ? '<i class="fas fa-file-alt" style="color: #28a745; margin-left: 8px;" title="Text content available"></i>' : ''}
+ ${doc.in_other_collections ? `<i class="fas fa-link" style="color: #667eea; margin-left: 8px;" title="In ${doc.other_collections_count + 1} collections"></i>` : ''}
+ </div>
<div class="ldr-document-meta">
${doc.file_size ? `Size: ${formatBytes(doc.file_size)} • ` : ''}
+ ${doc.source_type && doc.source_type !== 'unknown' ? `<span class="badge badge-info">${doc.source_type.replace('_', ' ')}</span> • ` : ''}
${doc.indexed ?
`<span class="badge badge-success">Indexed (${doc.chunk_count} chunks)</span>` :
'<span class="badge badge-warning">Not indexed</span>'
@@ -187,7 +190,7 @@ function renderDocuments() {
${doc.last_indexed_at ? ` • Last indexed: ${new Date(doc.last_indexed_at).toLocaleString()}` : ''}
</div>
</div>
- </div>
+ </a>
`).join('');
}
diff --git a/src/local_deep_research/web/static/js/collections_manager.js b/src/local_deep_research/web/static/js/collections_manager.js
index 4fd0177841..036dd7213a 100644
--- a/src/local_deep_research/web/static/js/collections_manager.js
+++ b/src/local_deep_research/web/static/js/collections_manager.js
@@ -82,7 +82,7 @@ function renderCollections() {
const container = document.getElementById('collections-container');
container.innerHTML = collections.map(collection => `
- <div class="ldr-collection-card" data-id="${collection.id}">
+ <a href="/library/collections/${collection.id}" class="ldr-collection-card" data-id="${collection.id}" style="text-decoration: none; color: inherit; cursor: pointer;">
<div class="ldr-collection-header">
<h3>${escapeHtml(collection.name)}</h3>
${collection.description ? `<p class="ldr-collection-description">${escapeHtml(collection.description)}</p>` : ''}
@@ -112,12 +112,11 @@ function renderCollections() {
`}
</div>
- <div class="ldr-collection-actions">
- <button class="ldr-btn-collections ldr-btn-collections-primary" onclick="window.location.href='/library/collections/${collection.id}'">
- <i class="fas fa-folder-open"></i> Open Collection
- </button>
+ <div class="ldr-collection-view-link">
+ <span>View</span>
+ <i class="fas fa-arrow-right"></i>
</div>
- </div>
+ </a>
`).join('');
}
diff --git a/src/local_deep_research/web/templates/pages/collection_details.html b/src/local_deep_research/web/templates/pages/collection_details.html
index ca359fa71d..4c6fe63626 100644
--- a/src/local_deep_research/web/templates/pages/collection_details.html
+++ b/src/local_deep_research/web/templates/pages/collection_details.html
@@ -75,21 +75,20 @@
<div class="ldr-embedding-settings-card">
<div class="ldr-embedding-info">
- <h4>Current Default Settings</h4>
- <div id="default-embedding-info" class="ldr-info-box">
+ <h4>Collection's Embedding Settings</h4>
+ <div id="collection-embedding-info" class="ldr-info-box">
<div class="ldr-loading-spinner">
- <i class="fas fa-spinner fa-spin"></i> Loading default settings...
+ <i class="fas fa-spinner fa-spin"></i> Loading settings...
</div>
</div>
<p class="ldr-form-text ldr-text-muted">
- <i class="fas fa-info-circle"></i> These are the default embedding settings that will be used for new collections.
- Individual collections can have different embedding settings based on their specific needs (e.g., different languages or content types).
+ <i class="fas fa-lock"></i> These settings are locked for this collection to ensure embedding consistency.
+ To use different settings, you would need to re-index the entire collection.
+ </p>
+ <p class="ldr-form-text ldr-text-muted" style="margin-top: 10px;">
+ <i class="fas fa-info-circle"></i> Default embedding settings for new collections can be changed in
+ <a href="/library/embedding-settings" style="color: #667eea;">Embedding Settings</a>.
</p>
- <div style="margin-top: 15px;">
- <a href="/library/embedding-settings" class="ldr-btn-collections ldr-btn-collections-info">
- <i class="fas fa-cog"></i> Configure Default Settings
- </a>
- </div>
</div>
</div>
</div>
diff --git a/src/local_deep_research/web/templates/pages/document_details.html b/src/local_deep_research/web/templates/pages/document_details.html
index 8d75d147f9..27b15f287d 100644
--- a/src/local_deep_research/web/templates/pages/document_details.html
+++ b/src/local_deep_research/web/templates/pages/document_details.html
@@ -163,6 +163,34 @@
</div>
{% endif %}
+ <!-- Collections -->
+ {% if document.collections %}
+ <div class="ldr-metadata-section">
+ <h2><i class="fas fa-folder"></i> Collections</h2>
+ <div class="ldr-metadata-value">
+ <div style="display: flex; flex-wrap: wrap; gap: 10px;">
+ {% for collection in document.collections %}
+ <a href="/library/collections/{{ collection.id }}"
+ class="ldr-btn ldr-btn-secondary"
+ style="text-decoration: none; display: flex; align-items: center; gap: 8px;">
+ <i class="fas fa-folder-open"></i>
+ <span>{{ collection.name }}</span>
+ {% if collection.indexed %}
+ <span style="background: #28a745; color: white; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem;">
+ Indexed ({{ collection.chunk_count }})
+ </span>
+ {% else %}
+ <span style="background: #ffc107; color: #333; padding: 2px 6px; border-radius: 4px; font-size: 0.75rem;">
+ Not indexed
+ </span>
+ {% endif %}
+ </a>
+ {% endfor %}
+ </div>
+ </div>
+ </div>
+ {% endif %}
+
<!-- RAG/Indexing Status -->
<div class="ldr-metadata-section">
<h2><i class="fas fa-search"></i> RAG & Indexing Status</h2>
diff --git a/src/local_deep_research/web/templates/pages/embedding_settings.html b/src/local_deep_research/web/templates/pages/embedding_settings.html
index 98e53b2094..5b3e9d1e44 100644
--- a/src/local_deep_research/web/templates/pages/embedding_settings.html
+++ b/src/local_deep_research/web/templates/pages/embedding_settings.html
@@ -9,6 +9,24 @@
<p class="ldr-subtitle">Configure default embedding models for new collections and semantic search</p>
</div>
+ <!-- Important Warning -->
+ <div class="ldr-alert ldr-alert-warning" style="margin-bottom: 2rem;">
+ <div style="display: flex; align-items: flex-start; gap: 1rem;">
+ <i class="fas fa-exclamation-triangle" style="font-size: 1.5rem; margin-top: 0.25rem;"></i>
+ <div>
+ <h4 style="margin: 0 0 0.5rem 0;">Important: Existing Collections</h4>
+ <p style="margin: 0 0 0.5rem 0;">
+ <strong>Changing these settings will only affect NEW collections.</strong>
+ Existing collections keep their original embedding settings to ensure data integrity and search consistency.
+ </p>
+ <p style="margin: 0;">
+ <i class="fas fa-lock"></i> Once a collection is indexed, its embedding settings are locked.
+ To change settings for an existing collection, you must re-index the entire collection, which will delete the current index.
+ </p>
+ </div>
+ </div>
+ </div>
+
<!-- Configuration Panel -->
<div class="ldr-rag-config-panel">
<h2><i class="fas fa-cog"></i> Configuration</h2>