This commit is contained in:
Philipinho
2025-10-17 21:58:40 +01:00
parent bf877fe5de
commit 93f6c1986d
3 changed files with 23 additions and 7 deletions

View File

@ -50,6 +50,7 @@ export class WorkspaceService {
@InjectKysely() private readonly db: KyselyDB, @InjectKysely() private readonly db: KyselyDB,
@InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue, @InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue,
@InjectQueue(QueueName.BILLING_QUEUE) private billingQueue: Queue, @InjectQueue(QueueName.BILLING_QUEUE) private billingQueue: Queue,
@InjectQueue(QueueName.AI_QUEUE) private aiQueue: Queue,
) {} ) {}
async findById(workspaceId: string) { async findById(workspaceId: string) {
@ -315,22 +316,36 @@ export class WorkspaceService {
if (typeof updateWorkspaceDto.aiSearch !== 'undefined') { if (typeof updateWorkspaceDto.aiSearch !== 'undefined') {
await this.workspaceRepo.updateAiSettings( await this.workspaceRepo.updateAiSettings(
workspaceId, workspaceId,
'aiSearch', 'search',
updateWorkspaceDto.aiSearch, updateWorkspaceDto.aiSearch,
); );
// to enable this if (updateWorkspaceDto.aiSearch) {
// we need to check if pgvector and embeddings table exists await this.aiQueue.add(QueueJob.WORKSPACE_CREATE_EMBEDDINGS, {
workspaceId,
});
} else {
// Schedule deletion after 24 hours
const deleteJobId = `ai-search-disabled-${workspaceId}`;
await this.aiQueue.add(
QueueJob.WORKSPACE_DELETE_EMBEDDINGS,
{ workspaceId },
{
jobId: deleteJobId,
delay: 24 * 60 * 60 * 1000,
removeOnComplete: true,
removeOnFail: true,
},
);
}
delete updateWorkspaceDto.aiSearch; delete updateWorkspaceDto.aiSearch;
// if true, send to ai queue
// if false, send to delete embeddings
} }
if (typeof updateWorkspaceDto.generativeAi !== 'undefined') { if (typeof updateWorkspaceDto.generativeAi !== 'undefined') {
await this.workspaceRepo.updateAiSettings( await this.workspaceRepo.updateAiSettings(
workspaceId, workspaceId,
'generativeAi', 'generative',
updateWorkspaceDto.generativeAi, updateWorkspaceDto.generativeAi,
); );
delete updateWorkspaceDto.generativeAi; delete updateWorkspaceDto.generativeAi;

View File

@ -53,6 +53,7 @@ export enum QueueJob {
WORKSPACE_CREATED = 'workspace-created', WORKSPACE_CREATED = 'workspace-created',
WORKSPACE_SPACE_UPDATED = 'workspace-updated', WORKSPACE_SPACE_UPDATED = 'workspace-updated',
WORKSPACE_DELETED = 'workspace-deleted', WORKSPACE_DELETED = 'workspace-deleted',
WORKSPACE_CREATE_EMBEDDINGS = 'workspace-create-embeddings',
WORKSPACE_DELETE_EMBEDDINGS = 'workspace-delete-embeddings', WORKSPACE_DELETE_EMBEDDINGS = 'workspace-delete-embeddings',
GENERATE_PAGE_EMBEDDINGS = 'generate-page-embeddings', GENERATE_PAGE_EMBEDDINGS = 'generate-page-embeddings',