From 104b02b02f2e3114b85563749087d28b46088ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CBeeRad=E2=80=9D?= Date: Thu, 29 Jan 2026 20:52:07 +1100 Subject: [PATCH] fix: disable vector setup when embeddings disabled --- app/api/nodes/route.ts | 2 +- src/services/database/sqlite-client.ts | 33 ++++++++++++++++-------- src/services/embedding/autoEmbedQueue.ts | 7 +++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/api/nodes/route.ts b/app/api/nodes/route.ts index 8469b2d..3204e5a 100644 --- a/app/api/nodes/route.ts +++ b/app/api/nodes/route.ts @@ -123,7 +123,7 @@ export async function POST(request: NextRequest) { metadata: body.metadata || {} }); - if (chunkStatus === 'not_chunked' && node.id) { + if (chunkStatus === 'not_chunked' && node.id && process.env.DISABLE_EMBEDDINGS !== 'true') { autoEmbedQueue.enqueue(node.id, { reason: 'node_created' }); } diff --git a/src/services/database/sqlite-client.ts b/src/services/database/sqlite-client.ts index 0fc46e3..90323eb 100644 --- a/src/services/database/sqlite-client.ts +++ b/src/services/database/sqlite-client.ts @@ -19,10 +19,12 @@ class SQLiteClient { private db: Database.Database; private config: SQLiteConfig; private readonly readOnly: boolean; + private readonly embeddingsDisabled: boolean; private constructor() { this.config = this.getSQLiteConfig(); this.readOnly = process.env.SQLITE_READONLY === 'true'; + this.embeddingsDisabled = process.env.DISABLE_EMBEDDINGS === 'true'; // Initialize database connection const dbDirectory = path.dirname(this.config.dbPath); @@ -33,13 +35,15 @@ class SQLiteClient { ? new Database(this.config.dbPath, { readonly: true, fileMustExist: true }) : new Database(this.config.dbPath); - // Load sqlite-vec extension - try { - this.db.loadExtension(this.config.vecExtensionPath); - console.log('SQLite vector extension loaded successfully'); - } catch (error) { - // Do not fail hard — allow the app to run without vector features - console.error('Warning: Failed to load vector extension:', error); + // Load sqlite-vec extension (skip entirely if embeddings are disabled) + if (!this.embeddingsDisabled) { + try { + this.db.loadExtension(this.config.vecExtensionPath); + console.log('SQLite vector extension loaded successfully'); + } catch (error) { + // Do not fail hard — allow the app to run without vector features + console.error('Warning: Failed to load vector extension:', error); + } } // Configure SQLite settings @@ -57,9 +61,11 @@ class SQLiteClient { this.db.pragma('temp_store = memory'); this.db.pragma('busy_timeout = 5000'); - // Ensure vector virtual tables are present and healthy - this.ensureVectorTables(); - this.healVectorTablesIfCorrupt(); + // Ensure vector virtual tables are present and healthy (skip if disabled) + if (!this.embeddingsDisabled) { + this.ensureVectorTables(); + this.healVectorTablesIfCorrupt(); + } // Ensure logging schema (rename memory->logs if needed, create triggers/views) this.ensureLoggingAndMemorySchema(); @@ -134,7 +140,9 @@ class SQLiteClient { } as DatabaseError; } // Proactively validate/repair vec vtables before any write transaction - this.healVectorTablesIfCorrupt(); + if (!this.embeddingsDisabled) { + this.healVectorTablesIfCorrupt(); + } const txn = this.db.transaction(callback); try { return txn(); @@ -154,6 +162,9 @@ class SQLiteClient { } public async checkVectorExtension(): Promise { + if (this.embeddingsDisabled) { + return false; + } try { const result = this.query('SELECT vec_version() as version'); return result.rows.length > 0; diff --git a/src/services/embedding/autoEmbedQueue.ts b/src/services/embedding/autoEmbedQueue.ts index 7978b68..b67d88e 100644 --- a/src/services/embedding/autoEmbedQueue.ts +++ b/src/services/embedding/autoEmbedQueue.ts @@ -16,8 +16,12 @@ export class AutoEmbedQueue { private readonly lastRunAt = new Map(); private readonly maxConcurrent = 1; private readonly cooldownMs = DEFAULT_COOLDOWN_MS; + private readonly embeddingsDisabled = process.env.DISABLE_EMBEDDINGS === 'true'; enqueue(nodeId: number, task: Omit = {}): boolean { + if (this.embeddingsDisabled && !task.force) { + return false; + } const existing = this.pendingTasks.get(nodeId); if (!existing) { this.pendingTasks.set(nodeId, { nodeId, ...task }); @@ -73,6 +77,9 @@ export class AutoEmbedQueue { } private async executeTask(task: AutoEmbedTask) { + if (this.embeddingsDisabled && !task.force) { + return; + } const node = await nodeService.getNodeById(task.nodeId); if (!node) { console.warn('[AutoEmbedQueue] Node missing, skipping', task.nodeId);