Model reference · open weights
bge-multilingual-gemma2 is an open-weight embedding model from BAAI. bge-multilingual-gemma2 (FP32) weighs 18.5 GB; the smallest configuration that runs it is RTX 4090 24 GB.
Summary of the BAAI/bge-multilingual-gemma2 model card, 2026-10-01
What it is
| Released by | BAAI |
|---|---|
| Released | 2024-07-25 |
| Parameters | 9.2B |
| VRAM | 18.5 GB for the weights |
What it runs on
| Card | Runs | Memory |
|---|---|---|
| RTX 3060 12 GB … RTX 4060 Ti 16 GB | does not fit | |
| RTX 3090 24 GB | fits | 23.4 GB |
| RTX 4090 24 GB | fits | 23.4 GB |
| RTX 5090 32 GB | fits | 31.0 GB |
| L40S 48 GB | fits | 44.0 GB |
| A100 80 GB | fits | 78.2 GB |
| H100 80 GB | fits | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | fits | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | fits | 107 GB |
| H200 141 GB | fits | 138 GB |
| B200 180 GB | fits | 176 GB |
From the model card
For more details please refer to our Github: FlagEmbedding.
BGE-Multilingual-Gemma2 is a LLM-based multilingual embedding model. It is trained on a diverse range of languages and tasks based on google/gemma-2-9b. BGE-Multilingual-Gemma2 primarily demonstrates the following advancements:
The training data of BGE-Multilingual-Gemma2 is available at this link.
git clone https://github.com/FlagOpen/FlagEmbedding.git
cd FlagEmbedding
pip install -e .
from FlagEmbedding import FlagLLMModel
queries = ["how much protein should a female eat", "summit define"]
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
]
model = FlagLLMModel('BAAI/bge-multilingual-gemma2',
query_instruction_for_retrieval="Given a web search query, retrieve relevant passages that answer the query.",
use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
embeddings_1 = model.encode_queries(queries)
embeddings_2 = model.encode_corpus(documents)
similarity = embeddings_1 @ embeddings_2.T
print(similarity)
# [[ 0.559 0.01654 ]
# [-0.002575 0.4998 ]]
By default, FlagLLMModel will use all available GPUs when encoding. Please set os.environ["CUDA_VISIBLE_DEVICES"] to select specific GPUs.
You also can set os.environ["CUDA_VISIBLE_DEVICES"]="" to make all GPUs unavailable.
from sentence_transformers import SentenceTransformer
import torch
# Load the model, optionally in float16 precision for faster inference
model = SentenceTransformer("BAAI/bge-multilingual-gemma2", model_kwargs={"torch_dtype": torch.float16})
# Prepare a prompt given an instruction
instruction = 'Given a web search query, retrieve relevant passages that answer the query.'
prompt = f'{instruction}\n'
# Prepare queries and documents
queries = [
'how much protein should a female eat',
'summit define',
]
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
]
# Compute the query and document embeddings
query_embeddings = model.encode(queries, prompt=prompt)
document_embeddings = model.encode(documents)
# Compute the cosine similarity between the query and document embeddings
similarities = model.similarity(query_embeddings, document_embeddings)
print(similarities)
# tensor([[ 0.5591, 0.0164],
# [-0.0026, 0.4993]], dtype=torch.float16)
import torch
import torch.nn.functional as F
from torch import Tensor
from transformers import AutoTokenizer, AutoModel
def last_token_pool(last_hidden_states: Tensor,
attention_mask: Tensor) -> Tensor:
left_padding = (attention_mask[:, -1].sum() == attention_mask.shape[0])
if left_padding:
return last_hidden_states[:, -1]
else:
sequence_lengths = attention_mask.sum(dim=1) - 1
batch_size = last_hidden_states.shape[0]
return last_hidden_states[torch.arange(batch_size, device=last_hidden_states.device), sequence_lengths]
def get_detailed_instruct(task_description: str, query: str) -> str:
return f'{task_description}\n{query}'
task = 'Given a web search query, retrieve relevant passages that answer the query.'
queries = [
get_detailed_instruct(task, 'how much protein should a female eat'),
get_detailed_instruct(task, 'summit define')
]
# No need to add instructions for documents
documents = [
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
"Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
]
input_texts = queries + documents
tokenizer = AutoTokenizer.from_pretrained('BAAI/bge-multilingual-gemma2')
model = AutoModel.from_pretrained('BAAI/bge-multilingual-gemma2')
model.eval()
max_length = 4096
# Tokenize the input texts
batch_dict = tokenizer(input_textsQuoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.
Benchmarks
As published on the model card: the maker's own numbers, not measured by AxForge.
| Task | Dataset | Metric | Score |
|---|---|---|---|
| Retrieval | MTEB NFCorpus | main_score | 38.114 |
| Retrieval | MTEB NFCorpus | ndcg_at_1 | 48.452 |
| Retrieval | MTEB NFCorpus | ndcg_at_3 | 44.451 |
| Retrieval | MTEB NFCorpus | ndcg_at_5 | 41.139 |
| Retrieval | MTEB NFCorpus | ndcg_at_10 | 38.114 |
| Retrieval | MTEB NFCorpus | ndcg_at_100 | 35.361 |
| Retrieval | MTEB NFCorpus | ndcg_at_1000 | 44.011 |
| Retrieval | MTEB NFCorpus | map_at_1 | 5.638 |
| Retrieval | MTEB NFCorpus | map_at_3 | 10.376 |
| Retrieval | MTEB NFCorpus | map_at_5 | 11.821 |
| Retrieval | MTEB NFCorpus | map_at_10 | 14.087 |
| Retrieval | MTEB NFCorpus | map_at_100 | 18.254 |
| Retrieval | MTEB NFCorpus | map_at_1000 | 19.868 |
| Retrieval | MTEB NFCorpus | precision_at_1 | 49.845 |
| Retrieval | MTEB NFCorpus | precision_at_3 | 41.899 |
| Retrieval | MTEB NFCorpus | precision_at_5 | 35.356 |
| Retrieval | MTEB NFCorpus | precision_at_10 | 28.514 |
| Retrieval | MTEB NFCorpus | precision_at_100 | 9.337 |
| Retrieval | MTEB NFCorpus | precision_at_1000 | 2.210 |
| Retrieval | MTEB NFCorpus | recall_at_1 | 5.638 |
| Retrieval | MTEB NFCorpus | recall_at_3 | 11.938 |
| Retrieval | MTEB NFCorpus | recall_at_5 | 14.062 |
| Retrieval | MTEB NFCorpus | recall_at_10 | 18.506 |
| Retrieval | MTEB NFCorpus | recall_at_100 | 35.970 |