lucataco / bge-m3

BGE-M3, the first embedding model which supports multiple retrieval mode, multilingual and multi-granularity retrieval.

  • Public
  • 234 runs
  • GitHub
  • Paper
  • License

Run time and cost

This model costs approximately $0.039 to run on Replicate, or 25 runs per $1, but this varies depending on your inputs. It is also open source and you can run it on your own computer with Docker.

This model runs on Nvidia T4 GPU hardware. Predictions typically complete within 3 minutes. The predict time for this model varies significantly based on the inputs.

Readme

BGE-M3 (paper, code)

In this project, we introduce BGE-M3, which is distinguished for its versatility in Multi-Functionality, Multi-Linguality, and Multi-Granularity. - Multi-Functionality: It can simultaneously perform the three common retrieval functionalities of embedding model: dense retrieval, multi-vector retrieval, and sparse retrieval. - Multi-Linguality: It can support more than 100 working languages. - Multi-Granularity: It is able to process inputs of different granularities, spanning from short sentences to long documents of up to 8192 tokens.

Some suggestions for retrieval pipeline in RAG: We recommend to use following pipeline: hybrid retrieval + re-ranking. - Hybrid retrieval leverages the strengths of various methods, offering higher accuracy and stronger generalization capabilities. A classic example: using both embedding retrieval and the BM25 algorithm. Now, you can try to use BGE-M3, which supports both embedding and sparse retrieval. This allows you to obtain token weights (similar to the BM25) without any additional cost when generate dense embeddings. - As cross-encoder models, re-ranker demonstrates higher accuracy than bi-encoder embedding model. Utilizing the re-ranking model (e.g., bge-reranker, cohere-reranker) after retrieval can further filter the selected text.

News:

  • 2/6/2024: We release the MLDR (a long document retrieval dataset covering 13 languages) and evaluation pipeline.
  • 2/1/2024: Thanks for the excellent tool from Vespa. You can easily use multiple modes of BGE-M3 following this notebook

Specs

  • Model
Model Name Dimension Sequence Length Introduction
BAAI/bge-m3 1024 8192 multilingual; unified fine-tuning (dense, sparse, and colbert) from bge-m3-unsupervised
BAAI/bge-m3-unsupervised 1024 8192 multilingual; contrastive learning from bge-m3-retromae
BAAI/bge-m3-retromae 8192 multilingual; extend the max_length of xlm-roberta to 8192 and further pretrained via retromae
BAAI/bge-large-en-v1.5 1024 512 English model
BAAI/bge-base-en-v1.5 768 512 English model
BAAI/bge-small-en-v1.5 384 512 English model
  • Data
Dataset Introduction
MLDR Docuemtn Retrieval Dataset, covering 13 languages

FAQ

1. Introduction for different retrieval methods

  • Dense retrieval: map the text into a single embedding, e.g., DPR, BGE-v1.5
  • Sparse retrieval (lexical matching): a vector of size equal to the vocabulary, with the majority of positions set to zero, calculating a weight only for tokens present in the text. e.g., BM25, unicoil, and splade
  • Multi-vector retrieval: use multiple vectors to represent a text, e.g., ColBERT.

2. Comparison with BGE-v1.5 and other monolingual models

BGE-M3 is a multilingual model, and its ability in monolingual embedding retrieval may not surpass models specifically designed for single languages. However, we still recommend trying BGE-M3 because of its versatility (support for multiple languages and long texts). Moreover, it can simultaneously generate multiple representations, and using them together can enhance accuracy and generalization, unlike most existing models that can only perform dense retrieval.

In the open-source community, there are many excellent models (e.g., jina-embedding, colbert, e5, etc), and users can choose a model that suits their specific needs based on practical considerations, such as whether to require multilingual or cross-language support, and whether to process long texts.

3. How to use BGE-M3 in other projects?

For embedding retrieval, you can employ the BGE-M3 model using the same approach as BGE. The only difference is that the BGE-M3 model no longer requires adding instructions to the queries. For sparse retrieval methods, most open-source libraries currently do not support direct utilization of the BGE-M3 model. Contributions from the community are welcome.

In our experiments, we use Pyserini and Faiss to do hybrid retrieval. Now you can ou can try the hybrid mode of BGE-M3 in Vespa. Thanks @jobergum.

4. How to fine-tune bge-M3 model?

You can follow the common in this example to fine-tune the dense embedding.

Our code and data for unified fine-tuning (dense, sparse, and multi-vectors) will be released.

Evaluation

Currently, the results of BM25 on non-English data are incorrect. We will review our testing process and update the paper as soon as possible. For more powerful BM25, you can refer to this repo. Thanks to the community for the reminder and to carlos-lassance for providing the results.

  • Multilingual (Miracl dataset)

avatar

  • Cross-lingual (MKQA dataset)

avatar

  • Long Document Retrieval
  • MLDR:
    avatar Please note that MLDR is a document retrieval dataset we constructed via LLM, covering 13 languages, including test set, validation set, and training set. We utilized the training set from MLDR to enhance the model’s long document retrieval capabilities. Therefore, comparing baselines with Dense w.o.long(fine-tuning without long document dataset) is more equitable. Additionally, this long document retrieval dataset will be open-sourced to address the current lack of open-source multilingual long text retrieval datasets. We believe that this data will be helpful for the open-source community in training document retrieval models.

  • NarritiveQA:
    avatar

Training

  • Self-knowledge Distillation: combining multiple outputs from different retrieval modes as reward signal to enhance the performance of single mode(especially for sparse retrieval and multi-vec(colbert) retrival)
  • Efficient Batching: Improve the efficiency when fine-tuning on long text. The small-batch strategy is simple but effective, which also can used to fine-tune large embedding model.
  • MCLS: A simple method to improve the performance on long text without fine-tuning. If you have no enough resource to fine-tuning model with long text, the method is useful.

Refer to our report for more details.

The fine-tuning codes and datasets will be open-sourced in the near future.

Acknowledgement

Thanks the authors of open-sourced datasets, including Miracl, MKQA, NarritiveQA, etc. Thanks the open-sourced libraries like Tevatron, pyserial.

Citation

If you find this repository useful, please consider giving a star :star: and citation

@misc{bge-m3,
      title={BGE M3-Embedding: Multi-Lingual, Multi-Functionality, Multi-Granularity Text Embeddings Through Self-Knowledge Distillation}, 
      author={Jianlv Chen and Shitao Xiao and Peitian Zhang and Kun Luo and Defu Lian and Zheng Liu},
      year={2024},
      eprint={2402.03216},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}