Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
show fancier stats
perf3ct51c83bbbc81a
diff --git a/src/public/app/widgets/type_widgets/options/ai_settings.ts b/src/public/app/widgets/type_widgets/options/ai_settings.tsindex 749c54a6e1..fd666958b6 100644--- a/src/public/app/widgets/type_widgets/options/ai_settings.ts+++ b/src/public/app/widgets/type_widgets/options/ai_settings.ts@@ -201,7 +201,10 @@ export default class AiSettingsWidget extends OptionsWidget {<div><strong>${t("ai_llm.queued_notes")}:</strong> <span class="embedding-queued-notes">-</span></div><div><strong>${t("ai_llm.failed_notes")}:</strong> <span class="embedding-failed-notes">-</span></div><div><strong>${t("ai_llm.last_processed")}:</strong> <span class="embedding-last-processed">-</span></div>- <div class="progress mt-2" style="height: 10px;">+ <div class="mt-2">+ <strong>${t("ai_llm.progress")}:</strong> <span class="embedding-status-text">-</span>+ </div>+ <div class="progress mt-1" style="height: 10px;"><div class="progress-bar embedding-progress" role="progressbar" style="width: 0%;"aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div></div>@@ -456,6 +459,30 @@ export default class AiSettingsWidget extends OptionsWidget {$progressBar.css('width', `${stats.percentComplete}%`);$progressBar.attr('aria-valuenow', stats.percentComplete.toString());$progressBar.text(`${stats.percentComplete}%`);++ // Update status text based on state+ const $statusText = this.$widget.find('.embedding-status-text');+ if (stats.queuedNotesCount > 0) {+ $statusText.text(t("ai_llm.processing", { percentage: stats.percentComplete }));+ } else if (stats.percentComplete < 100) {+ $statusText.text(t("ai_llm.incomplete", { percentage: stats.percentComplete }));+ } else {+ $statusText.text(t("ai_llm.complete"));+ }++ // Change progress bar color based on state+ if (stats.queuedNotesCount > 0) {+ // Processing in progress - use animated progress bar+ $progressBar.addClass('progress-bar-striped progress-bar-animated bg-info');+ $progressBar.removeClass('bg-success');+ } else if (stats.percentComplete < 100) {+ // Incomplete - use standard progress bar+ $progressBar.removeClass('progress-bar-striped progress-bar-animated bg-info bg-success');+ } else {+ // Complete - show success color+ $progressBar.removeClass('progress-bar-striped progress-bar-animated bg-info');+ $progressBar.addClass('bg-success');+ }}} catch (error) {console.error("Error fetching embedding stats:", error);diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.jsonindex 446fa055b0..25ab6263db 100644--- a/src/public/translations/en/translation.json+++ b/src/public/translations/en/translation.json@@ -1174,6 +1174,10 @@"failed_notes": "Failed Notes","last_processed": "Last Processed","never": "Never",+ "progress": "Progress",+ "processing": "Processing ({{percentage}}%)",+ "incomplete": "Incomplete ({{percentage}}%)",+ "complete": "Complete (100%)","refresh_stats": "Refresh Stats","refreshing": "Refreshing...","stats_error": "Error fetching embedding statistics",diff --git a/src/services/llm/embeddings/vector_store.ts b/src/services/llm/embeddings/vector_store.tsindex 568fedbfa2..3f17c0227e 100644--- a/src/services/llm/embeddings/vector_store.ts+++ b/src/services/llm/embeddings/vector_store.ts@@ -496,13 +496,32 @@ export async function getEmbeddingStats() {"SELECT utcDateCreated FROM note_embeddings ORDER BY utcDateCreated DESC LIMIT 1") as string | null || null;+ // Calculate the actual completion percentage+ // When reprocessing, we need to consider notes in the queue as not completed yet+ // We calculate the percentage of notes that are embedded and NOT in the queue++ // First, get the count of notes that are both in the embeddings table and queue+ const notesInQueueWithEmbeddings = await sql.getValue(`+ SELECT COUNT(DISTINCT eq.noteId)+ FROM embedding_queue eq+ JOIN note_embeddings ne ON eq.noteId = ne.noteId+ `) as number;++ // The number of notes with valid, up-to-date embeddings+ const upToDateEmbeddings = embeddedNotesCount - notesInQueueWithEmbeddings;++ // Calculate the percentage of notes that are properly embedded+ const percentComplete = totalNotesCount > 0+ ? Math.round((upToDateEmbeddings / totalNotesCount) * 100)+ : 0;+return {totalNotesCount,embeddedNotesCount,queuedNotesCount,failedNotesCount,lastProcessedDate,- percentComplete: totalNotesCount > 0 ? Math.round((embeddedNotesCount / totalNotesCount) * 100) : 0+ percentComplete: Math.max(0, Math.min(100, percentComplete)) // Ensure between 0-100};}