Skip to content

new: BAAI/BGE-M3 support with testing script#602

Open
lucifertrj wants to merge 4 commits into
qdrant:mainfrom
lucifertrj:main
Open

new: BAAI/BGE-M3 support with testing script#602
lucifertrj wants to merge 4 commits into
qdrant:mainfrom
lucifertrj:main

Conversation

@lucifertrj

Copy link
Copy Markdown

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New models submission:

  • Have you added an explanation of why it's important to include this model?
  • Have you added tests for the new model? Were canonical values for tests computed via the original model?
  • Have you added the code snippet for how canonical values were computed?
  • Have you successfully ran tests with your changes locally?

New Model: BAAI/bge-m3

MIT-Licensed:

Model Name Dimension Sequence Length Introduction
BAAI/bge-m3 1024 8192 multilingual; unified fine-tuning (dense, sparse, and colbert) from bge-m3-unsupervised

🔗 Colab Notebook: Open In Colab

Code Snippet for Canonical Values:

docs = ["hello world", "flag embedding"]
embeddings = list(embedding_model.embed(docs))
embeddings = np.stack(embeddings, axis=0)

canonical = np.round(embeddings[0, :5], 4)
print(f"Canonical vector values: {canonical}")

Output:

Canonical vector values: [-0.0404  0.037  -0.029   0.0161 -0.0357]

Added these values in: tests/test_text_onnx_embeddings.py

@coderabbitai

coderabbitai Bot commented Feb 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c49d205a-de9a-471c-83c1-cf6dfd9e6731

📥 Commits

Reviewing files that changed from the base of the PR and between 7fefc94 and 46c40b9.

📒 Files selected for processing (2)
  • fastembed/text/onnx_embedding.py
  • tests/test_text_onnx_embeddings.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_text_onnx_embeddings.py

📝 Walkthrough

Walkthrough

This pull request adds BAAI/bge-m3 to the supported ONNX model registry with its embedding dimensions, multilingual description, license, size, source, model path, and additional data file. The test suite adds the model’s canonical embedding vector for embedding assertions.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding BAAI/bge-m3 support and related test updates.
Description check ✅ Passed The description is clearly related to adding BAAI/bge-m3 support, tests, and canonical values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lucifertrj

lucifertrj commented Feb 5, 2026

Copy link
Copy Markdown
Author

@joein Supported Models docs page needs to be updated

Screenshot 2026-02-05 at 21 05 41

@mohamad-tohidi

Copy link
Copy Markdown

when will this merge?

@michelkluger

Copy link
Copy Markdown

I feel like the library is falling a bit behind in supporting models sadly

@mohamad-tohidi

Copy link
Copy Markdown

i agree

@JiwaniZakir JiwaniZakir left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DenseModelDescription in onnx_embedding.py advertises "8192 input tokens truncation" in the description, but there's no corresponding additional_kwargs (e.g., {"max_length": 8192}) or similar field to actually configure the tokenizer's max sequence length. Without this, the tokenizer will fall back to its default, likely 512 tokens, silently discarding the model's long-context capability and making the description misleading. It's worth checking how other long-context models in this registry handle that setting.

The test entry in test_text_onnx_embeddings.py only checks 5 embedding dimensions, consistent with the rest of the suite, but there's no assertion that the output shape matches the declared dim=1024. Given the model is 2.27 GB and has an unusual external data file (model.onnx_data), a shape check would help catch loading issues early — for instance, if the wrong ONNX graph is loaded or the external data file is missing at inference time.

@yerffejytnac

Copy link
Copy Markdown

Any news?

@X-Cotang

X-Cotang commented Jun 3, 2026

Copy link
Copy Markdown

Any update?

@ejohb

ejohb commented Jun 21, 2026

Copy link
Copy Markdown

This seems like a really important model to support natively, given it encodes all 3 vector types in a single pass.

@Dylancouzon

Dylancouzon commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Thanks to everyone who contributed here, and apologies for the delay. This one slipped through the cracks.

What I changed

  1. Merged main
  2. Reworded the description to match the sibling entries.
  3. Removed onnx/sentencepiece.bpe.model from additional_files. fastembed reads the root tokenizer.json, so only onnx/model.onnx_data is needed.
  4. Recomputed the canonical values from the original PyTorch model, since the previous ones were generated with fastembed
from transformers import AutoTokenizer, AutoModel
import torch, torch.nn.functional as F

tok = AutoTokenizer.from_pretrained("BAAI/bge-m3")
model = AutoModel.from_pretrained("BAAI/bge-m3").eval()

inp = tok(["hello world", "flag embedding"], padding=True, truncation=True,
          max_length=8192, return_tensors="pt")
with torch.no_grad():
    emb = F.normalize(model(**inp).last_hidden_state[:, 0], p=2, dim=1)
print(emb[0, :5])
# tensor([-0.0403941, 0.03703506, -0.02897445, 0.01611726, -0.03569157])

Verification

ruff, mypy, pyright, and the test suite all pass. fastembed matches the PyTorch reference to 1.2e-7 on both Apple Silicon and linux/amd64, and the two platforms agree to 3.9e-8.

Two things for you @joein:

Which class should own this: OnnxTextEmbedding or BuiltinSentenceEmbedding?

At 2.27 GB, the model is skipped by local runs and lightweight CI. The only way to run it in CI is via a manual workflow_dispatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants