Skip to Content
Home

quantvec

Data-oblivious, zero-training vector quantization & search for TypeScript. Clean-room TurboQuant  + RaBitQ . Runs in Node, browsers, Bun, and edge runtimes.

Get started → · GitHub  · Architecture


Why quantvec

Quick start

npm install quantvec # or: bun add quantvec / pnpm add quantvec
import { TurboQuantIndex } from 'quantvec'; // No training, no fit step — construct and add. const index = new TurboQuantIndex({ dim: 768, bits: 4 }); index.add(vectors); // Float32Array (flat) | number[][] | Float32Array[] const { indices, scores } = index.search(query, 10); // top-10, best-first

Need stable external ids, payload filtering, and persistence? Reach for the id-keyed index:

import { IdMapIndex } from 'quantvec'; const index = new IdMapIndex({ dim: 768, bits: 4, metric: 'cosine' }); index.addWithIds(['a', 'b', 'c'], vectors); const { ids, scores } = index.search(query, 10, { filter: id => id !== 'b', // optional allowlist predicate }); const bytes = index.toBytes(); // versioned, self-describing binary const restored = IdMapIndex.fromBytes<string>(bytes);

How it works

  1. Normalize each vector (store its norm).
  2. Random rotation (data-independent) so each coordinate follows a known Beta distribution.
  3. Lloyd-Max scalar quantization — the MSE-optimal codebook for that known distribution.
  4. Bit-pack to 2/3/4 bits per coordinate.
  5. RaBitQ length-renormalization scale per vector → an unbiased inner-product estimate at query time.

Read the Architecture page for the full pipeline, or jump to the API Reference.

Last updated on