Skip to content

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

Check ai enabled before scheduling embeddings

Hakan Shehu0b347db97ce7
diff --git a/apps/server/src/lib/embeddings.ts b/apps/server/src/lib/embeddings.ts
index 0b950a1f..bb34d567 100644
--- a/apps/server/src/lib/embeddings.ts
+++ b/apps/server/src/lib/embeddings.ts
@@ -28,6 +28,10 @@ export const deleteEmbeddingCursor = async (cursorId: string) => {
};
export const scheduleNodeEmbedding = async (node: SelectNode) => {
+ if (!configuration.ai.enabled) {
+ return;
+ }
+
if (node.type === 'message') {
const attributes = node.attributes as MessageAttributes;
if (attributes.subtype === 'question' || attributes.subtype === 'answer') {
@@ -54,6 +58,10 @@ export const scheduleNodeEmbedding = async (node: SelectNode) => {
};
export const scheduleDocumentEmbedding = async (documentId: string) => {
+ if (!configuration.ai.enabled) {
+ return;
+ }
+
await jobService.addJob(
{
type: 'embed_document',
diff --git a/apps/server/src/lib/nodes.ts b/apps/server/src/lib/nodes.ts
index 9bfafe18..73b0450b 100644
--- a/apps/server/src/lib/nodes.ts
+++ b/apps/server/src/lib/nodes.ts
@@ -11,7 +11,6 @@ import {
Node,
NodeAttributes,
UpdateNodeMutationData,
- MessageAttributes,
} from '@colanode/core';
import { decodeState, YDoc } from '@colanode/crdt';
import { cloneDeep } from 'lodash-es';
diff --git a/apps/server/src/services/job-service.ts b/apps/server/src/services/job-service.ts
index f52e9787..e4c396cc 100644
--- a/apps/server/src/services/job-service.ts
+++ b/apps/server/src/services/job-service.ts
@@ -40,33 +40,35 @@ class JobService {
debug(`Job queue error: ${error}`);
});
- this.jobQueue.upsertJobScheduler(
- 'check_node_embeddings',
- { pattern: '0 */30 * * * *' },
- {
- name: 'check_node_embeddings',
- data: { type: 'check_node_embeddings' } as JobInput,
- opts: {
- backoff: 3,
- attempts: 5,
- removeOnFail: 1000,
- },
- }
- );
-
- this.jobQueue.upsertJobScheduler(
- 'check_document_embeddings',
- { pattern: '0 */30 * * * *' },
- {
- name: 'check_document_embeddings',
- data: { type: 'check_document_embeddings' } as JobInput,
- opts: {
- backoff: 3,
- attempts: 5,
- removeOnFail: 1000,
- },
- }
- );
+ if (configuration.ai.enabled) {
+ this.jobQueue.upsertJobScheduler(
+ 'check_node_embeddings',
+ { pattern: '0 */30 * * * *' },
+ {
+ name: 'check_node_embeddings',
+ data: { type: 'check_node_embeddings' } as JobInput,
+ opts: {
+ backoff: 3,
+ attempts: 5,
+ removeOnFail: 1000,
+ },
+ }
+ );
+
+ this.jobQueue.upsertJobScheduler(
+ 'check_document_embeddings',
+ { pattern: '0 */30 * * * *' },
+ {
+ name: 'check_document_embeddings',
+ data: { type: 'check_document_embeddings' } as JobInput,
+ opts: {
+ backoff: 3,
+ attempts: 5,
+ removeOnFail: 1000,
+ },
+ }
+ );
+ }
}
public async initWorker() {