JavaScript · Quickstart

Quickstart

3.0.0-rc.1 · 4c3e5023

Create an index, insert a vector, and search it on an executor, writing the matches into an arena:

const assert = require('node:assert');
const usearch = require('usearch');

const index = usearch.DenseIndex.initRam({ metric: usearch.DenseMetric.Euclidean, connectivity: 16, dimensions: 3 });
index.insert(42n, new Float32Array([0.2, 0.6, 0.4]));

const executor = usearch.Executor.forRam(); // Absent counts derive the worker count from the hardware
const arena = new usearch.Arena(executor); // Memory where the executor computes, reused by every call
const matches = index.on(executor).search(new Float32Array([0.2, 0.6, 0.4]), 10, arena); // One query, up to ten matches
const found = matches.get(0);

assert(index.describe().size === 1);
assert.deepEqual(found.keys, usearch.keyFromInteger(42n));
assert(found.scores[0] === 0);