Skip to main content

roaringrange (Python)

Build static, range-fetchable search datasets from Python, then search millions of records in the browser with no backend. These bindings wrap the core Rust build module, so the files they emit are byte-identical to the Go and Rust builders and are read by the same WASM reader. Two index types: a trigram text index (Builder) and a similarity / vector index (VectorBuilder).

What it produces

Builder.build(out_dir) writes the four files the text reader serves over HTTP Range; VectorBuilder.build(path) writes one .rrvi similarity index:

file format contents
index.rrs RRSI trigram text index (popularity-split postings)
index.rrf RRSF facet sidecar (field → category → doc-ID bitmap, with counts)
records.idx / records.bin RRSR per-doc record bytes (your encoding)
*.rrvi RRVI IVFPQ similarity index (range-fetched coarse clusters + PQ codes)

Upload them to S3/CloudFront and point the WASM reader at the URLs.

Install

Prebuilt abi3 wheels (one wheel for CPython 3.8+) are published to PyPI:

pip install roaringrange

CI builds and tests the extension on CPython 3.12, 3.13, and 3.14.

From source (dev)

cd python
maturin develop --release      # builds + installs into the active venv
# or: maturin build --release   # produces a wheel in target/wheels/

Requires a Rust toolchain and pip install maturin.

Usage

import roaringrange as rr, json

b = rr.Builder(gram_size=3)
for row in rows:                              # rows from a DataFrame, DB, JSONL, …
    b.add(
        rank=row["citations"],                # higher rank = listed first (doc-ID order)
        text=f'{row["title"]} {row["abstract"]}',   # tokenized into trigram keys
        record=json.dumps({"t": row["title"], "y": row["year"]}).encode(),
        facets={"year": [str(row["year"])], "type": [row["type"]]},  # field → categories
    )

stats = b.build("out/")        # writes out/index.rrs, index.rrf, records.idx, records.bin
print(stats)                   # BuildStats(docs=..., ngrams=..., fields=...)

rr.tokenize(text, gram_size=3) returns the n-gram keys a string maps to — useful for understanding why a query does or doesn't match.

VectorBuilder trains an IVFPQ index over your embeddings and writes a single .rrvi file that the WASM reader range-fetches like the text index. Use the same doc_id as the text index so a vector hit maps to the same record (and can hybridize with trigram search). Vectors are L2-normalized for the default "ip" (cosine) metric.

import roaringrange as rr

vb = rr.VectorBuilder(dim=256, nlist=4096, m=32, metric="ip")  # m must divide dim
for doc_id, embedding in enumerate(embeddings):     # embeddings: any float sequences
    vb.add(doc_id, embedding.tolist())              # numpy row → list of floats
# or in one call: vb.add_many([(i, e.tolist()) for i, e in enumerate(embeddings)])

stats = vb.build("out/vectors.rrvi")
print(stats)   # VectorBuildStats(vectors=..., dim=256, nlist=..., m=32, nbits=8)

Parameters: nlist coarse clusters (≈ 4·√N, clamped to the vector count), m PQ subquantizers (must divide dim), nbits (1–8) → 2^nbits codes per subspace, metric "ip"/"cosine" or "l2". Training is deterministic (seed, kmeans_iters). One .rrvi per embedding model — each model is a different vector space. See ../VECTORS.md for the byte layout.

This pure-Rust trainer suits small/medium corpora and tests; at very large scale train with FAISS and export the same RRVI layout (the reader is identical).

Scale: train with FAISS, export to RRVI

For large corpora, train OPQ,IVF,PQ with FAISS and export the trained parts — no retraining in Rust. python/scripts/faiss_to_rrvi.py does this end to end (install the extra: pip install 'roaringrange[train]' for numpy + faiss-cpu):

from faiss_to_rrvi import export_to_rrvi
stats = export_to_rrvi(vectors, doc_ids, "vectors.rrvi", nlist=4096, m=32, metric="ip")

Under the hood it calls the low-level roaringrange.write_rrvi_from_faiss(...), which takes the FAISS arrays (OPQ rotation, coarse centroids, PQ codebooks, per-vector cluster + 8-bit codes) as little-endian byte buffers — so the wheel needs no numpy dependency. The export is verified against the Rust reader (recall@10 ≈ 0.9995 vs FAISS's own search on the same index).

Embedding text (mode 2: model2vec, no backend)

python/scripts/model2vec_embed.py embeds text with a model2vec static model (minishlab/potion-retrieval-32M, 512-d, mean-pooled token vectors — no transformer, fast on CPU) and builds a .rrvi. Install the extra: pip install 'roaringrange[embed]'.

from model2vec_embed import build_rrvi_from_texts
stats, _ = build_rrvi_from_texts(titles, doc_ids, "vectors.rrvi", nlist=256, m=32)

It's "mode 2" because the same model2vec recipe can run in the browser at query time, so similarity search needs no backend at all. The query embedding must use the identical model + pooling as the corpus, or the spaces won't match.

Notes

  • Ranking is baked in. Doc IDs are assigned in descending rank, so the top-K of any query is free at read time (no query-time scoring). Pick a good rank signal (citations, holdings, popularity, …).
  • Records are opaque. record= is raw bytes; the format never dictates your schema. Decode them however you like on the client.
  • In-memory build. This builds the whole index in RAM — ideal for up to many millions of records. For corpora whose index exceeds memory, the core crate's chunked path (build::chunk) is the route; exposing it here is a follow-up.

MIT — see ../LICENSE.

Metadata

Release files for roaringrange 0.42.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for roaringrange 0.42.0
File
roaringrange-0.42.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
roaringrange-0.42.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
roaringrange-0.42.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
roaringrange-0.42.0-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
roaringrange-0.42.0-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.7 MB

Release files / roaringrange-0.42.0-cp38-abi3-win_amd64.whl

Download URL roaringrange-0.42.0-cp38-abi3-win_amd64.whl
Size 483.6 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e1588247c0d42cdf45e793b27cb9a145f8074d7c1580f512999c691cf8319c4d
BLAKE2b-256 checksum
How to use checksums
b01e94e49ed3be0ddcb7e24d235de755e4e2611a4e7a7d90a8112155eff3cf54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / roaringrange-0.42.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL roaringrange-0.42.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 595.0 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
afed378308de90362dffc082f808c56080603c9f1c51da245df4b50f50387f87
BLAKE2b-256 checksum
How to use checksums
d1bd7fc44082a30c475f7d24dc6ed9982aec1bdaea11572ff0610f98d6c443ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / roaringrange-0.42.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL roaringrange-0.42.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 563.6 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8e08b27d4535575d291234346294805ea0a8da30b752fa78732a7c863f05f72e
BLAKE2b-256 checksum
How to use checksums
f4ffa5a5b6c4b3de6a406f4b34824ed8cd58c23c04facf888944aaa1b068ee4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / roaringrange-0.42.0-cp38-abi3-macosx_11_0_arm64.whl

Download URL roaringrange-0.42.0-cp38-abi3-macosx_11_0_arm64.whl
Size 528.1 kB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f46b576d07605ba8b81682b8a15693d6024a3765875c805c7721fec9a329ed1b
BLAKE2b-256 checksum
How to use checksums
36cc244c5686d506246c766cc79baf468f498f961df8bba4b2960ca0c67deee2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / roaringrange-0.42.0-cp38-abi3-macosx_10_12_x86_64.whl

Download URL roaringrange-0.42.0-cp38-abi3-macosx_10_12_x86_64.whl
Size 544.5 kB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7b9053bd02a026b2f249f250f0541822baaad9cda83521325f9d2a36a5b5b7e3
BLAKE2b-256 checksum
How to use checksums
f0f0a2e5763b6ec4213c9c4fc15fd9c8049f7d8b13e9bc6790769d06e334fe53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Security for roaringrange 0.42.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for roaringrange-0.42.0-cp38-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page