Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Update embedding configuration and scheduling for documents and nodes

Ylber Gashia7eda1f74612
diff --git a/apps/server/src/lib/configuration.ts b/apps/server/src/lib/configuration.ts
index a814c9b7..2b3340b8 100644
--- a/apps/server/src/lib/configuration.ts
+++ b/apps/server/src/lib/configuration.ts
@@ -84,7 +84,7 @@ export interface AIModelConfiguration {
export interface AiConfiguration {
enabled: boolean;
- nodeEmbedDelay: number;
+ embedDelay: number;
providers: {
openai: AIProviderConfiguration;
google: AIProviderConfiguration;
@@ -207,7 +207,7 @@ export const configuration: Configuration = {
},
ai: {
enabled: getOptionalEnv('AI_ENABLED') === 'true',
- nodeEmbedDelay: parseInt(getOptionalEnv('AI_NODE_EMBED_DELAY') || '10000'),
+ embedDelay: parseInt(getOptionalEnv('AI_EMBED_DELAY') || '10000'),
providers: {
openai: {
apiKey: getOptionalEnv('OPENAI_API_KEY') || '',
diff --git a/apps/server/src/lib/documents.ts b/apps/server/src/lib/documents.ts
index 299cdb93..55638f94 100644
--- a/apps/server/src/lib/documents.ts
+++ b/apps/server/src/lib/documents.ts
@@ -10,6 +10,8 @@ import { SelectUser } from '@/data/schema';
import { ConcurrentUpdateResult, UpdateDocumentOutput } from '@/types/nodes';
import { eventBus } from '@/lib/event-bus';
import { fetchNode } from '@/lib/nodes';
+import { jobService } from '@/services/job-service';
+import { configuration } from './configuration';
const debug = createDebugger('server:lib:documents');
@@ -170,6 +172,8 @@ const tryUpdateDocumentFromMutation = async (
workspaceId: user.workspace_id,
});
+ await scheduleDocumentEmbedding(mutation.documentId);
+
return {
type: 'success',
output: {
@@ -181,3 +185,16 @@ const tryUpdateDocumentFromMutation = async (
return { type: 'retry', output: null };
}
};
+
+async function scheduleDocumentEmbedding(documentId: string) {
+ await jobService.addJob(
+ {
+ type: 'embed_document',
+ documentId,
+ },
+ {
+ jobId: `embed_document:${documentId}`,
+ delay: configuration.ai.embedDelay,
+ }
+ );
+}
diff --git a/apps/server/src/lib/nodes.ts b/apps/server/src/lib/nodes.ts
index c3c771c7..37b83397 100644
--- a/apps/server/src/lib/nodes.ts
+++ b/apps/server/src/lib/nodes.ts
@@ -668,7 +668,7 @@ async function scheduleNodeEmbedding(nodeId: string) {
},
{
jobId: `embed_node:${nodeId}`,
- delay: configuration.ai.nodeEmbedDelay,
+ delay: configuration.ai.embedDelay,
}
);
}