tursodatabase / tursodatabase/libsql-js
Panic (unwrap on None) reading sqlite-vec vec0 KNN results — SELECT ... WHERE embedding MATCH ?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 335
- Forks
- 48
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 3
Description
Summary
Loading the sqlite-vec extension into a libsql database works, and a vec0 virtual table can be created, inserted into, and counted — but the KNN search query (... WHERE embedding MATCH ? ORDER BY distance) panics the native driver with called Option::unwrap() on a None value, aborting the process. This is the one operation that makes a vector extension useful, so sqlite-vec is effectively unusable via libsql.
Reproduced on both the latest stable libsql@0.5.29 and the latest prerelease libsql@0.6.0-pre.41.
Environment
libsql:0.5.29(and0.6.0-pre.41)sqlite-vec:0.1.9- Node.js:
v25.8.0 - OS: macOS, arm64
Minimal reproduction
const Database = require('libsql');
const sqliteVec = require('sqlite-vec');
const db = new Database(':memory:');
sqliteVec.load(db);
console.log(db.prepare('select vec_version() v').get()); // ✓ works
db.exec('CREATE VIRTUAL TABLE t USING vec0(embedding float[4])'); // ✓ works
const f = a => Buffer.from(new Float32Array(a).buffer);
db.prepare('INSERT INTO t(rowid, embedding) VALUES (?, ?)').run(1n, f([1, 0, 0, 0])); // ✓ works
console.log(db.prepare('SELECT count(*) c FROM t').get()); // ✓ works -> { c: 1 }
// ✗ PANICS:
db.prepare('SELECT rowid, distance FROM t WHERE embedding MATCH ? ORDER BY distance LIMIT 1')
.all(f([1, 0, 0, 0]));
Expected
The KNN query returns the nearest rows with their distance values (as it does under better-sqlite3 with the same extension).
Actual
thread '<unnamed>' panicked at src/statement.rs:396:62:
called `Option::unwrap()` on a `None` value
On 0.6.0-pre.41 the same query panics at src/lib.rs:1354:58 (fatal runtime error: failed to initiate panic, error 5, aborting).
Notes
load/CREATE VIRTUAL TABLE vec0/INSERT/SELECT count(*)all succeed — only thevec0KNN result (which surfaces the hiddendistancecolumn via theMATCHconstraint) fails. The panic looks like the driver assuming column metadata that avec0virtual-table result doesn't provide.- The identical extension + query works under
better-sqlite3. - A
panic::catch_unwind(or gracefulSqliteError) instead of anunwrap()would at least keep it recoverable, but the underlying goal is to readvec0KNN results.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the panic locations identified in src/statement.rs:396 and src/lib.rs:1354, then run the minimal Node.js reproduction against the supported versions. Compare the KNN query behavior with better-sqlite3. Done means the vec0 query no longer panics and returns the nearest row with its distance value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 64/100