Skip to content

Commit dc95dde

Browse files
authored
Merge pull request #80 from fparrav/fix/sqlite-vector-table-name
fix: SQLite vector table now respects OM_VECTOR_TABLE env variable
2 parents 8eedb89 + c4ee7f0 commit dc95dde

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

backend/src/core/db.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ if (is_pg) {
420420
const dir = path.dirname(db_path);
421421
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
422422
const db = new sqlite3.Database(db_path);
423+
// SQLite vector table name from env (default: "vectors" for backward compatibility)
424+
const sqlite_vector_table = process.env.OM_VECTOR_TABLE || "vectors";
423425
db.serialize(() => {
424426
db.run("PRAGMA journal_mode=WAL");
425427
db.run("PRAGMA synchronous=NORMAL");
@@ -434,7 +436,7 @@ if (is_pg) {
434436
`create table if not exists memories(id text primary key,user_id text,segment integer default 0,content text not null,simhash text,primary_sector text not null,tags text,meta text,created_at integer,updated_at integer,last_seen_at integer,salience real,decay_lambda real,version integer default 1,mean_dim integer,mean_vec blob,compressed_vec blob,feedback_score real default 0)`,
435437
);
436438
db.run(
437-
`create table if not exists vectors(id text not null,sector text not null,user_id text,v blob not null,dim integer not null,primary key(id,sector))`,
439+
`create table if not exists ${sqlite_vector_table}(id text not null,sector text not null,user_id text,v blob not null,dim integer not null,primary key(id,sector))`,
438440
);
439441
db.run(
440442
`create table if not exists waypoints(src_id text,dst_id text not null,user_id text,weight real not null,created_at integer,updated_at integer,primary key(src_id,user_id))`,
@@ -470,7 +472,7 @@ if (is_pg) {
470472
"create index if not exists idx_memories_user on memories(user_id)",
471473
);
472474
db.run(
473-
"create index if not exists idx_vectors_user on vectors(user_id)",
475+
`create index if not exists idx_vectors_user on ${sqlite_vector_table}(user_id)`,
474476
);
475477
db.run(
476478
"create index if not exists idx_waypoints_src on waypoints(src_id)",
@@ -540,9 +542,8 @@ if (is_pg) {
540542
vector_store = new ValkeyVectorStore();
541543
console.log("[DB] Using Valkey VectorStore");
542544
} else {
543-
const vt = process.env.OM_VECTOR_TABLE || "vectors";
544-
vector_store = new PostgresVectorStore({ run_async, get_async, all_async }, vt);
545-
console.log(`[DB] Using SQLite VectorStore with table: ${vt}`);
545+
vector_store = new PostgresVectorStore({ run_async, get_async, all_async }, sqlite_vector_table);
546+
console.log(`[DB] Using SQLite VectorStore with table: ${sqlite_vector_table}`);
546547
}
547548

548549
transaction = {

0 commit comments

Comments
 (0)