Skip to main content

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': [...]}

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.md for the accuracy trade-off).

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

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: physical cores)
BGE_M3_LITE_FUSED_URL, BGE_M3_LITE_INT8_URL mirror for the fused / int8 release assets

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.3.0: fp32 with exact parity with FlagEmbedding (fused graph by default), opt-in int8 backbone (SmoothQuant, dense cosine 0.998), retrieval helpers, token-budget batching, Windows. Plan: docs/roadmap.md.

Download files

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

Source Distribution

bge_m3_lite-0.3.0.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

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

bge_m3_lite-0.3.0-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file bge_m3_lite-0.3.0.tar.gz.

File metadata

  • Download URL: bge_m3_lite-0.3.0.tar.gz
  • Upload date:
  • Size: 51.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for bge_m3_lite-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9d821139a81809e53a99138fb79323bc108c4ae60740b3cdc13853aa45e8ce17
MD5 e4046884c5904643bf3ea03685687a67
BLAKE2b-256 548bea1851fbe26e44f14775f05b44c6e8232b470e4c690b786883c32b1d9ecf

See more details on using hashes here.

File details

Details for the file bge_m3_lite-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: bge_m3_lite-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for bge_m3_lite-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c98c61801aeb35dfa202419c2575d3329a29decc639a6292c9abdeb0208d18a7
MD5 9274e1666efdbb163bf993e3b99a9658
BLAKE2b-256 4ac80653479b1fc1de7e4b31a777810ba49109e0274678414a79431d6e65d2e1

See more details on using hashes here.

Release history Release notifications | RSS feed

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

0.0.2

2 files

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