Retrieval-augmented generation for WooCommerce is often associated with vector embeddings, semantic similarity, and large language models. Those components are valuable, but they do not replace lexical retrieval. BM25 still matters because WooCommerce catalogs contain exact terms that customers, support agents, and merchandising teams expect the search system to recognize precisely.
What BM25 contributes to WooCommerce RAG
BM25 is a term-based ranking algorithm used by search engines such as Elasticsearch and OpenSearch. It scores documents according to factors including term frequency, inverse document frequency, and field-length normalization. In practical terms, a product is more relevant when it contains the words in the query, especially when those words are uncommon and appear in important fields.
That behavior is particularly useful for catalog data. Queries containing an SKU, model number, fabric code, compatibility identifier, or exact product name often have little semantic ambiguity. A vector search may find products with similar descriptions, but BM25 can identify the precise matching product immediately.
Where lexical retrieval outperforms embeddings
- SKUs and model numbers: A query such as
ACME-TRV-204should return the matching product before visually similar products. - Technical specifications: Terms such as
IP68,USB-C PD 100W,18-55mm, and3/8-16can be poorly represented by embeddings or tokenized inconsistently. - Brand and product names: Exact names are important when a customer is asking about a known item rather than exploring a category.
- Compatibility queries: Device identifiers, vehicle years, part numbers, and software versions usually require literal matching.
- Policy and support content: Terms such as “final sale,” “subscription renewal,” or a specific shipping method may need exact evidence from indexed documents.
For a WooCommerce agency, this means a RAG pipeline should not assume that semantic similarity is the best first-stage retriever for every request. Retrieval should match the structure of the query and the catalog.
BM25 in a WooCommerce retrieval pipeline
A practical architecture uses BM25 and vector search as complementary retrieval methods:
- Normalize the query. Preserve meaningful identifiers while standardizing case, whitespace, and common punctuation.
- Run lexical retrieval. Search product titles, SKUs, attributes, short descriptions, long descriptions, and selected taxonomy terms with field-specific boosts.
- Run semantic retrieval. Use an embedding search for conceptual requests such as “a quiet outdoor heater for a small patio.”
- Fuse or rerank the results. Combine lexical and vector scores, or send the candidate set to a reranker that considers the original query.
- Apply WooCommerce constraints. Remove products that are not published, purchasable, in the requested category, within the price range, or compatible with the selected attributes.
- Build the generation context. Include only authoritative product fields and the source identifiers needed for citations or traceability.
BM25 can be used as the primary retriever for exact or identifier-heavy queries and as one candidate generator in a hybrid pipeline for natural-language queries.
Use field boosts instead of treating all catalog text equally
WooCommerce product data is not a flat document. A match in the product title or SKU usually deserves more weight than a match buried in a long description. Attribute values may also be more important than marketing copy when the query contains a specification.
A representative Elasticsearch-style query might look like this:
{
"query": {
"multi_match": {
"query": "USB-C 100W charger",
"fields": [
"sku^8",
"name^6",
"attributes.value^4",
"categories^2",
"short_description^2",
"description"
],
"type": "best_fields",
"operator": "and"
}
}
}
The exact boosts should be validated against production queries rather than copied unchanged. A SKU match may deserve a near-exact clause, while a long description may benefit from broader matching. Agencies should also decide whether variations, parent products, and child-specific SKUs are indexed as separate searchable documents.
Handling identifiers and WooCommerce tokenization
Default analyzers are not always suitable for product identifiers. Hyphens, slashes, periods, and mixed alphanumeric strings can change how a term is indexed. For example, ACME-TRV-204, IP68, and 18-55mm should be tested with the chosen analyzer to ensure that searches match the intended tokens.
A common pattern is to index both analyzed and exact forms:
- An analyzed field supports partial or natural-language matching.
- A
keywordfield supports exact matching, filtering, and identifier boosts. - A normalized keyword field can support case-insensitive matching while retaining the original display value.
For SKUs and external part numbers, an exact match can receive a strong boost without forcing every query into exact-match behavior. Be careful with punctuation removal: aggressive normalization can create collisions between distinct products.
BM25 and faceted filtering are different responsibilities
BM25 ranks textual relevance; it does not replace WooCommerce filters. A customer asking for “black waterproof hiking boots under $150” may need both lexical or semantic retrieval and structured constraints for color, water resistance, product category, and price.
Index structured values separately so the retrieval layer can apply filters such as:
category =