Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

laterank

Pre-release. It works end to end, but the API and on-disk format may change before 0.1.0.

laterank is a small Python library for searching your own documents locally with late-interaction models (BGE-M3 or ColBERT-style). It encodes your documents once into a plain folder of NumPy arrays and JSON, finds about a hundred promising candidates with a cheap first stage (BM25, dense, hybrid, SMVE or MUVERA), then re-orders them with exact MaxSim — so you get close to exhaustive late-interaction quality at a fraction of the cost. Pipelines are short strings like hybrid > maxsim@100, you can measure any of them on your own data, and the defaults are the settings that won in our measurements on BEIR. It grows out of the research in smve-lab; SMVE is TopK's method and is credited as such.

Install

You need Python 3.12 or newer. Pick the extra for the model you want (colbert or bge-m3):

pip install "laterank[colbert]"

Either extra brings in torch, which is a large download.

Quick start

from laterank import ColBERTEncoder, Index

docs = [
    {"id": "a", "text": "Statins lower cholesterol but can cause muscle pain."},
    {"id": "b", "text": "BM25 is a classic ranking function for search."},
    {"id": "c", "text": "Tea is made from the leaves of a plant."},
]
encoder = ColBERTEncoder("mixedbread-ai/mxbai-edge-colbert-v0-32m")
index = Index.build("./my_index", docs, encoder, bm25=True, pipeline="bm25 > maxsim@100")

for hit in index.search(encoder.encode_query("do statins hurt muscles?"), k=2):
    print(hit.rank, hit.id, round(hit.score, 3), hit.text)

To use the index in a later session, reopen it:

from laterank import Index, load_encoder

index = Index.open("./my_index")
encoder = load_encoder(index.manifest.encoder)  # the exact model commit the index was built with

Each document needs a unique string id and a text, and can have a title and a metadata dict; other keys are refused. The command line's --docs file uses BEIR's _id instead of id.

Long documents are cut off. BGE-M3 and mxbai keep only the first 512 tokens (max_length and document_length), so split long documents into smaller ones before you build the index.

Choosing a pipeline

index.tune tries every pipeline the index can run (exact search, each first stage alone, each first stage followed by maxsim@20 ... maxsim@1000) and picks the best one that fits a latency budget. Give it a few judged queries (recommended): it keeps the highest nDCG@10.

from laterank import Budget

queries = {"q1": encoder.encode_query("do statins hurt muscles?")}
qrels = {"q1": {"a": 1}}
report = index.tune(Budget(latency_ms=20), queries=queries, qrels=qrels)
print(report.table())
if report.best:  # None means no pipeline fits the budget
    index.set_default(report.best)

queries maps a query id to encoder.encode_query(text), and qrels maps a query id to {doc_id: relevance}, the same as index.evaluate.

Without labels, leave both out. Tune then cuts short spans out of your documents and picks the pipeline that best agrees with exact MaxSim. That measures "agrees with MaxSim", not "finds relevant documents": it can't pick a pipeline that beats MaxSim, and it can miss bm25 > maxsim@d, which sometimes does (SciFact: 0.7086 vs 0.6991 for exact search). Up to 0.052 nDCG@10 was lost in our tests (at sub-millisecond budgets; 0.042 above 1 ms); see docs/dev/tune_validation.md.

Command line

laterank build ./idx --dataset scifact --encoder colbert \
    --hf-id mixedbread-ai/mxbai-edge-colbert-v0-32m
laterank search ./idx "statin side effects" -k 5
laterank evaluate ./idx --dataset scifact --pipeline "bm25 > maxsim@100" --pipeline exhaustive
laterank tune ./idx --budget-ms 20 --dataset scifact --apply

Quote your pipelines. Without quotes, the shell reads > as "write the output to a file".

--dataset takes a folder holding corpus.jsonl, or a BEIR name, which is downloaded the first time. To index your own documents, use --docs FILE instead: a JSONL file with _id, text and an optional title on each line. --encoder is required, and search, evaluate and tune read the model from the index. Every search loads the model again (about 7 s with mxbai on a Mac), so for many queries use the Python API. Without --dataset, tune measures agreement with MaxSim (see above).

Working on laterank

Start with START_HERE.md: the daily workflow, the spec rules, and every command.

License

Apache-2.0 — see LICENSE.

Metadata

Release files for laterank 0.1.0b1

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

Source distribution (sdist)

Source distribution for laterank 0.1.0b1
File Size Uploaded Provenance Actions
laterank-0.1.0b1.tar.gz 63.4 kB Without provenance Details for laterank-0.1.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for laterank 0.1.0b1
File Interpreter ABI Platform Actions
laterank-0.1.0b1-py3-none-any.whl Python 3 none any Details for laterank-0.1.0b1-py3-none-any.whl

Total release size: 147.5 kB

Release files / laterank-0.1.0b1.tar.gz

Download URL laterank-0.1.0b1.tar.gz
Size 63.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f729b382a6125389efc7836969ea6b67edccd21e54034f3670368be038471d26
BLAKE2b-256 checksum
How to use checksums
e73cbe31687b71d1c12c0b3a7f8b06b91474073396cd06244559b1273e6ab469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / laterank-0.1.0b1-py3-none-any.whl

Download URL laterank-0.1.0b1-py3-none-any.whl
Size 84.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
409be582c70b00f0b1a92f7413074214e1337e44bfe356150453f4c1cedfe075
BLAKE2b-256 checksum
How to use checksums
88894cd14a472f887c41c9f2187ccc91ade33905874238309e19828f5fe5cf35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for laterank 0.1.0b1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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