Skip to main content

Training-free ordinal & sign quantization for compressed vector retrieval

Project description

ordvec (Python)

Python bindings for ordvec — a training-free ordinal & sign vector-quantization library for compressed nearest-neighbour retrieval over high-dimensional embeddings. Pure-Rust core, zero system dependencies; SIMD-accelerated at runtime (AVX-512 / AVX2 / scalar).

import numpy as np
import ordvec

q = ordvec.RankQuant(1024, 2)          # 1024-dim, 2 bits/coord
q.add(np.random.randn(10_000, 1024).astype(np.float32))
# asymmetric: full-precision float queries vs bucketed docs (recommended)
scores, ids = q.search_asymmetric(np.random.randn(8, 1024).astype(np.float32), k=10)

Classes

Class Purpose
Rank Full-precision rank vectors (u16 per coordinate).
RankQuant Bucketed ranks, bits ∈ {1, 2, 4}; symmetric + asymmetric (float-query LUT) scoring.
Bitmap Constant-weight top-bucket bitmap per document; popcount(Q AND D) candidate scoring.
SignBitmap Sign bitmap for sign-cosine candidate generation; separate from the constant-weight bitmap theorem.

The Rust crate's b = 8 RankQuant evidence/refinement width is not exposed through the v0.5 Python RankQuant constructor and cannot be persisted to .ovrq; use bits 1, 2, or 4 from Python.

Two-stage retrieval (subset rerank)

A Bitmap / SignBitmap probe yields a candidate shortlist that RankQuant.search_asymmetric_subset(query, candidates, k) reranks exactly:

cands = bm.top_m_candidates(query, m=256)          # uint32 shortlist
scores, ids = rq.search_asymmetric_subset(query, cands, k=10)

Both returned arrays have length min(k, len(candidates)), not k. When k > len(candidates) the result is silently capped to the candidate count — the subset path never pads with sentinel rows. If you assemble a fixed-width (n_q, k) result buffer, size each row by its candidate count rather than assuming k rows back.

Theory and calibration

Bitmap exposes the constant-weight top-bucket overlap statistic formalized in ordvec-formalization. In that finite Lean model, literal bitmap overlap is the query-preserving quotient statistic, an overlap threshold is Bayes-optimal under explicit monotone-overlap assumptions, and the idealized uniform constant-weight null calibrates that threshold by the hypergeometric upper tail.

This is not a deployment guarantee for every encoder or corpus. Real-corpus recall, monotonicity, and null fit remain empirical diagnostics.

Installation

pip install ordvec

Wheels target CPython 3.10+ (abi3) and require numpy>=2.2. Building from source needs a Rust toolchain (MSRV 1.89) and maturin.

Safety contract

The Python binding releases the GIL while Rust searches, scores, and mutates indexes. Inputs that cross a GIL-released call are copied into Rust-owned buffers first, so ordinary Python in-place NumPy mutation from another thread cannot race the detached Rust scan. Large calls may temporarily require an additional input-sized buffer. The cross-language ownership and lifetime contract is maintained in docs/bindings-safety.md for this release line.

Type stubs

The package ships hand-written type stubs (_ordvec.pyi) and a py.typed marker, so editors and mypy get full signatures for the four index classes, the module-level rank-math primitives, and the MAX_* constants — the abi3 native module is otherwise opaque to static analysis.

Provenance & license

The ordvec Python package's active upstream, implementation history, issues, releases, and governance live in Project-Navi/ordvec.

Courtesy note: ordvec was developed using the early turbovec project context as a rapid-development scaffold, with thanks to that lineage. It is not a source fork of turbovec.

Dual-licensed under either of MIT or Apache-2.0 at your option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ordvec-0.5.0.tar.gz (355.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ordvec-0.5.0-cp310-abi3-win_amd64.whl (435.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

ordvec-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (551.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

ordvec-0.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (515.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

ordvec-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (477.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file ordvec-0.5.0.tar.gz.

File metadata

  • Download URL: ordvec-0.5.0.tar.gz
  • Upload date:
  • Size: 355.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ordvec-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e1e2363936886e3f7666643a7619e8a53a69309752286f6d73f34e1af29c2127
MD5 845318c966fad89e9242b97bb3ad51b5
BLAKE2b-256 e34280e766f16873c19a714970ccd4e6c54d055d6e17a5943afd7f4822ceefe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ordvec-0.5.0.tar.gz:

Publisher: release.yml on Project-Navi/ordvec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ordvec-0.5.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: ordvec-0.5.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 435.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for ordvec-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 216a6b68cd8f75e1c8aa4ca1bb7b6f4141da98ed3f05c0e98886432495bbe93b
MD5 c2ae0fdbd8a1242abb06cea6b6d2f7ae
BLAKE2b-256 20bcce7459aee2cac6dc50461275a9d95264289e1aba3634fdad07c8982f0b4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ordvec-0.5.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on Project-Navi/ordvec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ordvec-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ordvec-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82f7cef16a2c2b13657394df4e89c2b5f02e974f11f303c598c927edf1e02f8e
MD5 8c1b36e6c175ea39f014ee41895ca0f0
BLAKE2b-256 128afb67a28e15798c76e2031ac0bbb0efeefe593583bfc4b30792b974cdbdc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ordvec-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Project-Navi/ordvec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ordvec-0.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ordvec-0.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f922ade5a7230b61bb59440946f43d8b5db9a3f9cb073cf8305d0cb687aaf3ff
MD5 fdf505d24a94ad05de456f69d8c3cc44
BLAKE2b-256 a90a8d11622ffd71cb20d9b3913ec63ad14788a57ab463dfecd195d509b19d0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ordvec-0.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Project-Navi/ordvec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ordvec-0.5.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ordvec-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 564281052ea218d0c570536e2fc94cac0d22e3ca948a2c8cfe64fdb04ee415e7
MD5 38cfd9903b11e7d2af91ac8a972db6c3
BLAKE2b-256 1646dc01cea8656ad557bf16b513d2e067eac808b6dadbd7703660bd307137bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ordvec-0.5.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on Project-Navi/ordvec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page