fix: disable vector setup when embeddings disabled
This commit is contained in:
@@ -123,7 +123,7 @@ export async function POST(request: NextRequest) {
|
|||||||
metadata: body.metadata || {}
|
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' });
|
autoEmbedQueue.enqueue(node.id, { reason: 'node_created' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,12 @@ class SQLiteClient {
|
|||||||
private db: Database.Database;
|
private db: Database.Database;
|
||||||
private config: SQLiteConfig;
|
private config: SQLiteConfig;
|
||||||
private readonly readOnly: boolean;
|
private readonly readOnly: boolean;
|
||||||
|
private readonly embeddingsDisabled: boolean;
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
this.config = this.getSQLiteConfig();
|
this.config = this.getSQLiteConfig();
|
||||||
this.readOnly = process.env.SQLITE_READONLY === 'true';
|
this.readOnly = process.env.SQLITE_READONLY === 'true';
|
||||||
|
this.embeddingsDisabled = process.env.DISABLE_EMBEDDINGS === 'true';
|
||||||
|
|
||||||
// Initialize database connection
|
// Initialize database connection
|
||||||
const dbDirectory = path.dirname(this.config.dbPath);
|
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, { readonly: true, fileMustExist: true })
|
||||||
: new Database(this.config.dbPath);
|
: new Database(this.config.dbPath);
|
||||||
|
|
||||||
// Load sqlite-vec extension
|
// Load sqlite-vec extension (skip entirely if embeddings are disabled)
|
||||||
try {
|
if (!this.embeddingsDisabled) {
|
||||||
this.db.loadExtension(this.config.vecExtensionPath);
|
try {
|
||||||
console.log('SQLite vector extension loaded successfully');
|
this.db.loadExtension(this.config.vecExtensionPath);
|
||||||
} catch (error) {
|
console.log('SQLite vector extension loaded successfully');
|
||||||
// Do not fail hard — allow the app to run without vector features
|
} catch (error) {
|
||||||
console.error('Warning: Failed to load vector extension:', 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
|
// Configure SQLite settings
|
||||||
@@ -57,9 +61,11 @@ class SQLiteClient {
|
|||||||
this.db.pragma('temp_store = memory');
|
this.db.pragma('temp_store = memory');
|
||||||
this.db.pragma('busy_timeout = 5000');
|
this.db.pragma('busy_timeout = 5000');
|
||||||
|
|
||||||
// Ensure vector virtual tables are present and healthy
|
// Ensure vector virtual tables are present and healthy (skip if disabled)
|
||||||
this.ensureVectorTables();
|
if (!this.embeddingsDisabled) {
|
||||||
this.healVectorTablesIfCorrupt();
|
this.ensureVectorTables();
|
||||||
|
this.healVectorTablesIfCorrupt();
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure logging schema (rename memory->logs if needed, create triggers/views)
|
// Ensure logging schema (rename memory->logs if needed, create triggers/views)
|
||||||
this.ensureLoggingAndMemorySchema();
|
this.ensureLoggingAndMemorySchema();
|
||||||
@@ -134,7 +140,9 @@ class SQLiteClient {
|
|||||||
} as DatabaseError;
|
} as DatabaseError;
|
||||||
}
|
}
|
||||||
// Proactively validate/repair vec vtables before any write transaction
|
// Proactively validate/repair vec vtables before any write transaction
|
||||||
this.healVectorTablesIfCorrupt();
|
if (!this.embeddingsDisabled) {
|
||||||
|
this.healVectorTablesIfCorrupt();
|
||||||
|
}
|
||||||
const txn = this.db.transaction(callback);
|
const txn = this.db.transaction(callback);
|
||||||
try {
|
try {
|
||||||
return txn();
|
return txn();
|
||||||
@@ -154,6 +162,9 @@ class SQLiteClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async checkVectorExtension(): Promise<boolean> {
|
public async checkVectorExtension(): Promise<boolean> {
|
||||||
|
if (this.embeddingsDisabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const result = this.query('SELECT vec_version() as version');
|
const result = this.query('SELECT vec_version() as version');
|
||||||
return result.rows.length > 0;
|
return result.rows.length > 0;
|
||||||
|
|||||||
@@ -16,8 +16,12 @@ export class AutoEmbedQueue {
|
|||||||
private readonly lastRunAt = new Map<number, number>();
|
private readonly lastRunAt = new Map<number, number>();
|
||||||
private readonly maxConcurrent = 1;
|
private readonly maxConcurrent = 1;
|
||||||
private readonly cooldownMs = DEFAULT_COOLDOWN_MS;
|
private readonly cooldownMs = DEFAULT_COOLDOWN_MS;
|
||||||
|
private readonly embeddingsDisabled = process.env.DISABLE_EMBEDDINGS === 'true';
|
||||||
|
|
||||||
enqueue(nodeId: number, task: Omit<AutoEmbedTask, 'nodeId'> = {}): boolean {
|
enqueue(nodeId: number, task: Omit<AutoEmbedTask, 'nodeId'> = {}): boolean {
|
||||||
|
if (this.embeddingsDisabled && !task.force) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const existing = this.pendingTasks.get(nodeId);
|
const existing = this.pendingTasks.get(nodeId);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
this.pendingTasks.set(nodeId, { nodeId, ...task });
|
this.pendingTasks.set(nodeId, { nodeId, ...task });
|
||||||
@@ -73,6 +77,9 @@ export class AutoEmbedQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async executeTask(task: AutoEmbedTask) {
|
private async executeTask(task: AutoEmbedTask) {
|
||||||
|
if (this.embeddingsDisabled && !task.force) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const node = await nodeService.getNodeById(task.nodeId);
|
const node = await nodeService.getNodeById(task.nodeId);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
console.warn('[AutoEmbedQueue] Node missing, skipping', task.nodeId);
|
console.warn('[AutoEmbedQueue] Node missing, skipping', task.nodeId);
|
||||||
|
|||||||
Reference in New Issue
Block a user