August 12, 2024

BM𝒳: A Freshly Baked Take on BM25

All posts
BM𝒳: A Freshly Baked Take on BM25

Reading Time

8 min read

Publish Date

August 12, 2024

Authors

  • Sean Lee

    Sean Lee

  • Aamir Shakir

    Aamir Shakir

  • Julius Lipp

    Julius Lipp

  • Rui Huang

    Rui Huang

We are proud to announce that researchers from Mixedbread and the Hong Kong Polytechnic University have developed a new lexical search algorithm, BMX, that outperforms the current standard BM25 across the board and is easy to use via Mixedbread's open-source Baguetter library.

Read on to learn about BMX, how it works, our benchmarks, and how to use it in practice. If you want to jump right in, you can look into the paper and the library right here:

  • : Our research paper covering the approach in more academic detail.
  • : Our reference implementation of BMX and an easy to hack testing framework for information retrieval.

What is BMX?

Most text search engines are powered by lexical (keyword) search algorithms, the most prominent of which is BM25. It powers search engines for web search, e-commerce, legal search engines, and many more applications. A key strength of is that it performs really well in an out of distribution setting, meaning that it generalizes well on data it has not seen before. However, the keyword search approach comes with its own limitations:

  1. BM25 does not consider the similarity between the query and any given document, which could enable a more accurate assessment of this document's relevance to the query.
  2. Lexical search algorithms lack semantic understanding and are therefore unable to deal with linguistic nuances like synonyms and homonyms. This limitation is a key factor in the underperformance of lexical search compared to domain-specific text embedding-based semantic search.

To tackle these challenges, we propose BMX, a lexical search algorithm that incorporates both similarity and semantics. It comes with these key innovations:

  1. Entropy-weighted similarity: We adjust the similarity scores between query tokens and related documents based on the entropy of each token. This approach reduces the influence of common tokens, allowing less frequent but more meaningful tokens to have a greater impact on the similarity score.

  2. Weighted query augmentation (WQA): To incorporate semantics into lexical search, we developed a method that processes both the original query and its augmented versions simultaneously within BMX. This approach removes the need for multiple retrievals and reranking steps, leading to increased efficiency.

How does BMX work?

Now, we will explore the core scoring algorithm in BMX as well as weighted query augmentation (WQA). This will be a math-heavy section, but please bear with us!

Performance and Benchmarking

To validate our ideas and assess the performance of BMX, we evaluated it extensively on different benchmarks including , , and some multilingual benchmarks. You can find a full overview of our benchmarking in the . Our results show that BMX outperforms BM25 across the board and can offer a significant improvement in retrieval quality.

BEIR

BEIR is a benchmark focused on out-of-domain information retrieval. It covers datasets for different domains, document or query lengths, and tasks. After evaluation on the 15 available benchmarks, we compare BMX to the implementations of BM25 in and the library:

ModelAASDSFNFCTCVTCHFQAHQAMMFVRNQDBPQRACFCQAAvg.
BM25S, k1=1.2, b=0.75
Robertson49.215.568.331.959.033.825.458.522.650.329.230.380.413.729.939.87
ATIRE48.715.668.131.861.033.225.358.522.650.329.130.380.513.730.139.92
BM25+48.715.668.131.861.033.225.358.522.650.329.130.380.513.730.139.92
BM25L49.615.868.732.262.933.025.055.921.446.628.129.480.313.529.839.48
BM2548.715.668.031.861.033.225.358.522.650.329.130.380.513.730.139.91
Baguetter, k1=1.2, b=0.75
Robertson49.5515.6968.7132.8564.3630.9525.2759.1323.1950.9328.5531.6978.7313.5430.7340.26
ATIRE49.2315.6668.7332.7165.9431.1525.3059.1323.2350.9828.5931.5678.7213.5531.0040.37
BM25+49.2315.6668.7332.7165.9431.1525.3059.1323.2350.9828.5931.5678.7213.5531.0040.37
BM25L50.3215.8869.3733.0067.0531.5224.7956.3522.0147.3727.3530.8778.2113.2930.8739.88
BM2549.3215.6568.6732.6865.7831.1125.2659.0923.2450.9828.8531.5678.7313.5530.9940.36
BMX50.4615.9169.4232.8468.134.3425.3961.7324.2155.7529.8432.278.5613.3230.7741.52

As the table shows, BMX generally outperforms all BM25 variants, achieving the best results on 11 out of 15 datasets. In our view, this underscores the importance of incorporating query-document similarity in our search algorithm.

Other than that, we also observe that embedding-based models consistently outperform lexical models, which can be attributed to their powerful semantic understanding. However, due to their significant advantage regarding resource requirements, lexical search algorithms still remain much more widely used.

BRIGHT

BRIGHT was introduced as the first text retrieval benchmark requiring intensive reasoning to retrieve the relevant documents. The benchmark includes 1,385 real-world queries across diverse domains such as StackExchange, LeetCode, and math competitions. These queries are paired with, for example, relevant web pages linked in StackExchange answers and theorems tagged in math Olympiad questions, all of which necessitate deliberate reasoning to identify their connections to the respective queries. For this evaluation, we also took a look at the performance of BMX with WQA.

ModelBIOESECOPSYROBSOSLLCPONYAOPSTQTTAvg.
Embedding Models
E5-Mistral-7B18.8026.0015.5015.8016.409.8018.5028.704.807.1023.9025.1017.50
Proprietary Models
OpenAI23.7026.3020.0027.5012.9012.5020.3023.602.508.5022.2010.8017.57
Cohere19.0027.5020.2021.8016.2016.5017.7026.801.806.5015.107.1016.35
Voyage23.6025.1019.8024.8011.2015.0015.6030.601.507.4026.1011.1017.65
Lexical Models
BM25 (k1=0.9k1=0.9, b=0.4b=0.4)19.2529.6716.8915.7714.1915.2215.3025.054.628.286.572.3414.43
BM25 (k1=0.9k1=0.9, b=0.4b=0.4) + WQA22.933.8617.224.3314.5420.2116.0126.616.038.4110.503.2916.99
BMX (α=0.05\alpha=0.05)26.433.5513.2916.0614.6813.8015.4725.3510.919.188.172.3815.77
BMX (α=0.05\alpha=0.05) + WQA31.5740.2417.4023.5316.6718.3215.0528.3410.829.229.982.7418.66

The table demonstrates that BMX with weighted query augmentation outperforms all baselines, including embedding models and other lexical models. We attribute this to BMX's ability to generalize effectively across various domains, while embedding models often struggle with out-of-domain data. The results highlight that the WQA mechanism successfully enhances BMX’s semantic understanding, enabling it to handle realistic retrieval scenarios more effectively than alternative solutions. Also, BMX achieves this without the need for costly training on massive high-quality datasets, as would be required for embedding models.

Multilingual Benchmark

To verify the performance of BMX on multilingual data, we also performed benchmarking on datasets for Chinese, Japanese, Korean, German, and French retrieval tasks.

ModelMMarcoRetrieval (Chinese)JaQuAD (Japanese)StrategyQA (Korean)GermanDPR (German)FQuAD (French)Avg.
BM2547.4154.2633.8952.2791.8055.93
BMX47.9454.6335.7253.5891.9256.76

The table presents the evaluation results, demonstrating that BMX consistently outperforms BM25 across these multilingual datasets. This suggests the increased effectiveness of BMX in handling diverse multilingual information retrieval tasks.

Try it out

Installation

Before you start, make sure to install the Baguetter library:

pip install baguetter

Usage

The following examples show how to use BMX in practice:

from baguetter.indices import BMXSparseIndex
 
# Initialize BM𝒳 index
bmx = BMXSparseIndex()
 
# Add bakery items to the index
docs = [
    "Freshly crusty baked sourdough bread with a crispy crust",
    "Flaky croissants made with French butter",
    "Chocolate chip cookies with chunks of dark chocolate",
    "Cinnamon rolls with cream cheese frosting",
    "Artisanal baguettes with a soft interior and crusty exterior"
]
keys = list(range(len(docs)))
 
bmx.add_many(keys=keys, values=docs)
 
# Search for bread
query = "crusty bread"
results = bmx.search(query, top_k=2)
 
print(results)
# SearchResults(keys=[0, 4], scores=array([2.5519667 , 0.97304875], dtype=float32), normalized=False)

Why does this matter?

Improving the quality of lexical search without a significant increase in complexity or computational resource requirements could lead to a range of beneficial outcomes. Using BMX could improve the user experience of any application that relies on search algorithms. We also expect performance benefits for natural language processing applications that include our algorithm as part of their pipeline.

We're excited to hear about the community's opinions on BMX and where this algorithm could be used in the future. If you want to give us feedback or discuss anything search- or machine learning-related, please come join our .

Cite As:
@article{li2024bmx,
      title={BMX: Entropy-weighted Similarity and Semantic-enhanced Lexical Search},
      author={Xianming Li and Julius Lipp and Aamir Shakir and Rui Huang and Jing Li},
      year={2024},
      eprint={2408.06643},
      archivePrefix={arXiv},
      primaryClass={cs.IR},
      url={https://arxiv.org/abs/2408.06643},
}