Skip to content

fix: SQLite vector table now respects OM_VECTOR_TABLE env variable - #80

Merged
nullure merged 1 commit into
CaviraOSS:mainfrom
fparrav:fix/sqlite-vector-table-name
Dec 2, 2025
Merged

fix: SQLite vector table now respects OM_VECTOR_TABLE env variable#80
nullure merged 1 commit into
CaviraOSS:mainfrom
fparrav:fix/sqlite-vector-table-name

Conversation

@fparrav

@fparrav fparrav commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Summary

Fixes SQLite backend ignoring the OM_VECTOR_TABLE environment variable, causing "no such table" errors on fresh Docker installs.

Problem

  • docker-compose.yml sets OM_VECTOR_TABLE=openmemory_vectors by default
  • SQLite was hardcoding the table name as vectors (ignoring the env variable)
  • VectorStore tried to use openmemory_vectors (from env)
  • Result: SQLITE_ERROR: no such table: openmemory_vectors

PostgreSQL already respected this env variable correctly.

Solution

Make SQLite table creation and index use the OM_VECTOR_TABLE env variable, with vectors as the default for backward compatibility with existing databases.

Changes

  • backend/src/core/db.ts:
    • Read OM_VECTOR_TABLE env variable (default: vectors)
    • Use variable in table creation instead of hardcoded name
    • Use variable in index creation
    • Use same variable for VectorStore initialization

Testing

  1. Fresh Docker install with default config now works
  2. Existing SQLite databases with vectors table still work (backward compatible)
  3. TypeScript compiles without errors

- SQLite was hardcoding table name as 'vectors' while docker-compose
  sets OM_VECTOR_TABLE=openmemory_vectors by default
- This caused 'no such table: openmemory_vectors' error on fresh installs
- PostgreSQL already respected this env variable, now SQLite does too
- Default remains 'vectors' for backward compatibility with existing DBs
Copilot AI review requested due to automatic review settings December 2, 2025 15:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug where the SQLite backend was ignoring the OM_VECTOR_TABLE environment variable, causing "no such table" errors in fresh Docker installations. The fix ensures SQLite respects the environment variable while maintaining backward compatibility with existing databases.

  • Reads OM_VECTOR_TABLE environment variable with vectors as default for backward compatibility
  • Updates SQLite table creation and index creation to use the configurable table name
  • Aligns SQLite behavior with PostgreSQL, which already respected this environment variable

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/src/core/db.ts
);
db.run(
`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))`,
`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))`,

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table name from the environment variable is directly interpolated into the SQL statement without proper escaping or validation. While PostgreSQL uses quoted identifiers (line 92), SQLite does not, potentially allowing SQL injection if OM_VECTOR_TABLE contains malicious input like vectors; DROP TABLE memories--.

Consider either:

  1. Adding validation to ensure the table name contains only safe characters (alphanumeric and underscores)
  2. Using quoted identifiers similar to PostgreSQL: `create table if not exists "${sqlite_vector_table}"(...)`

Example validation:

const sqlite_vector_table = process.env.OM_VECTOR_TABLE || "vectors";
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(sqlite_vector_table)) {
    throw new Error(`Invalid table name: ${sqlite_vector_table}`);
}

Copilot uses AI. Check for mistakes.
Comment thread backend/src/core/db.ts
);
db.run(
"create index if not exists idx_vectors_user on vectors(user_id)",
`create index if not exists idx_vectors_user on ${sqlite_vector_table}(user_id)`,

Copilot AI Dec 2, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The table name from the environment variable is directly interpolated into the SQL statement without proper escaping or validation. This creates the same SQL injection vulnerability as the table creation statement.

Apply the same validation or escaping approach as recommended for the table creation to ensure consistency and security.

Copilot uses AI. Check for mistakes.
@nullure
nullure merged commit dc95dde into CaviraOSS:main Dec 2, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants