npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ruvector/acorn-wasm

v0.1.0

Published

ACORN predicate-agnostic filtered HNSW in WebAssembly — high-recall vector search with arbitrary metadata filters, for browsers, Cloudflare Workers, Deno, and Bun

Readme

@ruvector/acorn-wasm

ACORN predicate-agnostic filtered HNSW in WebAssembly. High-recall vector search with arbitrary metadata filters, in the browser or at the edge.

npm License

What is ACORN?

ACORN (Patel et al., SIGMOD 2024, arXiv:2403.04871) solves filtered HNSW's recall-collapse problem. Standard post-filter HNSW retrieves k candidates and discards the ones that fail your predicate — but at low selectivity (e.g. 1 % of vectors match) you'd need to retrieve thousands of candidates to expect 10 valid hits, and recall drops to near-zero. ACORN fixes this structurally with two changes:

  1. γ-augmented graph constructionγ × M edges per node instead of M. The denser graph stays navigable even when the predicate prunes most nodes.
  2. Predicate-agnostic traversal — expand all neighbors regardless of predicate. A failing node doesn't enter the result set, but its neighbors enter the candidate frontier. The beam never starves.

Net effect: 96 % recall@10 at 1 % selectivity where post-filter HNSW collapses to near-zero.

Install

npm install @ruvector/acorn-wasm

Usage (browser)

import init, { AcornIndex } from "@ruvector/acorn-wasm";

await init();

const dim = 128;
const n = 5_000;
const vectors = new Float32Array(n * dim);
// ... populate `vectors` with embeddings (n × dim, row-major) ...

// gamma=2 → ACORN-γ (best recall at low selectivity)
// gamma=1 → ACORN-1 (smaller index, fine for moderate selectivity)
const idx = AcornIndex.build(vectors, dim, 2);

const query = new Float32Array(dim);
// ... fill query ...

// Predicate is any JS function (id: number) => boolean
const inStock = (id) => products[id].stockCount > 0;
const results = idx.search(query, 10, inStock);
// → [{ id, distance }, ...]

Usage (Node.js / Bun)

import { AcornIndex } from "@ruvector/acorn-wasm/node/ruvector_acorn_wasm.js";
// no `init()` for the node target

const idx = AcornIndex.build(vectors, 128, 2);
const results = idx.search(query, 10, (id) => metadata[id].published);

Usage (bundlers — Vite, Webpack, Rollup)

import { AcornIndex } from "@ruvector/acorn-wasm/bundler/ruvector_acorn_wasm.js";
// the bundler handles the .wasm import transparently

API

class AcornIndex

AcornIndex.build(vectors, dim, gamma)

Build an index from a flat Float32Array of length n * dim.

| Parameter | Type | Description | |---|---|---| | vectors | Float32Array | Row-major matrix of n vectors, each of length dim. | | dim | number | Vector dimensionality. | | gamma | number | Edge multiplier. 1 → ACORN-1 (M=16). 2 → ACORN-γ (M·γ=32, recommended for low selectivity). |

Throws if dim == 0, vectors is empty, vectors.length is not a multiple of dim, or gamma == 0.

idx.search(query, k, predicate)

Find the k nearest neighbors of query whose id satisfies predicate. Returns an array of SearchResult ordered ascending by distance.

predicate is invoked as predicate(id: number) => boolean for each node visited during search (≤ ef nodes, ~150 default — bounded). Use it for any metadata filter: equality, range, geo, ACL, composite — there is no schema coupling.

idx.dim (getter, number)

Vector dimensionality of the index.

idx.memoryBytes (getter, number)

Approximate heap size — graph edges + raw vectors, in bytes.

idx.name (getter, string)

Variant label for diagnostics: "ACORN-1 (γ=1, M=16)" or "ACORN-γ (γ=2, M=32)".

interface SearchResult

{
  id: number;       // caller-supplied vector id
  distance: number; // approximate L2² distance
}

version()

Returns the crate version baked at build time.

Recall and performance

Native Rust benchmark (x86_64, n=5K, D=128, k=10):

| Selectivity | ACORN-γ recall@10 | ACORN-γ QPS | Flat scan recall | Flat scan QPS | |---|---|---|---|---| | 50 % | 34.5 % | 65 K | 100.0 % | 18 K | | 10 % | 79.7 % | 47 K | 100.0 % | 60 K | | 1 % | 96.0 % | 18 K | 100.0 % | 151 K |

The structural win is at low selectivity: ACORN-γ holds high recall as the predicate gets more selective, while post-filter approaches collapse. WASM throughput is typically 30–60 % of native at the same dataset size.

Why use this in the browser

  • Filtered RAG without a server. Query an embedding store with arbitrary metadata filters entirely client-side.
  • Privacy. User vectors never leave the device.
  • Edge runtimes. Cloudflare Workers, Deno Deploy, Vercel Edge — same .wasm, no native binaries.
  • Predicate is just JS. Any (id: number) => boolean function works — your filter logic stays in JS where you already have it.

Sister packages

Source

License

MIT OR Apache-2.0