Download docs/methodology.md from quocbao747/embedding-model-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/quocbao747/embedding-model-benchmark/resolve/main/docs/methodology.md
- Command line
-
hf download hf://quocbao747/embedding-model-benchmark/docs/methodology.md
-
curl -L -o methodology.md https://huggingface.co/quocbao747/embedding-model-benchmark/resolve/main/docs/methodology.md
How the models are benchmarked
1. Pipeline
For every model × dataset pair:
- Load the dataset with
mteb(corpus, queries, relevance labels). - Encode all documents and all queries with the model, in its own input format (§2), max length = min(model default, 512 tokens), L2-normalised.
- Search: exact cosine top-100 over the whole corpus (no ANN, no reranker). As in mteb, a hit whose id equals the query id is dropped.
- Score with
pytrec_eval: nDCG@10 (primary), P@1 (first result correct), MRR@10, Recall@10, Recall@100. - Save metrics (JSONL), the top-10 ids per query, and token statistics (tokens per Vietnamese word, share of documents cut at the window).
Jobs (model × dataset, or document shards of 5,000 docs for 8B models) are pulled from a shared queue by several workers; shard embeddings are merged before search, so results are identical to a single pass.
2. Input formats (per model family)
| Family | Query | Document | Pooling |
|---|---|---|---|
| Qwen3-Embedding, Octen, Skill-Venus | Instruct: {task instruction}\nQuery:{query} (task-specific English instruction, also for Vietnamese) |
raw text (Octen: its configured " " prefix) |
last token, left padding |
| EmbeddingGemma (300m, 2), EmbeddingNandi | task: {search result / question answering / fact checking} | query: {query} |
title: {title or "none"} | text: {text} |
mean (model config) |
| BGE-M3 | raw text | raw text | CLS (dense); ReLU token weights (sparse); per-token vectors (ColBERT) |
| bge-base-en-v1.5 | Represent this sentence for searching relevant passages: + query |
raw text | CLS |
| OpenEmbed | Find a passage that answers the given query. + query (assumed: the card lists no text-search instruction) |
raw text | last token |
| others (paraphrase-multilingual, granite, Mistral-Embed) | raw text | raw text | model config |
| OpenAI text-embedding-3-small (API) | raw text, first 512 tokens (cl100k_base) | raw text, first 512 tokens | API (1,536-d; Matryoshka rows = first 1024/512/256 dims re-normalised) |
Models are pinned to the Hugging Face commit downloaded on 2026-12-03. API models: OpenAI models through the Batch API, and Gemini (embedding-2, embedding-001) / Voyage / Perplexity through OpenRouter. Added later through OpenRouter: Cohere embed-multilingual-v3.0, embed-5-fast and embed-5-pro (input_type search_query / search_document; the provider serving v3.0 rejects inputs over 2,048 characters, so 88 of the 512-token documents were cut further: 83 in GreenNode Tables, 2 in WebFAQ, 2 in FiQA, 1 in Zalo Legal; no queries) and Perplexity pplx-embed-v1-4b / pplx-embed-v2-context-0.6b (the context model embeds each document on its own, without multi-chunk context). Amazon titan-embed-text-v2 through OpenRouter: plain text. All API inputs are cut to the first 512 tokens with the cl100k_base tokenizer, because the providers' own tokenizers aren't public. Precision: bf16, except the Zalo Legal, translated and English scores of Qwen3-Embedding-4B and BGE-M3 (fp16) and EmbeddingGemma 2 (fp32). A check on Qwen3-Embedding-4B (7 datasets) found fp16, bf16 and fp32 encoding within 0.5 nDCG@10 of each other (mean gap to fp32: 0.08 for fp16, 0.18 for bf16).
3. Hybrid retrieval (BGE-M3)
Dense and sparse each retrieve a top-100. Their union is re-scored with s = w_dense·dense + w_sparse·sparse + w_colbert·colbert; "all three" uses (1, 0.3, 1), "dense+sparse" uses (1, 0.3, 0). The heads are re-implemented from FlagEmbedding and checked against the reference values in the BGE-M3 README (dense 0.626, lexical 0.1955, ColBERT 0.7796).
4. Extra experiments
- Long input window: selected long-context models re-encoded at 2,048 tokens on Zalo Legal, Table-Markdown and TVPL, where 9–36% of documents exceed 512 tokens.
- Matryoshka truncation: for MRL models, the first d dimensions are kept and re-normalised (Qwen3: 1024/512/256; EmbeddingGemma / Nandi: 512/256/128).
- bf16 vs fp16: Qwen3-Embedding-0.6B in both (Zalo 67.08 vs 67.10).
- NVFP4 (Nemotron-3.5): the NVFP4 checkpoints use the
compressed-tensorsnvfp4-pack-quantizedformat: 4-bit (E2M1) weights with FP8 scales per 16 values and a global scale, and 4-bit inputs to every linear layer with dynamic per-16 scales and a static global scale (W4A4). They are run as a faithful emulation: the weights are unpacked with the library's own decompressor, each layer input is quantised and de-quantised with the library's ownforward_quantize, and the product runs in bf16 with fp32 accumulation. This reproduces the checkpoint's rounding; only the final accumulation order can differ from FP4 hardware. Speed of the emulation is not representative of native FP4. - harrier, F2LLM-v2, jina v3/v4/v5, AITeamVN, Vintern, dangvantuan, multilingual-e5: same datasets, 512-token window and bf16 as above, each model's own input format from its card or
config_sentence_transformers.json. harrier and F2LLM-v2 get the same per-dataset instructions as Qwen3 (Instruct: <task> Query:). jina models use their retrieval adapters and prompts (retrieval.query/retrieval.passagefor v3,task="retrieval"withquery/passageordocumentfor v4/v5; v4 single-vector, text only). multilingual-e5 usesquery:/passage:. dangvantuan/vietnamese-embedding is PhoBERT: text is word-segmented withpyvias its card shows, and its window is 256 tokens (258 positions). Vintern-Embedding-1B is multi-vector (128-dim per token) and scored with exact MaxSim, using the card'sprocess_queries/process_docsformat. - Library versions for models with their own code: models that ship custom code run on the transformers version they were written for: jina v3/v5 and dangvantuan/vietnamese-document-embedding on 4.57.6; jina-v4 on 4.52.4 with peft 0.15.2 (the card's minimum; under 4.57 its embeddings were degenerate, every similarity ≈ 0.85, so 4.57 results were discarded); Vintern on 4.48.2 (pinned in its card; its optional
flash_attnand video-onlydecordimports are bypassed, the text path is unchanged). jina-v4's own input code treats any text starting withhttpas an image URL (and an existing file path as an image); corpus documents can start with a URL, so every input goes through its text processor (process_texts), which gives bit-identical embeddings for ordinary text. Every other model uses transformers 5.25.1. Each model was smoke-tested on two small datasets before its full run. - Nemotron-3.5 input format: the card's Transformers path (chat template
query:/passage:system prefix, no BOS/EOS, mean pooling, bidirectional). The template rendering was checked token-for-token againstapply_chat_template, and the card's example scores were reproduced before the full run. - Mistral-Multimodal-Embed-1B input check: re-encoding SciFact-VN with the card's own text path (
get_text_features, 512 tokens) gives nDCG@10 48.97 against 49.35 in our run (document cosine 0.998 on average), so the stored scores stand. - English → Vietnamese (Qwen3-Embedding-4B, BGE-M3 and EmbeddingGemma 2): English scores are re-computed on exactly the VN-MTEB query subset, so the drop compares the same queries.
5. Checks before a model is scored
- Smoke test: 6 sanity pairs (3 English + 3 Vietnamese) must rank correctly with no NaN; Qwen-family models must use left padding with an EOS last token.
- Throughput and memory (README "Speed and memory"): every open model alone on the same machine, batch 32, 512-token window, bf16 weights and activations (BGE-M3: fp16), 2,048 Zalo Legal documents + 818 queries; peak memory = PyTorch's peak allocation (weights + activations). The NVFP4 checkpoints are excluded there (software emulation). The full accuracy runs shared hardware between jobs, so their timings are not used for speed.
- Harness sanity: BGE-M3 dense on Zalo Legal reproduces the published MRR@10 (65.4 vs 64.4 in the BKAI paper); SciFact matches MTEB (64.1).
6. Caveats
- Several models appear to have seen English benchmark data: scores drop much more on the translated copy of the same queries (e.g. SciFact, ArguAna, FiQA). The native Vietnamese sets are the fairest comparison.
- The five small native sets are mostly Wikipedia QA and near the ceiling, so they separate models less than the large four.
- OpenEmbed is CC-BY-NC (non-commercial).
- One instruction was written per dataset for instruction-tuned models; a different wording can move scores (Table-Markdown is the most sensitive).
- ViQuAD and the Qwen3 models (explained): Qwen3-Embedding-0.6B / 4B score 11 / 17 nDCG@10 on ViQuAD, against ~50–60 for comparable models. The cause is the dataset build plus a property of these models, not a harness bug:
- The mteb ViQuAD retrieval corpus mixes passages with the answer strings themselves as separate documents. 47% of its 2,490 documents are under 40 characters ("Roosevelt", "Mỹ", "1932"), and every query has two relevant documents: the passage and its short answer.
- Qwen3 gives very short texts a high similarity to almost any question. For "How many Iraqi jets fled to Iran?" it scores unrelated one-word documents like "Stalin" at 0.55 and "Roosevelt" at 0.51, close to the correct passage (0.58). Skill-Venus, a Qwen3-0.6B fine-tune, scores the same strings at 0.18–0.22.
- As a result, Qwen3 ranks a short, wrong entity string first for 93–97% of queries; one document ("Roosevelt") is the top hit for 64 different questions. Skill-Venus does this for 41% and EmbeddingGemma-300m for 6%.
- Ruled out: padding/batching (the same short documents encoded alone vs in a mixed batch give cosine 1.00), id collisions (no query id equals a document id) and duplicate documents (none).
- ViQuAD is not part of the native-4 leaderboard average. It still reflects a real risk: with Qwen3, keep very short chunks (titles, single entities) out of the index, or filter them.
Ranking precision
How results were ranked. Retrieval scores in this benchmark come from one of two ranking procedures, marked in each metrics record by the ranking field (the ranking column in results/scores.csv). Records tagged fp32 were ranked by exact nearest-neighbour search in 32-bit floating point over the stored query and document embeddings. This covers all API models, Qwen3-Embedding-8B, Nemotron-3.5 (BF16 and NVFP4), granite-311m, the sets that were encoded in chunks and merged, and the re-scored embeddings of Qwen3-Embedding-4B, BGE-M3 and EmbeddingGemma 2. Records tagged bf16 were ranked in the same pass that produced the embeddings, with query–document similarities computed and stored in bfloat16. Only the metrics and top-10 lists were kept for those runs, so they cannot be re-ranked. bfloat16 keeps only about three significant digits, so many candidate documents receive exactly the same score. Which of them makes the top 10 then depends on tie-breaking rather than on the model. We measured the effect by re-ranking 115 model–task pairs, whose embeddings we still have, both ways. nDCG@10 moved by 0.13 points on average and by up to 0.42 points for 95% of pairs, with a maximum of 0.71, and there was no systematic direction (mean −0.05). P@1 moved by up to 1.2 points for 95% of pairs. Treat differences of about ±0.5 nDCG@10 (and about ±1.5 P@1) between bf16 results as ties. Differences between fp32 results are exact up to equal scores among duplicate documents (below 0.05 nDCG@10).
The remaining rows of those three models without a re-ranked counterpart in results/scores.csv (for example the English sets and the BGE-M3 hybrid modes) are tagged fp16: ranked in fp16, which is finer than bf16. Where both exist, re-ranking those embeddings in fp32 changed nDCG@10 by at most 0.24 at full size and 0.38 for truncated (Matryoshka) sizes.