vectorlite

0.2.0 • Public • Published

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);

Package Sidebar

Install

npm i vectorlite

Weekly Downloads

281

Version

0.2.0

License

Apache-2.0

Unpacked Size

3.08 kB

Total Files

3

Last publish

Collaborators

  • 1yefuwang1