vectorlite
v0.2.0
Published
A fast and tunable vector search extension for SQLite
Downloads
14
Maintainers
Readme
vectorlite
for nodejs
Vectorlite is a fast and tunable vector search extension for SQLite. For more info, please check https://github.com/1yefuwang1/vectorlite.
Example
Below is an example of using it with better-sqlite3
.
const sqlite3 = require('better-sqlite3');
const vectorlite = require('vectorlite');
const db = new sqlite3(':memory:');
db.loadExtension(vectorlite.vectorlitePath());
console.log(db.prepare('select vectorlite_info()').all());
// Create a vectorlite virtual table hosting 10-dimensional float32 vectors with hnsw index
db.exec('create virtual table test using vectorlite(vec float32[10], hnsw(max_elements=100));')
// insert a json vector
db.prepare('insert into test(rowid, vec) values (?, vector_from_json(?))').run([0, JSON.stringify(Array.from({length: 10}, () => Math.random()))]);
// insert a raw vector
db.prepare('insert into test(rowid, vec) values (?, ?)').run([1, Buffer.from(Float32Array.from(Array.from({length: 10}, () => Math.random())).buffer)]);
// a normal vector query
let result = db.prepare('select rowid from test where knn_search(vec, knn_param(?, 2))')
.all([Buffer.from(Float32Array.from(Array.from({length: 10}, () => Math.random())).buffer)]);
console.log(result);
// a vector query with rowid filter
result = db.prepare('select rowid from test where knn_search(vec, knn_param(?, 2)) and rowid in (1,2,3)')
.all([Buffer.from(Float32Array.from(Array.from({length: 10}, () => Math.random())).buffer)]);
console.log(result);