Retrieval Augmented Spelling Correction for E-Commerce Applications

Xuan Guo, Rohit Patki, Dante Everaert, Christopher Potts

Introduction

In the competitive landscape of e-commerce, search accuracy is a primary driver of customer satisfaction and conversion. A critical component of this accuracy is spelling correction—the ability to interpret a user's intent despite typos or phonetic misspellings. However, traditional spelling correction models and even modern Large Language Models (LLMs) face a significant hurdle known as the "over-correction" problem. This occurs when a model mistakenly "fixes" a valid, unique brand name or niche product term into a more common dictionary word. For instance, a model might change the brand "playgro" to "playground" or "hygeeni" to "hygiene," effectively preventing the user from finding the specific product they intended to buy.

Researchers from Amazon and Stanford have addressed this issue by developing a Retrieval Augmented Generation (RAG) framework specifically tailored for e-commerce spelling services. By integrating real-time product catalog data into the correction process, they have demonstrated that LLMs can be transformed from general-purpose language processors into domain-aware specialists.

The Challenge of Over-Correction

Standard LLMs are trained on massive, static datasets. While this provides them with a broad understanding of language, it also makes them susceptible to two major flaws in an e-commerce context:

  1. Knowledge Obsolescence: New brands and products are launched daily. A model trained six months ago has no inherent knowledge of a brand created yesterday.
  2. Generalization Bias: LLMs are optimized to predict the most likely next token based on general usage. In general English, "playground" is much more common than "playgro," leading the model to favor the former even when the latter is the correct search term.

To solve this, the researchers propose giving the LLM a "live" look at the product catalog during the inference process, ensuring the model has access to the most current "ground truth."

Methodology: The RAG Pipeline

The proposed framework consists of a three-stage pipeline designed to ground the LLM's output in actual catalog data.

1. Retrieval

When a user submits a query, the system first searches the product catalog to identify relevant items. The researchers evaluated three distinct retrieval strategies:

  • BM25: A classic keyword-matching algorithm.
  • Fuzzy BM25: An adaptation of BM25 that allows for minor character-level differences, better suited for catching typos.
  • ColBERT: A sophisticated neural retrieval model that utilizes token-level vector representations to capture semantic intent rather than just literal character matches.

2. Prompting

The top results from the retrieval stage are injected into the LLM's prompt as context. The model is then instructed to use this context to determine whether the user's query contains a typo or if it refers to a specific product or brand present in the catalog.

3. Contextual Fine-Tuning

The researchers discovered that simply providing context to a "frozen" (unmodified) LLM was insufficient. To bridge the gap, they introduced Contextual Fine-Tuning. In this phase, the model is trained on triples consisting of the <query, retrieved context, label>. This specific training teaches the model to distinguish between helpful, relevant context and "noise"—irrelevant or misspelled items that might be returned by the retriever.

Experimental Results

The framework was tested using a dataset of 50,000 training pairs and a 10,000-query evaluation set sampled from Amazon search logs (2021–2023). The evaluation set was intentionally designed to be difficult, with a high density of misspellings (25%) and brand names (33%).

Performance Breakthroughs

The results were stark. A base Mistral-7B model without RAG or fine-tuning achieved a meager F1 score of 28.1. When the full RAG pipeline with ColBERT and Contextual Fine-Tuning was applied, the F1 score surged to 71.0.

Key insights from the data include:

  • The Fine-Tuning Gap: While adding RAG to a frozen Claude-3-sonnet model provided a minor boost (from 34.7 to 39.3 F1), the fine-tuned Mistral model's performance suggests that the model must be explicitly taught how to weigh external context against its internal weights.
  • Neural Retrieval Superiority: ColBERT consistently outperformed BM25 variants. Its ability to understand the intent behind a misspelled query proved crucial for retrieving the correct reference brands from the catalog.
  • Brand Accuracy: On queries specifically involving brand names, the RAG + Contextual Fine-Tuning approach improved the F1 score from 44.1 (basic fine-tuning) to 60.8.

Production Viability

A common concern with RAG systems is latency. However, the researchers found that adding the retrieval step only increased total generation time by 2.79% when using a large index of 572,000 documents. This minimal overhead makes the system highly viable for real-time production environments.

Conclusion and Future Directions

This research demonstrates that RAG, when combined with targeted fine-tuning, can effectively solve the over-correction problem in e-commerce. By grounding LLMs in a dynamic product catalog, the system becomes significantly more resilient to the "vocabulary drift" caused by new brand names.

Future work will focus on "selective RAG"—developing a mechanism for the model to decide if retrieval is necessary before performing it—to further reduce latency and noise. Additionally, the team aims to improve the system's ability to handle "catalog noise," where misspellings within the product database itself can occasionally lead the model astray.

Summary updated

BibTeX
@inproceedings{guo2024retrieval,
  author = {Xuan Guo and Rohit Patki and Dante Everaert and Christopher Potts},
  title = {{Retrieval Augmented Spelling Correction for E-Commerce Applications}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-industry.7},
}
Figure