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=2unlocks ~6% min-coverage at 500K;B=4is the default sweet spot;B=8+works better for multimodal corpora.docs_packed(optional): pass the same packed-doc listfull_maxsimtakes and theK+Mmargin rescore goes through the bit-identical packed kernel (Fix-A). Without it the rescore uses the i8 flat tiled kernel, which diverges fromfull_maxsimby float-add-order noise; with it,alpha_ef=1cleanly reaches 99.5–100% overlap (true PAC corner).- Per-round telemetry: the returned
statsdict includesround_kernel_ms,round_elim_ms,round_n_survivors, andround_tokensarrays 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).
Release files for colbandit 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| colbandit-0.1.0.tar.gz | 1.2 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 14.0+ ARM64 | Details |
| colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64 | Details |
| colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 14.0+ ARM64 | Details |
| colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.28+ x86-64 | Details |
| colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 14.0+ ARM64 | Details |
| colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.28+ x86-64 | Details |
| colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl | CPython 3.9 | CPython 3.9 | macOS 14.0+ ARM64 | Details |
Total release size: 41.4 MB
Release files / colbandit-0.1.0.tar.gz
| Download URL | colbandit-0.1.0.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f83089626ff0ba40c08ff7488c7c87c5ef0a67b322ca452ca0420da1342266b
|
|
BLAKE2b-256 checksum How to use checksums |
f4bbdad2978e44baf5884fbb4380a9debbb0c1201616c3686207d675562341f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | colbandit-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.8 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e372c12e1c41041da28931d27f83a95a6e9c446455b3653513b7030221f90e72
|
|
BLAKE2b-256 checksum How to use checksums |
19fd13df52236fa3482d8b6d94081f640f9eb1054aa942d20eecf45b698566e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | colbandit-0.1.0-cp312-cp312-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
65585c46122a8a0b0b6f9edd050d049fc6101fe7d94e704cab0133c820af3ba8
|
|
BLAKE2b-256 checksum How to use checksums |
10d51078ed9e5843c8288bea3c0bbdbdd0550ec446844bd1c790cd116e5d7ac0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | colbandit-0.1.0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.8 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e33848b96a333df7240ae86db1e3666a2fc04b0639868407bcd93352a4b4ffd7
|
|
BLAKE2b-256 checksum How to use checksums |
8cd01e45fcedd68b334920ed02e2d0701ef5b96f7239cee227a605bca447ddaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | colbandit-0.1.0-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d8cb237fad78dfc778aa6cd37efb5de367f6512c91990446146c843793cade52
|
|
BLAKE2b-256 checksum How to use checksums |
3b5265395df2db98dbeac678957b20410a6bc8062554b90b6593e8cc88e6fc94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | colbandit-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.8 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9096d10cd0725d26f67741f6299ba7e08fc3d5a701412b73565479ca994141a3
|
|
BLAKE2b-256 checksum How to use checksums |
c1ad33066ba2bb7cd4d4e9b49ae85e4ff100ebff5f482cbf649b02ccff4f88fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | colbandit-0.1.0-cp310-cp310-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a01eed789ce5914b6ba7720d7ba252977d7291c1ac504d6ca19ded62cb68dfd0
|
|
BLAKE2b-256 checksum How to use checksums |
2a1c3770e40bc72beb3f04ea026415e4ecf819235521a2d4466e71e22cb0a039
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
| Download URL | colbandit-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.8 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9e081c160123ea8986753179f5c979326004332e7b050d8be113593624f9f34c
|
|
BLAKE2b-256 checksum How to use checksums |
89e2835415ef377e145ab529f736bd79943ecb6f24d5f87d8a5f9d8304ab051c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl
| Download URL | colbandit-0.1.0-cp39-cp39-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.9 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
54e1c6e4086df17a2911da725dfc3cb4647ae0fe38c9db97269b16f3f18f87ee
|
|
BLAKE2b-256 checksum How to use checksums |
c629462441ef5cf9e96feb8d46a64aa5e0694434e61cc710a66af60439b43c71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|