mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
allow users to manually request index to be rebuilt
This commit is contained in:
parent
730d123802
commit
fc5599575c
@ -238,6 +238,13 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
<div class="help-text">${t("ai_llm.reprocess_all_embeddings_description")}</div>
|
<div class="help-text">${t("ai_llm.reprocess_all_embeddings_description")}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<button class="btn btn-sm btn-primary reprocess-index">
|
||||||
|
${t("ai_llm.reprocess_index")}
|
||||||
|
</button>
|
||||||
|
<div class="help-text">${t("ai_llm.reprocess_index_description")}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>${t("ai_llm.embedding_statistics")}</label>
|
<label>${t("ai_llm.embedding_statistics")}</label>
|
||||||
<div class="embedding-stats-container">
|
<div class="embedding-stats-container">
|
||||||
@ -461,6 +468,25 @@ export default class AiSettingsWidget extends OptionsWidget {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const $reprocessIndex = this.$widget.find('.reprocess-index');
|
||||||
|
$reprocessIndex.on('click', async () => {
|
||||||
|
$reprocessIndex.prop('disabled', true);
|
||||||
|
$reprocessIndex.text(t("ai_llm.reprocessing_index"));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await server.post('embeddings/rebuild-index');
|
||||||
|
toastService.showMessage(t("ai_llm.reprocess_index_started"));
|
||||||
|
// Refresh stats after reprocessing starts
|
||||||
|
await this.refreshEmbeddingStats();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error rebuilding index:", error);
|
||||||
|
toastService.showError(t("ai_llm.reprocess_index_error"));
|
||||||
|
} finally {
|
||||||
|
$reprocessIndex.prop('disabled', false);
|
||||||
|
$reprocessIndex.text(t("ai_llm.reprocess_index"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const $embeddingRefreshStats = this.$widget.find('.embedding-refresh-stats');
|
const $embeddingRefreshStats = this.$widget.find('.embedding-refresh-stats');
|
||||||
$embeddingRefreshStats.on('click', async () => {
|
$embeddingRefreshStats.on('click', async () => {
|
||||||
await this.refreshEmbeddingStats();
|
await this.refreshEmbeddingStats();
|
||||||
|
@ -1161,6 +1161,7 @@
|
|||||||
"enable_auto_update_embeddings_description": "Automatically update embeddings when notes are modified",
|
"enable_auto_update_embeddings_description": "Automatically update embeddings when notes are modified",
|
||||||
"auto_update_embeddings": "Auto-update Embeddings",
|
"auto_update_embeddings": "Auto-update Embeddings",
|
||||||
"auto_update_embeddings_desc": "Automatically update embeddings when notes are modified",
|
"auto_update_embeddings_desc": "Automatically update embeddings when notes are modified",
|
||||||
|
"no_failed_embeddings": "No failed embeddings",
|
||||||
"enable_automatic_indexing": "Automatic Indexing",
|
"enable_automatic_indexing": "Automatic Indexing",
|
||||||
"enable_automatic_indexing_description": "Periodically run indexing jobs in the background to maintain the knowledge base",
|
"enable_automatic_indexing_description": "Periodically run indexing jobs in the background to maintain the knowledge base",
|
||||||
"similarity_threshold": "Similarity Threshold",
|
"similarity_threshold": "Similarity Threshold",
|
||||||
@ -1179,6 +1180,12 @@
|
|||||||
"reprocess_started": "Embedding reprocessing started in the background",
|
"reprocess_started": "Embedding reprocessing started in the background",
|
||||||
"reprocess_error": "Error starting embedding reprocessing",
|
"reprocess_error": "Error starting embedding reprocessing",
|
||||||
|
|
||||||
|
"reprocess_index": "Rebuild Search Index",
|
||||||
|
"reprocess_index_description": "Rebuild the semantic search index structure for better query performance. This doesn't regenerate embeddings.",
|
||||||
|
"reprocessing_index": "Rebuilding...",
|
||||||
|
"reprocess_index_started": "Index rebuilding started in the background",
|
||||||
|
"reprocess_index_error": "Error rebuilding search index",
|
||||||
|
|
||||||
"embedding_statistics": "Embedding Statistics",
|
"embedding_statistics": "Embedding Statistics",
|
||||||
"total_notes": "Total Notes",
|
"total_notes": "Total Notes",
|
||||||
"processed_notes": "Processed Notes",
|
"processed_notes": "Processed Notes",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import options from "../../services/options.js";
|
import options from "../../services/options.js";
|
||||||
import vectorStore from "../../services/llm/embeddings/vector_store.js";
|
import vectorStore from "../../services/llm/embeddings/vector_store.js";
|
||||||
import providerManager from "../../services/llm/embeddings/providers.js";
|
import providerManager from "../../services/llm/embeddings/providers.js";
|
||||||
|
import indexService from "../../services/llm/index_service.js";
|
||||||
import becca from "../../becca/becca.js";
|
import becca from "../../becca/becca.js";
|
||||||
import type { Request, Response } from "express";
|
import type { Request, Response } from "express";
|
||||||
import log from "../../services/log.js";
|
import log from "../../services/log.js";
|
||||||
@ -257,6 +258,27 @@ async function retryAllFailedNotes(req: Request, res: Response) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manually trigger a rebuild of the search index
|
||||||
|
*/
|
||||||
|
async function rebuildIndex(req: Request, res: Response) {
|
||||||
|
// Start the index rebuilding operation in the background
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
await indexService.startFullIndexing(true);
|
||||||
|
log.info("Index rebuilding completed successfully");
|
||||||
|
} catch (error: any) {
|
||||||
|
log.error(`Error during background index rebuilding: ${error.message || "Unknown error"}`);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
// Return the response data
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Index rebuilding started in the background"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
findSimilarNotes,
|
findSimilarNotes,
|
||||||
searchByText,
|
searchByText,
|
||||||
@ -267,5 +289,6 @@ export default {
|
|||||||
getEmbeddingStats,
|
getEmbeddingStats,
|
||||||
getFailedNotes,
|
getFailedNotes,
|
||||||
retryFailedNote,
|
retryFailedNote,
|
||||||
retryAllFailedNotes
|
retryAllFailedNotes,
|
||||||
|
rebuildIndex
|
||||||
};
|
};
|
||||||
|
@ -383,6 +383,7 @@ function register(app: express.Application) {
|
|||||||
apiRoute(GET, "/api/embeddings/failed", embeddingsRoute.getFailedNotes);
|
apiRoute(GET, "/api/embeddings/failed", embeddingsRoute.getFailedNotes);
|
||||||
apiRoute(PST, "/api/embeddings/retry/:noteId", embeddingsRoute.retryFailedNote);
|
apiRoute(PST, "/api/embeddings/retry/:noteId", embeddingsRoute.retryFailedNote);
|
||||||
apiRoute(PST, "/api/embeddings/retry-all-failed", embeddingsRoute.retryAllFailedNotes);
|
apiRoute(PST, "/api/embeddings/retry-all-failed", embeddingsRoute.retryAllFailedNotes);
|
||||||
|
apiRoute(PST, "/api/embeddings/rebuild-index", embeddingsRoute.rebuildIndex);
|
||||||
|
|
||||||
// LLM chat session management endpoints
|
// LLM chat session management endpoints
|
||||||
apiRoute(PST, "/api/llm/sessions", llmRoute.createSession);
|
apiRoute(PST, "/api/llm/sessions", llmRoute.createSession);
|
||||||
@ -392,7 +393,7 @@ function register(app: express.Application) {
|
|||||||
apiRoute(DEL, "/api/llm/sessions/:sessionId", llmRoute.deleteSession);
|
apiRoute(DEL, "/api/llm/sessions/:sessionId", llmRoute.deleteSession);
|
||||||
apiRoute(PST, "/api/llm/sessions/:sessionId/messages", llmRoute.sendMessage);
|
apiRoute(PST, "/api/llm/sessions/:sessionId/messages", llmRoute.sendMessage);
|
||||||
route(GET, "/api/llm/sessions/:sessionId/messages", [auth.checkApiAuth, csrfMiddleware], llmRoute.sendMessage, apiResultHandler);
|
route(GET, "/api/llm/sessions/:sessionId/messages", [auth.checkApiAuth, csrfMiddleware], llmRoute.sendMessage, apiResultHandler);
|
||||||
|
|
||||||
// LLM index management endpoints
|
// LLM index management endpoints
|
||||||
apiRoute(GET, "/api/llm/index/stats", llmRoute.getIndexStats);
|
apiRoute(GET, "/api/llm/index/stats", llmRoute.getIndexStats);
|
||||||
apiRoute(PST, "/api/llm/index/start", llmRoute.startIndexing);
|
apiRoute(PST, "/api/llm/index/start", llmRoute.startIndexing);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user