Skip to content

0.1.7-alpha: INSERT into vec0 fails with 'Only integers are allowed for primary key values' when onnxruntime-node is loaded in the same Node.js process #270

@AhmedBytesBits

Description

@AhmedBytesBits

Environment

  • sqlite-vec npm version: 0.1.7-alpha.2 (regression from 0.1.6)
  • Platform: darwin arm64 (macOS, Apple Silicon)
  • Node.js: v22.22.0
  • Package: sqlite-vec npm + better-sqlite3 v12.6.2
  • Also affected: sqlite-vec 0.1.7-alpha.1 (same alpha series)

Description

After loading onnxruntime-node (which is a dependency of @huggingface/transformers) in the same Node.js process, all INSERT statements into a vec0 virtual table via better-sqlite3 prepared statements fail with:

SqliteError: Only integers are allows for primary key values on vec_aya_editions

Note: the typo ("allows" instead of "allowed") is present in the error message.

This error occurs even when:

  • The rowid value is a plain JavaScript number (e.g. 1)
  • The rowid is declared as rowid integer primary key in the CREATE statement
  • The embedding blob is a valid Uint8Array of the correct size

Workaround: Passing BigInt(id) instead of a plain number for the rowid parameter resolves the issue with 0.1.7-alpha.2. This workaround is not needed with 0.1.6.

Reproduction

import Database from 'better-sqlite3';
import * as sqliteVec from 'sqlite-vec';
import { pipeline } from '@huggingface/transformers'; // loads onnxruntime-node internally

const db = new Database(':memory:');
sqliteVec.load(db);
db.exec('CREATE VIRTUAL TABLE t USING vec0(rowid integer primary key, embedding float[4])');

const emb = new Uint8Array(new Float32Array([1, 2, 3, 4]).buffer);

// ✅ Works BEFORE onnxruntime-node loads
db.prepare('INSERT INTO t(rowid, embedding) VALUES (1, ?)').run(emb);

// Load a model (triggers onnxruntime-node native library load)
await pipeline('feature-extraction', 'Xenova/multilingual-e5-base');

// ❌ Fails AFTER onnxruntime-node loads — "Only integers are allows for primary key values"
db.prepare('INSERT INTO t(rowid, embedding) VALUES (2, ?)').run(emb);

// ✅ Workaround: use BigInt for rowid
db.prepare('INSERT INTO t(rowid, embedding) VALUES (?, ?)').run(BigInt(2), emb);

Root Cause (hypothesis)

onnxruntime-node loads native .node/.dylib binaries via dlopen, which appears to affect SQLite's internal parameter type enforcement for vec0 virtual tables. The change only affects the npm package's dylib — the Python (sqlite-vec PyPI 0.1.6) version is unaffected. This suggests a difference in how the vec0 extension compiled into the 0.1.7-alpha npm package handles integer type checking compared to 0.1.6.

Impact

This breaks the common pattern of using @huggingface/transformers for embedding generation alongside sqlite-vec for storage in the same Node.js server process.

Regression

This bug is not present in sqlite-vec 0.1.6 — the same code works correctly on that version without the BigInt workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions