BMX: A Freshly Baked Take on BM25

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:

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

Our new BMX search algorithm iterates on the long-standing industry standard
and can be accessed via our fully open-source Baguetter library.

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 BM25 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:

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.
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:

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.

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.

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!

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

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 Baguetter and the bm25s library:

ModelAASDSFNFCTCVTCHFQAHQAMMFVRNQDBPQRACFCQAAvg.BM25S, k1=1.2, b=0.75Robertson49.215.568.331.959.033.825.458.522.650.329.230.380.413.729.939.87ATIRE48.715.668.131.861.033.225.358.522.650.329.130.380.513.730.139.92BM25+48.715.668.131.861.033.225.358.522.650.329.130.380.513.730.139.92BM25L49.615.868.732.262.933.025.055.921.446.628.129.480.313.529.839.48BM2548.715.668.031.861.033.225.358.522.650.329.130.380.513.730.139.91Baguetter, k1=1.2, b=0.75Robertson49.5515.6968.7132.8564.3630.9525.2759.1323.1950.9328.5531.6978.7313.5430.7340.26ATIRE49.2315.6668.7332.7165.9431.1525.3059.1323.2350.9828.5931.5678.7213.5531.0040.37BM25+49.2315.6668.7332.7165.9431.1525.3059.1323.2350.9828.5931.5678.7213.5531.0040.37BM25L50.3215.8869.3733.0067.0531.5224.7956.3522.0147.3727.3530.8778.2113.2930.8739.88BM2549.3215.6568.6732.6865.7831.1125.2659.0923.2450.9828.8531.5678.7313.5530.9940.36BMX50.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 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 ModelsE5-Mistral-7B18.8026.0015.5015.8016.409.8018.5028.704.807.1023.9025.1017.50Proprietary ModelsOpenAI23.7026.3020.0027.5012.9012.5020.3023.602.508.5022.2010.8017.57Cohere19.0027.5020.2021.8016.2016.5017.7026.801.806.5015.107.1016.35Voyage23.6025.1019.8024.8011.2015.0015.6030.601.507.4026.1011.1017.65Lexical ModelsBM25 (, )19.2529.6716.8915.7714.1915.2215.3025.054.628.286.572.3414.43BM25 (, ) + WQA22.933.8617.224.3314.5420.2116.0126.616.038.4110.503.2916.99BMX ()26.433.5513.2916.0614.6813.8015.4725.3510.919.188.172.3815.77BMX () + 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.

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.93BMX47.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.

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

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)

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 Discord community.

{Categories} _Category: Takes{/Categories}
{URL}https://www.mixedbread.ai/blog/intro-bmx{/URL}
{Author}unknown{/Author}
{Image}https://www.mixedbread.ai/images/blog/intro-bmx/intro-bmx.jpg?title=BM%F0%9D%92%B3%3A+A+Freshly+Baked+Bake+on+BM25+-+Blog&description=Introducing+BMX%2C+an+iteration+on+the+industry+standard+BM25+search+algorithm.+Through+the+incorporation+of+entropy-weighted+query-document+similarity+and+weighted+query+augmentation%2C+the+algorithm+can+increase+search+performance+on+the+most+relevant+information+retrieval+benchmarks.{/Image}
{Keywords}{/Keywords}
{Source}POV{/Source}
{Thumb}{/Thumb}

Exit mobile version