Hybrid Search Architecture for E-Commerce Websites: Combining BM25 Keywords, Vector Embeddings and RRF Algorithm

On e-commerce websites, online stores or trading floors with catalogs from a few thousand to hundreds of thousands of products, the group of customers who actively type queries into the search bar always has a purchase conversion rate 2 to 4 times higher than the group of customers who just browse the regular catalog. They are people who have clearly identified their needs and are willing to spend money. However, the biggest paradox happening on most sales websites today is that the search system is the weakest part. When a customer types in a phrase that describes a real-life situation like "non-slip running shoes in the rain" or mistakenly types in a letter like "headband noise-canceling headphones", traditional search engines based on LIKE SQL string matching or basic keyword indexing immediately return a cold message: "No matching products found". Just that blank screen is enough to make customers immediately close the tab and switch to shopping on another platform.

To solve this problem completely, modern search system architects are replacing simple search engines with Hybrid Search Architecture – a close combination of traditional Lexical Search and Vector-based Semantic Search (Semantic Vector Search). Each method possesses a unique strength that the other method cannot replace, and only when working together can they create a comprehensive smart search experience in the e-commerce environment.

The first piece of the system is Vocabulary Search with BM25 (Best Matching 25) algorithm operating on the Inverted Index structure of tools such as Elasticsearch, OpenSearch or Meilisearch. The undisputed strength of BM25 is its absolute accuracy for queries containing specific identifiers, product codes (SKUs), brand names or precise specifications. When customers type the exact phrase "iPhone 16 Pro Max 256GB Titan Desert" or the part code "BOSCH-GSR-180", BM25 will calculate the frequency of each keyword in the product title and description, and give the highest priority to rare keywords with specific classification. However, BM25's fatal flaw lies in its complete semantic blindness: if in the store's database, the product is named "Non-slip rubber-soled sneakers", the BM25 algorithm will never understand that the customer's query "rainy running shoes" is targeting those same shoes because there are no keywords that directly match. continued.

The second piece of the puzzle that fills this cognitive gap is Semantic Search Using Vector Embeddings. Instead of storing text as discrete characters, the entire product name, description of use, material and properties of each item in the database are passed through an embedded language model (Embedding Model supports Vietnamese well) to be converted into a multidimensional string of real numbers - called Vector - stored in the super-fast HNSW (Hierarchical Navigable Small World) graph index. In this multidimensional mathematical space, concepts with the same meaning or purpose will be located at very close coordinates. When customers type "luxury middle-aged male boss gifts", their query is also encoded into a vector in real time and the system performs Cosine Similarity distance measurements to pull out a list of products such as high-end pens, purple tea sets or agarwood gift boxes - even though the titles of these products do not contain the word "boss" or "middle-aged". However, if only using Vector Search alone, the system is prone to making silly mistakes in exact identification queries: when a customer searches for "black size XL t-shirt", the vector search may return even a dark blue size M shirt because in the semantic space they are both very close to the concept of "dark t-shirt".

The biggest technical challenge when combining BM25 and Vector Search lies in the fact that these two systems return two completely incompatible scales. similarity: BM25's score is a positive real number with no upper bound (e.g. 14.8 or 27.3), while Vector Search's similarity score is fixed between 0 and 1 (e.g. 0.84). You cannot simply add these two numbers together. This is where the Reciprocal Rank Fusion (RRF) algorithm plays its role as an excellent conductor. Instead of paying attention to the raw score difference of each engine, the RRF algorithm only considers the ranking position (Rank) of each product in the results list of each search stream, applying the aggregate score formula:

Where $rank_i(d)$ is the ranking of product $d$ in the $i$ search system, and $k$ is a smoothing constant (usually chosen to be 60) to prevent The fact that a product ranks top 1 in one stream but completely disappears in the other stream is too dominant. Thanks to this scoring mechanism based on relative rankings, products that both exactly match important keywords (ranking high in BM25) and closely match the contextual intent of the buyer (ranking high in Vector Search) will automatically be pushed to the first positions on the results page, while noisy results of each individual method are pushed back down.

To turn the Hybrid Search architecture into a true sales machine on the website interface, the technical team also combined Incorporates a pre-query processing layer and instant suggestions (Instant Autocomplete): automatically corrects typing errors in Vietnamese diacritics, identifies hidden attribute filters right in the search sentence (for example, automatically separates "little floral dress under 500k" into the keyword "little floral dress" with the price <= 500000 filter), and always displays best-selling products in the same related categories if the warehouse really runs out of the model the customer is looking for. Investing in upgrading the search system according to Hybrid Search architecture not only helps users find the right item they want in a few seconds, but also fully exploits the value of the entire product catalog available on the website.