Skip to main content

Query-time top-K identification for late-interaction (ColBERT-style) retrieval.

Project description

Col-Bandit

Query-time top-K identification for late-interaction (ColBERT-style) retrieval.

Col-Bandit accelerates multi-vector reranking by adaptively computing only the MaxSim cells needed to identify the exhaustive top-K, instead of scoring the full N × T query-token × document matrix. It is a drop-in scoring/reranking layer over precomputed token embeddings — no retraining, no index changes — and runs on x86 (AVX2) and Apple Silicon (NEON) via the vendored numkong kernel.

Paper: Col-Bandit: Query-Time Top-K Estimation for Late-Interaction Retrieval.

Install

pip install colbandit

That's it. Precompiled wheels are shipped for Linux x86_64, macOS arm64, macOS x86_64, and Windows x86_64 (Python 3.9–3.12). The native CB-NK kernel is bundled inside the package — no separate dependency, no PYTHONPATH.

Source builds (when no wheel is available) need a C toolchain and Python ≥ 3.9. macOS users also need libomp (brew install libomp).

git clone https://github.com/roipony/ColBandit colbandit && cd colbandit
./install.sh    # or: pip install .

Quickstart

import numpy as np
from colbandit import ColBandit

# Precomputed multi-vector embeddings: one [L_i, d] array per document.
docs  = [np.random.randn(60, 128).astype("float32") for _ in range(10_000)]
query = np.random.randn(32, 128).astype("float32")          # [T, d]

cb = ColBandit(alpha_ef=0.2, M=5, delta=0.01)               # paper-deployed defaults
cb.index(docs)                                              # one-time packing
ids, scores = cb.search(query, k=5)                         # top-5 document ids + scores

index() and search() accept NumPy arrays or PyTorch tensors. A single padded [N, L, d] array is also accepted by index().

API

ColBandit(alpha_ef=0.2, M=5, delta=0.01, n_threads=1, rng_seed=42, exact_rescore=True) Construct.
.index(doc_embeddings, doc_ids=None) Pack documents (list of [L_i, d]).
.search(query_embedding, k=5) -> (ids, scores) Estimate the top-k.
.save(path) / ColBandit.load(path) Persist / restore the packed index.

Knobs. alpha_ef ∈ (0,1] is the single cost–fidelity knob: smaller prunes more aggressively (faster, lower fidelity); alpha_ef=1 is the conservative corner. M is the rescore margin (keep K+M survivors, rescore exactly). n_threads parallelises across queries (throughput, not single-query latency).

Low-level kernel (advanced)

The high-level ColBandit wrapper is built on colbandit._kernel, also re-exported on the top-level colbandit namespace as colbandit_flat, topm_flat, full_maxsim, maxsim_pack, extract_flat_from_packed, and total_tokens. Three knobs on colbandit_flat are worth knowing:

  • round_size (default 4): tokens revealed per bandit round, 1..16. Smaller means more aggressive elimination — lower coverage floor, but a lower max-coverage ceiling too. B=2 unlocks ~6% min-coverage at 500K; B=4 is the default sweet spot; B=8+ works better for multimodal corpora.
  • docs_packed (optional): pass the same packed-doc list full_maxsim takes and the K+M margin rescore goes through the bit-identical packed kernel (Fix-A). Without it the rescore uses the i8 flat tiled kernel, which diverges from full_maxsim by float-add-order noise; with it, alpha_ef=1 cleanly reaches 99.5–100% overlap (true PAC corner).
  • Per-round telemetry: the returned stats dict includes round_kernel_ms, round_elim_ms, round_n_survivors, and round_tokens arrays for diagnostics.

Sanity check

After ./install.sh:

# 1) tests (top-K correctness + save/load roundtrip)
python tests/test_smoke.py

# 2) benchmark vs brute-force Full-MaxSim on a planted-winner corpus
python examples/bench.py                          # N=5000, K=5 — quick
python examples/bench.py --N 50000 --threads 4    # larger / multi-thread

Both should report Overlap@5 = 1.00 and a meaningful speedup over brute force.

Repo layout

colbandit/                Python package (ColBandit + _kernel C extension)
native/numkong/           vendored CB-NK kernel sources (C, ISA-probed)
examples/quickstart.py    minimal example
tests/test_smoke.py       smoke tests
setup.py + pyproject.toml standalone build (no separate numkong dep)
install.sh                one-shot source installer

Acknowledgements

Col-Bandit bundles a vendored snapshot of NumKong by Ash Vardanian (Apache-2.0). The progressive-elimination kernel in native/numkong/python/colbandit.c is built on top of NumKong's SIMD MaxSim primitives. See NOTICE for the full attribution.

License

Apache-2.0 (matches the bundled CB-NK kernel).

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

colbandit-0.1.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

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

colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file colbandit-0.1.0.tar.gz.

File metadata

  • Download URL: colbandit-0.1.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for colbandit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9f83089626ff0ba40c08ff7488c7c87c5ef0a67b322ca452ca0420da1342266b
MD5 b68c4fee3bd3c4aa82ca2ae67c679322
BLAKE2b-256 f4bbdad2978e44baf5884fbb4380a9debbb0c1201616c3686207d675562341f5

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e372c12e1c41041da28931d27f83a95a6e9c446455b3653513b7030221f90e72
MD5 e03774b83930418c6cbdff0d540ca17e
BLAKE2b-256 19fd13df52236fa3482d8b6d94081f640f9eb1054aa942d20eecf45b698566e6

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 65585c46122a8a0b0b6f9edd050d049fc6101fe7d94e704cab0133c820af3ba8
MD5 bcf74dd627b587cccbce29e93d45bf43
BLAKE2b-256 10d51078ed9e5843c8288bea3c0bbdbdd0550ec446844bd1c790cd116e5d7ac0

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e33848b96a333df7240ae86db1e3666a2fc04b0639868407bcd93352a4b4ffd7
MD5 6f7d848b99fc3302c9f261061af4afe9
BLAKE2b-256 8cd01e45fcedd68b334920ed02e2d0701ef5b96f7239cee227a605bca447ddaa

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d8cb237fad78dfc778aa6cd37efb5de367f6512c91990446146c843793cade52
MD5 0a7795e663457fef3f1086fdfa5f6885
BLAKE2b-256 3b5265395df2db98dbeac678957b20410a6bc8062554b90b6593e8cc88e6fc94

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9096d10cd0725d26f67741f6299ba7e08fc3d5a701412b73565479ca994141a3
MD5 2b64c4dd6f27d5eabcbcca7cd054ce47
BLAKE2b-256 c1ad33066ba2bb7cd4d4e9b49ae85e4ff100ebff5f482cbf649b02ccff4f88fe

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a01eed789ce5914b6ba7720d7ba252977d7291c1ac504d6ca19ded62cb68dfd0
MD5 cbc2f77e8ceef5f045eb72ef2fbeafdb
BLAKE2b-256 2a1c3770e40bc72beb3f04ea026415e4ecf819235521a2d4466e71e22cb0a039

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9e081c160123ea8986753179f5c979326004332e7b050d8be113593624f9f34c
MD5 99feb8a9a17ff4d5deb1e0b8470a0af9
BLAKE2b-256 89e2835415ef377e145ab529f736bd79943ecb6f24d5f87d8a5f9d8304ab051c

See more details on using hashes here.

File details

Details for the file colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 54e1c6e4086df17a2911da725dfc3cb4647ae0fe38c9db97269b16f3f18f87ee
MD5 7fdb30aa4d1ec4f412a89ed6bff5fd5b
BLAKE2b-256 c629462441ef5cf9e96feb8d46a64aa5e0694434e61cc710a66af60439b43c71

See more details on using hashes here.

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