bge-m3-lite
CPU inference for BAAI/bge-m3 with
onnxruntime as the only dependency. All three BGE-M3 outputs are supported
and match the official PyTorch implementation (FlagEmbedding) to fp32 precision:
| output | shape | notes |
|---|---|---|
dense_vecs |
(n, 1024) |
CLS pooling, L2-normalised |
lexical_weights |
list[dict[str, float]] |
token-id → weight, max-pooled, specials removed |
colbert_vecs |
list[(len-1, 1024)] |
per-token vectors without <s>, L2-normalised |
Everything except the transformer forward pass is implemented in this package
from scratch: the XLM-RoBERTa tokenizer (SentencePiece unigram model, the
nmt_nfkc precompiled charsmap, Unicode grapheme segmentation), the torch-free
loader for the sparse / ColBERT heads, the model downloader and the pooling.
Platforms: Apple Silicon, Linux ARM64, Linux x86_64, Windows x86_64 (Python 3.11+).
Install
uv add bge-m3-lite # or: pip install bge-m3-lite
Use
from bge_m3_lite import BGEM3Embedder
embedder = BGEM3Embedder() # first call downloads ~2.3 GB into ~/.cache/bge-m3-lite
out = embedder.encode(
["What is BGE M3?", "BGE M3 是一個多語言嵌入模型。"],
return_dense=True,
return_sparse=True,
return_colbert_vecs=True,
)
out["dense_vecs"].shape # (2, 1024)
out["lexical_weights"][0] # {'4865': 0.08, '83': 0.08, ...}
out["colbert_vecs"][0].shape # (7, 1024)
embedder.convert_id_to_token(out["lexical_weights"][0])
embedder.compute_lexical_matching_score(lw_query, lw_passage)
embedder.colbert_score(q_vecs, p_vecs)
# retrieval helpers: queries default to 512 tokens, passages to max_length (8192)
q = embedder.encode_queries(["What is BGE M3?"])
p = embedder.encode_corpus(["BGE M3 is a multilingual embedding model ..."])
embedder.compute_score([("What is BGE M3?", "BGE M3 is ...")])
# {'colbert': [...], 'sparse': [...], 'dense': [...], 'sparse+dense': [...], 'colbert+sparse+dense': [...]}
from bge_m3_lite import AsyncEmbedder # asyncio / FastAPI: never blocks the event loop
async with AsyncEmbedder(
precision="int8"
) as emb: # bounded in-flight calls, optional micro-batching
out = await emb.encode_queries(
"What is BGE M3?"
) # same signatures and outputs as above
Passing a single string returns unwrapped values, like FlagEmbedding.
Batches are bounded by batch_size texts and max_batch_tokens padded
tokens (default 16384), so mixing short and 8192-token inputs stays within
memory.
BGEM3Embedder(precision="int8") loads a 4× smaller quantised backbone
(see docs/quantization/ for the accuracy trade-off).
BGEM3Embedder(low_memory=True) starts in 0.1–0.6 s with ~140 MiB of private
memory (weights stay in the mapped file, shared between processes) at twice
the latency of a single short query: for serverless and one-shot use
(docs/resources.md). Serving: docs/serving/recipe.md (FastAPI recipe, workers ×
memory, measured throughput per concurrency).
CLI
bge-m3-lite download # pre-fetch the model files (2.3 GB + 288 MB fused)
bge-m3-lite info # cache state
echo "hello" | bge-m3-lite encode --sparse --colbert --tokens
bge-m3-lite encode --low-memory --int8 "one-shot" # fast start, small footprint
Environment variables
| variable | effect |
|---|---|
BGE_M3_LITE_CACHE |
cache directory (default ~/.cache/bge-m3-lite/BAAI--bge-m3) |
HF_ENDPOINT |
Hugging Face mirror, e.g. https://hf-mirror.com |
BGE_M3_LITE_OFFLINE=1 |
never download, fail if files are missing |
BGE_M3_LITE_THREADS |
onnxruntime intra-op threads (default: performance cores on Apple Silicon, physical cores elsewhere) |
BGE_M3_LITE_SPIN=1 |
let onnxruntime's threads spin between runs (default off: no idle CPU, see docs/resources.md) |
BGE_M3_LITE_FUSED_URL, BGE_M3_LITE_INT8_URL |
base URL (mirror) for the fused / int8 release asset pairs |
Model files are pinned to a specific Hugging Face revision and verified by SHA-256 after download.
Development
See AGENTS.md and docs/ (architecture, tokenizer, verification, development).
Status
v0.6.2: fp32 with exact parity with FlagEmbedding (fused graph; attention in
query chunks and the layer tail in 256-row windows, so an 8192-token text
needs 1.8 GB and any batch 0.07 MiB per padded token), opt-in int8 backbone
(row-wise + SmoothQuant, dense cosine 0.999 on every platform, 0.3 s
start-up), retrieval helpers, token-budget batching, low_memory mode, no
idle CPU, and an asyncio AsyncEmbedder for FastAPI with a length-aware
micro-batcher (its scheduling audited on Python 3.11 and 3.12+). Shipped versions and closed decisions with their numbers:
docs/roadmap/.
Metadata
Release files for bge-m3-lite 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bge_m3_lite-0.6.2.tar.gz | 120.8 kB | Without provenance | Details for bge_m3_lite-0.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bge_m3_lite-0.6.2-py3-none-any.whl | Python 3 | none | any | Details for bge_m3_lite-0.6.2-py3-none-any.whl |
Total release size: 244.5 kB
Release files / bge_m3_lite-0.6.2.tar.gz
| Download URL | bge_m3_lite-0.6.2.tar.gz |
|---|---|
| Size | 120.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bb4c800279c827e5e9971554a486a904b3d209a64e96ab181536e4876d2414c
|
|
BLAKE2b-256 checksum How to use checksums |
dbd177324f537118b9b462f443de3c21613ab56b2da5f2ac00457c170be67ec1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / bge_m3_lite-0.6.2-py3-none-any.whl
| Download URL | bge_m3_lite-0.6.2-py3-none-any.whl |
|---|---|
| Size | 123.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d77f7ff95e21ed94e968cfb2007f239f6e81c2f718674d46dd68056fa958904d
|
|
BLAKE2b-256 checksum How to use checksums |
fe8c129575b6207df0bc3a7463bdf594245b55592d1af94695b24c5bf082bbbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for bge-m3-lite 0.6.2
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.