From 8b3babc28ec9286b051b4c3ace435cadc04ef4fd Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Fri, 4 Jul 2025 09:33:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B5=8C=E5=85=A5=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E7=9A=84=E5=88=9D=E5=A7=8B=E5=8C=96=E5=92=8C?= =?UTF-8?q?=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=B5=8C=E5=85=A5=E6=A8=A1=E5=9E=8B=E5=8A=A0=E8=BD=BD=E5=92=8C?= =?UTF-8?q?=E5=B5=8C=E5=85=A5=E6=B5=8B=E8=AF=95=E7=9A=84=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9ef5c7a..f7cc0fa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,6 +14,7 @@ import { RAGEngine } from './core/rag/rag-engine' import { TransEngine } from './core/transformations/trans-engine' import { DBManager } from './database/database-manager' import { migrateToJsonDatabase } from './database/json/migrateToJsonDatabase' +import { EmbeddingManager } from './embedworker/EmbeddingManager' import EventListener from "./event-listener" import { t } from './lang/helpers' import { PreviewView } from './PreviewView' @@ -52,6 +53,7 @@ export default class InfioPlugin extends Plugin { mcpHub: McpHub | null = null ragEngine: RAGEngine | null = null transEngine: TransEngine | null = null + embeddingManager: EmbeddingManager | null = null inlineEdit: InlineEdit | null = null diffStrategy?: DiffStrategy dataviewManager: DataviewManager | null = null @@ -73,6 +75,10 @@ export default class InfioPlugin extends Plugin { // initialize dataview manager this.dataviewManager = createDataviewManager(this.app) + // initialize embedding manager + this.embeddingManager = new EmbeddingManager() + console.log('EmbeddingManager initialized') + // add icon to ribbon this.addRibbonIcon('wand-sparkles', t('main.openInfioCopilot'), () => this.openChatView(), @@ -426,16 +432,18 @@ export default class InfioPlugin extends Plugin { name: '测试本地嵌入模型', callback: async () => { try { - // 动态导入嵌入管理器 - const { embeddingManager } = await import('./embedworker/index'); - + if (!this.embeddingManager) { + new Notice('EmbeddingManager 未初始化', 5000); + return; + } + // 加载模型 - await embeddingManager.loadModel("Xenova/all-MiniLM-L6-v2", true); + await this.embeddingManager.loadModel("Xenova/all-MiniLM-L6-v2", true); // 测试嵌入 "hello world" const testText = "hello world"; - const result = await embeddingManager.embed(testText); + const result = await this.embeddingManager.embed(testText); // 显示结果 const resultMessage = ` @@ -480,6 +488,9 @@ export default class InfioPlugin extends Plugin { // MCP Hub cleanup this.mcpHub?.dispose() this.mcpHub = null + // EmbeddingManager cleanup + this.embeddingManager?.terminate() + this.embeddingManager = null // Dataview cleanup this.dataviewManager = null } @@ -638,6 +649,10 @@ export default class InfioPlugin extends Plugin { return this.transEngineInitPromise } + getEmbeddingManager(): EmbeddingManager | null { + return this.embeddingManager + } + private async migrateToJsonStorage() { try { const dbManager = await this.getDbManager()