UNPKG

vectorlite

Version:

A fast and tunable vector search extension for SQLite

34 lines (26 loc) 1.51 kB
# `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`. ```javascript 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); ```