diff --git a/.gitignore b/.gitignore index 9cf75ba..424562f 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ docs/AI回答.md # rag-worker (migrated to own project) rag-worker/ +uploads/ diff --git a/src/config/storage.config.ts b/src/config/storage.config.ts index cf2ddf8..4509dd6 100644 --- a/src/config/storage.config.ts +++ b/src/config/storage.config.ts @@ -1,7 +1,7 @@ import { registerAs } from '@nestjs/config'; export default registerAs('storage', () => ({ - driver: process.env.STORAGE_DRIVER || 'local', + driver: process.env.STORAGE_DRIVER || (process.env.NODE_ENV === 'production' ? 'cos' : 'local'), localPath: process.env.STORAGE_LOCAL_PATH || './uploads', cos: { secretId: process.env.STORAGE_COS_SECRET_ID || '', diff --git a/src/modules/rag/internal-rag.controller.ts b/src/modules/rag/internal-rag.controller.ts index 3e6b786..f82edb9 100644 --- a/src/modules/rag/internal-rag.controller.ts +++ b/src/modules/rag/internal-rag.controller.ts @@ -115,7 +115,7 @@ export class InternalRagController { const totalChars = sourceChunks.reduce((sum, c) => sum + (c.tokenCount || c.content?.length || 0), 0); await this.prisma.knowledgeSource.updateMany({ where: { id: sourceId }, - data: { textLength: totalChars, parseStatus: 'completed', updatedAt: new Date() }, + data: { textLength: totalChars, parseStatus: 'completed', indexStatus: 'completed', updatedAt: new Date() }, }); } } @@ -140,6 +140,15 @@ export class InternalRagController { body.importId, body.candidates || [], ); + + // 更新 source 的学习状态 + if (body.sourceId && body.candidates?.length > 0) { + await this.prisma.knowledgeSource.updateMany({ + where: { id: body.sourceId }, + data: { learningStatus: 'completed', updatedAt: new Date() }, + }); + } + return { success: true, count: body.candidates?.length || 0 }; } } diff --git a/src/workers/document-import.worker.ts b/src/workers/document-import.worker.ts index 5304a34..e8c2523 100644 --- a/src/workers/document-import.worker.ts +++ b/src/workers/document-import.worker.ts @@ -40,10 +40,9 @@ export class DocumentImportWorker extends WorkerHost { try { if (!rawText) { - await this.repository.updateStatus(importId, 'completed'); - await this.redis.set(`job:document-import:${importId}:status`, 'completed', 86400); - await this.redis.set(`job:document-import:${importId}:progress`, '100', 86400); - await this.redis.set(`job:document-import:${importId}:message`, '无需解析的空文件', 86400); + // 文件导入(PDF/Office 等),由 Python RAG Worker 处理 + // BullMQ Worker 只处理纯文本导入 + this.logger.log(`Skipping file import ${importId} — delegated to Python RAG Worker`); return; }