[!Warning]
I am not affiliated with MongoDB. This model is an implementation of the asymmetric strategy as described in mdbr-leaf-ir, designed for the MongoDB team to adopt/clone.
mdbr-leaf-ir-asym is a compact high-performance text embedding model specifically designed for information retrieval (IR) tasks, e.g., the retrieval stage of Retrieval-Augmented Generation (RAG) pipelines.
If you are looking to perform other tasks such as classification, clustering, semantic sentence similarity, summarization, please check out our mdbr-leaf-mt model.
[!Note] Note: this model has been developed by the ML team of MongoDB Research. At the time of writing it is not used in any of MongoDB's commercial product or service offerings.
Technical Report
A technical report detailing our proposed LEAF training procedure is available here.
Highlights
State-of-the-Art Performance: mdbr-leaf-ir-asym achieves state-of-the-art results for compact embedding models, ranking #1 on the public BEIR benchmark leaderboard for models with ≤100M parameters.
Flexible Architecture Support: mdbr-leaf-ir-asym uses an asymmetric retrieval architecture enabling even greater retrieval results.
MRL and Quantization Support: embedding vectors generated by mdbr-leaf-ir-asym compress well when truncated (MRL) and can be stored using more efficient types like int8 and binary. See below for more information.
Benchmark Comparison
The table below shows the average BEIR benchmark scores (nDCG@10) for mdbr-leaf-ir-asym compared to other retrieval models.
mdbr-leaf-ir ranks #1 on the BEIR public leaderboard, and when run in asymmetric "(asym.)" mode, the results improve even further.
Model
Size
BEIR Avg. (nDCG@10)
OpenAI text-embedding-3-large
Unknown
55.43
mdbr-leaf-ir (asym.)
23M
54.03
mdbr-leaf-ir
23M
53.55
snowflake-arctic-embed-s
32M
51.98
bge-small-en-v1.5
33M
51.65
OpenAI text-embedding-3-small
Unknown
51.08
granite-embedding-small-english-r2
47M
50.87
snowflake-arctic-embed-xs
23M
50.15
e5-small-v2
33M
49.04
SPLADE++
110M
48.88
MiniLM-L6-v2
23M
41.95
BM25
–
41.14
Quickstart
Sentence Transformers
python
1from sentence_transformers import SentenceTransformer
23# Load the model 4model = SentenceTransformer("tomaarsen/mdbr-leaf-ir-asym")56# Example queries and documents7queries =[8"What is machine learning?",9"How does neural network training work?",10]1112documents =[13"Machine learning is a subset of artificial intelligence that focuses on algorithms that can learn from data.",14"Neural networks are trained through backpropagation, adjusting weights to minimize prediction errors.",15]1617# Encode queries and documents18query_embeddings = model.encode_query(queries)19document_embeddings = model.encode_document(documents)2021# Compute similarity scores22scores = model.similarity(query_embeddings, document_embeddings)2324# Print results25for i, query inenumerate(queries):26print(f"Query: {query}")27for j, doc inenumerate(documents):28print(f" Similarity: {scores[i, j]:.4f} | Document {j}: {doc[:80]}...")2930# Query: What is machine learning?31# Similarity: 0.6729 | Document 0: Machine learning is a subset of artificial intelligence that focuses on algorith...32# Similarity: 0.4472 | Document 1: Neural networks are trained through backpropagation, adjusting weights to minimi...3334# Query: How does neural network training work?35# Similarity: 0.4080 | Document 0: Machine learning is a subset of artificial intelligence that focuses on algorith...36# Similarity: 0.5477 | Document 1: Neural networks are trained through backpropagation, adjusting weights to minimi...
mdbr-leaf-ir is aligned to snowflake-arctic-embed-m-v1.5, the model it has been distilled from. This enables flexible architectures in which, for example, documents are encoded using the larger model, while queries can be encoded faster and more efficiently with the compact leaf model. This generally outperforms the symmetric setup in which both queries and documents are encoded with leaf.
To use exclusively the leaf model, use mdbr-leaf-ir.
MRL Truncation
Embeddings have been trained via MRL and can be truncated for more efficient storage:
Vector quantization, for example to int8 or binary, can be performed as follows:
Note: For vector quantization to types other than binary, we suggest performing a calibration to determine the optimal ranges, see here.
Good initial values, according to the teacher model's documentation, are:
int8: -0.3 and +0.3
int4: -0.18 and +0.18
python
1from sentence_transformers.quantization import quantize_embeddings
2import torch
34query_embeds = model.encode(queries, prompt_name="query")5doc_embeds = model.encode(documents)67# Quantize embeddings to int8 using -0.3 and +0.3 as calibration ranges8ranges = torch.tensor([[-0.3],[+0.3]]).expand(2, query_embeds.shape[1]).cpu().numpy()9query_embeds = quantize_embeddings(query_embeds,"int8", ranges=ranges)10doc_embeds = quantize_embeddings(doc_embeds,"int8", ranges=ranges)1112# Calculate similarities; cast to int64 to avoid under/overflow13similarities = query_embeds.astype(int) @ doc_embeds.astype(int).T
1415print('After quantization:')16print(f"* Embeddings type: {query_embeds.dtype}")17print(f"* Similarities:\n{similarities}")1819# After quantization:20# * Embeddings type: int821# * Similarities:22# [[118022 79111]23# [ 72961 98333]]