Check ai enabled before scheduling embeddings

This commit is contained in:
Hakan Shehu
2025-04-23 10:34:03 +02:00
parent 885f139521
commit 0b347db97c
3 changed files with 36 additions and 27 deletions

View File

@@ -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',

View File

@@ -11,7 +11,6 @@ import {
Node,
NodeAttributes,
UpdateNodeMutationData,
MessageAttributes,
} from '@colanode/core';
import { decodeState, YDoc } from '@colanode/crdt';
import { cloneDeep } from 'lodash-es';

View File

@@ -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,
},
}
);
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,
},
}
);
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() {