Database instance (supports node:sqlite, better-sqlite3, @photostructure/sqlite)
Name of the DiskANN virtual table
Query vector as Float32Array or number[] (must match index dimension)
Number of neighbors to return (default: 10)
Optionaloptions: SearchOptionsArray of k nearest neighbors sorted by distance, including any metadata columns
// Basic search
const vec = new Float32Array([0.1, 0.2, 0.3]);
const results = searchNearest(db, "embeddings", vec, 10);
results.forEach(({ rowid, distance }) => {
console.log(`ID: ${rowid}, Distance: ${distance}`);
});
// With metadata columns (use raw SQL for filtering)
const stmt = db.prepare(`
SELECT rowid, distance, category, year
FROM photos
WHERE vector MATCH ? AND k = ? AND category = 'landscape'
`);
const filtered = stmt.all(vec, 10);
Search for k nearest neighbors in a DiskANN index