Model reference · open weights

bge-m3-onnx

Available as managed deployment Embeddings aapot · community Embeddings 1 variants 527 dl/mo

bge-m3-onnx is an open-weight embedding model from aapot. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.

Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.

What it is

Released byaapot
TypeEmbedding models
TaskEmbeddings
Context8194 tokens
Runs withtransformers
Released2024-02-16
Popularity527 downloads / month
LicenceOpen weights

About

What bge-m3-onnx is

BGE-M3 converted to ONNX weights with HF Optimum, to be compatible, for example, with ONNX Runtime.

This ONNX model outputs dense, sparse and ColBERT embedding representations all at once. The output is a list of numpy arrays in previously mentioned order of representations.

Note: dense and ColBERT embeddings are normalized like the default behavior in the original FlagEmbedding library, if you want unnormalized outputs you can modify the code in bgem3_model.py and re-run the ONNX export with export_onnx.py script.

This ONNX model also has "O2" level graph optimizations applied, you can read more about optimization levels here. If you want ONNX model with different optimization or without optimizations, you can re-run the ONNX export script export_onnx.py with appropriate optimization argument.

Read the full model card

Usage with ONNX Runtime (Python)

If you haven't already, you can install the ONNX Runtime Python library with pip:

pip install onnxruntime==1.17.0

For tokenization, you can for example use HF Transformers by installing it with pip:

pip install transformers==4.37.2

Clone this repository with Git LFS to get the ONNX model files.

You can then use the model to compute embeddings, as follows:

import onnxruntime as ort
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-m3")
ort_session = ort.InferenceSession("model.onnx")

inputs = tokenizer("BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.", padding="longest", return_tensors="np")
inputs_onnx = {k: ort.OrtValue.ortvalue_from_numpy(v) for k, v in inputs.items()}

outputs = ort_session.run(None, inputs_onnx)

Note: you can use following sparse token weight processor from FlagEmbedding to get same the output for the sparse representation from the ONNX model:

from collections import defaultdict

def process_token_weights(token_weights: np.ndarray, input_ids: list):
    # conver to dict
    result = defaultdict(int)
    unused_tokens = set(
        [
            tokenizer.cls_token_id,
            tokenizer.eos_token_id,
            tokenizer.pad_token_id,
            tokenizer.unk_token_id,
        ]
    )
    for w, idx in zip(token_weights, input_ids):
        if idx not in unused_tokens and w > 0:
            idx = str(idx)
            # w = int(w)
            if w > result[idx]:
                result[idx] = w
    return result

token_weights = outputs[1].squeeze(-1)
lexical_weights = list(
    map(process_token_weights, token_weights, inputs["input_ids"].tolist())
)

Export ONNX weights

You can export ONNX weights with the provided custom BGE-M3 PyTorch model bgem3_model.py file and with the provided export_onnx.py ONNX weight export script which leverages HF Optimum. If needed, you can modify the bgem3_model.py model configuration to for example remove embedding normalization or to not output all three embedding representations. If you modify the number of output representations, you need to also modify the ONNX output config BGEM3OnnxConfig in export_onnx.py.

First, install needed Python requirements as follows:

pip install -r requirements.txt

Then you can export ONNX weights as follows:

python export_onnx.py --output . --opset 17 --device cpu --optimize O2

You can read more about the optional optimization levels here

From the published model card. Full card on the HuggingFace links in the sidebar.

Using it via the API

Call it like any OpenAI endpoint

Once AxForge deploys bge-m3-onnx for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (bge-m3-onnx below is illustrative; you get the exact model name on deployment.)

$ curl -sS https://api.axforge.ai/v1/embeddings \
  -H "Authorization: Bearer $AXFORGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"bge-m3-onnx","input":"text to embed"}'

Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.

© 2026 AxForge · EU-hosted AI infrastructure Pricing Docs Trust Privacy Terms