RAG: ночная пакетная индексация эмбеддингов, очередь embedding_queue, MCP get_organization_context, снижение OLLAMA_KEEP_ALIVE
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { users, forms } from "@shared/schema";
|
||||
import { ragSettings, type RagSetting } from "@shared/schema";
|
||||
import { embeddingQueue } from "@shared/schema";
|
||||
import { llmProviders, type LlmProvider, type InsertLlmProvider } from "@shared/schema";
|
||||
import { taskRoles, type TaskRole, taskUserAccess, type TaskUserAccess, roleMembers, roles, taskAssignees, type TaskAssignee, formAccessRules, type FormAccessRule, type InsertFormAccessRule } from "@shared/schema";
|
||||
import { db } from "../db";
|
||||
@@ -439,4 +440,56 @@ export class SystemStorage extends RolesStorage {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Embedding Queue
|
||||
// =====================
|
||||
|
||||
async enqueueEmbedding(
|
||||
organizationId: number,
|
||||
entityType: 'form' | 'task' | 'task_message',
|
||||
entityId: number,
|
||||
operation: 'upsert' | 'delete' = 'upsert'
|
||||
): Promise<void> {
|
||||
await db
|
||||
.insert(embeddingQueue)
|
||||
.values({
|
||||
organizationId,
|
||||
entityType,
|
||||
entityId,
|
||||
operation,
|
||||
createdAt: new Date(),
|
||||
})
|
||||
.onConflictDoNothing({ target: [embeddingQueue.organizationId, embeddingQueue.entityType, embeddingQueue.entityId] });
|
||||
}
|
||||
|
||||
async getPendingEmbeddingQueue(
|
||||
limit: number = 1000
|
||||
): Promise<Array<{ id: number; organizationId: number; entityType: 'form' | 'task' | 'task_message'; entityId: number; operation: 'upsert' | 'delete' }>> {
|
||||
const rows = await db
|
||||
.select({
|
||||
id: embeddingQueue.id,
|
||||
organizationId: embeddingQueue.organizationId,
|
||||
entityType: embeddingQueue.entityType,
|
||||
entityId: embeddingQueue.entityId,
|
||||
operation: embeddingQueue.operation,
|
||||
})
|
||||
.from(embeddingQueue)
|
||||
.where(isNull(embeddingQueue.processedAt))
|
||||
.orderBy(asc(embeddingQueue.createdAt))
|
||||
.limit(limit);
|
||||
return rows as Array<{ id: number; organizationId: number; entityType: 'form' | 'task' | 'task_message'; entityId: number; operation: 'upsert' | 'delete' }>;
|
||||
}
|
||||
|
||||
async markEmbeddingQueueProcessed(ids: number[]): Promise<void> {
|
||||
if (ids.length === 0) return;
|
||||
await db
|
||||
.update(embeddingQueue)
|
||||
.set({ processedAt: new Date() })
|
||||
.where(inArray(embeddingQueue.id, ids));
|
||||
}
|
||||
|
||||
async clearEmbeddingQueue(): Promise<void> {
|
||||
await db.delete(embeddingQueue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user