Research report · July 2026

Routing Commerce Search Queries: Simple Lookup vs. LLM Overview

A binary classifier that decides, per query, whether an e-commerce search should return the ordinary product grid (SIMPLE — “men’s shirts”) or additionally trigger an LLM-generated shopping overview (COMPLEX — “shirts for a beach wedding in Hawaii in summer”). Built and evaluated on 6,636 ensemble-labeled queries from five public datasets, with leave-one-dataset-out generalization tests, a targeted commerce-complex challenge slice, and an explicit latency/cost frontier.

95.7%test accuracy, recommended model (95% CI 94.6–96.8)
29→60%commerce-complex recall, base → shipped configuration
~3 msp50 single-query latency (DistilBERT, Apple M-series)
κ = 0.915inter-annotator agreement of the label ensemble

▶ Try the live demo — the exact int8 export of the recommended model, served from this site. Code on GitHub.

Recommendation. Ship the fine-tuned DistilBERT trained with commerce-complex enrichment, operated at threshold τ = 0.25. It is within noise of the best LLM-free accuracy on the IID test set, doubles recall on the commerce-complex slice the feature actually targets, and costs ~3 ms per query — 200× faster than putting an LLM in the routing hot path (649 ms p50, ~$0.02 per 1k queries).

1Problem & taxonomy

Search overviews are expensive (LLM latency + tokens) and, on straightforward queries, worse than useless — they push the product grid below the fold. The router’s job is to spend that cost only where synthesis adds value. We use a binary taxonomy:

The full annotation rubric (with tie-breakers, e.g. attribute-stacking stays SIMPLE; bare superlatives are COMPLEX; canonical occasion-categories like “wedding dress” stay SIMPLE) is reproduced below and shipped as src/rubric.py.

Annotation rubric (verbatim)
Label SIMPLE when a conventional product-search backend fully serves the intent:
the query names a product, brand, model/SKU, or category, possibly with directly
filterable attributes (size, color, material, gender, price cap). The user knows
what they want; showing a ranked product grid is the complete answer.

Label COMPLEX when an LLM overview genuinely helps: satisfying the query requires
inference, synthesis, or explanation that a product grid alone does not provide.
Signals (any one suffices): occasion/context translation · advice/recommendation
intent incl. superlatives · multi-constraint trade-offs or persona fit ·
comparisons · compatibility/fitment · question-form or how-to ·
gift discovery · problem/symptom queries.

Tie-breakers: attribute-stacking alone stays SIMPLE no matter how many attributes;
a bare superlative ("best coffee maker") is COMPLEX; a price cap alone stays SIMPLE,
price + use case is COMPLEX; canonical occasion-categories ("wedding dress",
"running shoes") stay SIMPLE; nonsense/navigational fragments default to SIMPLE.

2Datasets

Five public query datasets, four of them commerce product-search logs and one general-web set (MS MARCO) kept deliberately as a domain-shift probe. From each we sampled, cleaned (length 3–150 chars, ≥90% ASCII, cross-dataset dedupe), and pooled 6,661 unique queries.

DatasetSourceUnique queriesSampled% COMPLEX
Amazon ESCI (US)amazon-science/esci-data (Apache-2.0)97,3452,5004.7
Home DepotKaggle relevance task (HF mirror)11,7952,0001.2
MS MARCO (dev)Microsoft passage ranking101,0931,50096.5
WANDS (Wayfair)wayfair/WANDS (MIT)4804803.2
TREC Product Search ’23trec-product-search (HF)1861863.2
MS MARCO: 96.5% COMPLEX (n=1,492) MS MARCO 96.5% Amazon ESCI: 4.7% COMPLEX (n=2,491) Amazon ESCI 4.7% WANDS: 3.2% COMPLEX (n=476) WANDS 3.2% TREC Product Search: 3.2% COMPLEX (n=185) TREC PS ’23 3.2% Home Depot: 1.2% COMPLEX (n=1,992) Home Depot 1.2% 0%25% 50%75% 100%

Figure 1 — Labels correlate strongly with dataset. Commerce logs are 95–99% SIMPLE; MS MARCO’s question-form queries are 96.5% COMPLEX. This imbalance drives both the generalization findings (§6) and the enrichment experiment (§7).

3Ground truth by LLM ensemble

No public dataset carries this label, so ground truth was produced by an ensemble of Gemini 2.5 Flash annotators: two independent prompt variants — A: rubric-verbatim, label-only; B: a re-framed “router” task with per-query rationale — each labeling all 6,661 queries at temperature 0, plus an adjudicator variant with a larger thinking budget that ruled only on A/B disagreements.

Known bias: a Gemini few-shot classifier is also one of the evaluated models (§5). Since gold labels come from Gemini prompts too, its score is optimistic — treated as a soft ceiling, not a fair competitor (§9).

4Classifier candidates

ModelDescriptionParams / cost profile
length_thresh≥6 tokens → COMPLEX (honesty baseline)1 constant
heuristichand-written rules: question words, superlatives, “vs”, gift, pronouns, “for” + occasion/persona lexicons~90 keywords, 1 µs
feats_gbm18 engineered lexical features → HistGradientBoostingsmall tree ensemble
tfidf_logregword 1-2gram + char 3-5gram TF-IDF → logistic regression (C tuned on val)sparse linear, 0.3 ms
minilm_logregfrozen all-MiniLM-L6-v2 embeddings → logistic regression22M frozen + linear
distilbert_ftDistilBERT fine-tuned end-to-end (3 epochs, 32 s on M-series)66M, ~3 ms
gemini_fewshotGemini 2.5 Flash, 10-example few-shot prompt (no rubric)API call, 649 ms

Splits: 70/10/20 train/val/test, stratified by label × dataset, fixed seed; all models share the identical test set (n = 1,328).

5Main results

Gemini few-shot: 97.1% (96.2–98.0) — shares model family with the labelers; 649 ms gemini few-shot ⚠ .971 DistilBERT fine-tuned: 96.1% (95.0–97.1) distilbert ft .961 DistilBERT fine-tuned + enrichment (recommended): 95.7% (94.6–96.8) distilbert ft +enrich ★ .957 TF-IDF + LogReg + enrichment: 95.3% (94.1–96.4) tfidf logreg +enrich .953 TF-IDF + LogReg: 94.9% (93.7–96.0) tfidf logreg .949 MiniLM embeddings + LogReg: 93.8% (92.5–95.1) minilm logreg .938 Engineered features + GBM: 90.7% (89.2–92.3) feats gbm .907 Hand-written heuristic: 88.7% (87.0–90.4) heuristic .887 Length threshold ≥6 tokens: 79.1% (77.0–81.2) length ≥ 6 .791 .75.80 .85.90 .951.0 test accuracy (n = 1,328), whiskers = bootstrap 95% CI

Figure 2 — Accuracy at argmax threshold, 2,000-resample bootstrap CIs. The hatched Gemini bar shares a model family with the labeling ensemble (§9); ★ marks the recommended model. All learned models beat the heuristic by wide, non-overlapping margins.

ModelAccMacro-F1Complex PComplex RROC-AUCp50 lat.$/1k queries
gemini_fewshot ⚠.971.962.917.969649 ms$0.02
distilbert_ft.961.945.950.884.9853.3 ms~0
distilbert_ft +enrich ★.957.942.907.916.9843.3 ms~0
tfidf_logreg +enrich.953.932.954.844.9760.3 ms~0
tfidf_logreg.949.927.947.834.9740.3 ms~0
minilm_logreg.938.912.907.825.9663.2 ms~0
feats_gbm.907.862.902.691.8959.7 ms~0
heuristic.887.834.829.6691 µs~0
length ≥ 6.791.704.575.516~0~0

Three observations. First, query complexity is largely a surface-lexical property: a 0.3 ms sparse linear model recovers ~95% accuracy, and even a length threshold gets 79%. Second, fine-tuning buys its margin mostly on complex recall (.916 vs .844 for TF-IDF at comparable precision) — exactly the metric the product cares about. Third, the LLM’s +1 pt over DistilBERT costs 200× the latency; in a hot path serving every search, that trade is unjustifiable.

6Generalization: leave-one-dataset-out

Each trainable model was retrained five times with one dataset fully held out. Accuracy stays high on held-out commerce datasets, but macro-F1 reveals the cost: recall of the rare COMPLEX class collapses on unseen domains.

heuristic tfidf logreg distilbert ft
ESCI tfidf: 0.571 heuristic: 0.613 distilbert: 0.655 Home Depot heuristic: 0.576 tfidf: 0.604 distilbert: 0.708 MS MARCO tfidf: 0.034 distilbert: 0.034 heuristic: 0.506 learned models collapse → predict all-SIMPLE TREC PS heuristic: 0.560 tfidf: 0.617 distilbert: 0.672 WANDS tfidf: 0.492 distilbert: 0.492 heuristic: 0.628 0.00.25 0.500.75 1.0 macro-F1

Figure 3 — Macro-F1 with each dataset held out of training. Trained without MS MARCO, every learned model routes essentially all of its question-form queries to SIMPLE (3.5% accuracy on a 97%-COMPLEX set), while the keyword heuristic — which hard-codes question words — reaches 0.51 F1 / 73% accuracy.

The headline finding of this study: learned complexity signals do not transfer across phrasing domains. A model that has never seen question-form informational queries does not discover that “how much does X cost” is COMPLEX — no matter the architecture. Training-data diversity matters more than model capacity; the cheap insurance is a rule-OR-model union (route COMPLEX if either fires), which preserves the heuristic’s domain-independent floor.

7The commerce-complex gap

Only ~160 of the pool’s COMPLEX labels come from commerce logs — yet “shirts for a beach wedding”-style queries are the whole point of the feature. Two interventions target this gap:

  1. Enrichment: 2,000 extra ESCI/Home Depot queries, sampled with a bias toward complexity signals (≥5 tokens or advice/occasion keywords), ensemble-labeled the same way (κ = 0.73 — these are harder, more borderline queries). Half joined training; half form a held-out challenge slice (1,000 queries, 65 COMPLEX).
  2. Operating point: the router’s threshold is a product decision, not 0.5 by default. An unnecessary overview costs interface real estate and tokens; a missed one loses the feature’s value. We sweep τ on held-out data.
Challenge slice (n=1,000)Complex recallFalse-positive rate
distilbert_ft (τ=.5).292.018
tfidf_logreg (τ=.5).400.027
distilbert_ft +enrich (τ=.5).462.034
distilbert_ft +enrich (τ=.25) ★.600.063
heuristic.585.179
challenge complex recall IID test accuracy challenge false-positive rate
τ = .25 ★ τ=.25 — IID test accuracy .950 τ=.25 — challenge recall .600 τ=.25 — challenge FPR .063 τ=.5 — IID test accuracy .957 τ=.5 — challenge recall .462 τ=.5 — challenge FPR .034 .957 acc .462 recall .034 FPR .10.20 .30.40 .50 threshold τ 0 .5 1.0

Figure 4 — Threshold sweep for the enriched DistilBERT. Moving from argmax (τ=.5) to τ=.25 lifts commerce-complex recall .462→.600 while IID accuracy slips only .957→.950 and the false-positive rate stays at 6.3%. The model is systematically under-confident on occasion-translation queries (they cluster at p≈0.1–0.6), so a lower threshold recovers them cheaply.

Net effect of both interventions: commerce-complex recall .292 → .600 (+31 pts) for −1.1 pt IID accuracy. The heuristic still catches slightly fewer of these than the shipped configuration while triggering falsely 3× as often.

8Error analysis

The recommended model makes 66 errors on the 1,328-query test set. Reading all of them, three clusters emerge:

9Threats to validity

  1. LLM-labeled ground truth. Gold labels are Gemini-ensemble output. The κ=0.915 agreement is between two prompts of the same model family — it bounds prompt-sensitivity, not true label quality. The 70-query human audit (~95% agreement) mitigates but does not eliminate this; the Gemini few-shot “ceiling” in §5 is inflated for the same reason.
  2. Domain–label confound. 90% of COMPLEX labels come from MS MARCO (Figure 1), so IID metrics partly reward domain recognition. The LODO study (§6) and the challenge slice (§7) were designed specifically to expose this — and did.
  3. Challenge-slice noise. The enriched sample’s κ is 0.73 (borderline queries by construction); its recall numbers carry more label noise than the main test set.
  4. English-only, US-centric, and latency measured on one machine (Apple M-series, batch = 1).

10Deployment recommendation

  1. Router: distilbert_ft_enriched at τ = 0.25, in-process (~3 ms p50, no extra infra). Where 3 ms is too much, tfidf_logreg at 0.3 ms keeps 95.3% accuracy but gives up complex recall.
  2. Union with the heuristic for domain robustness (§6): route COMPLEX if either the model or the question-word/comparison rules fire. The rules cost microseconds and cover phrasing families the training data may lack.
  3. Overview is additive, not substitutive: at τ=.25 the router triggers on ~27% of queries; the product grid should always render, with the overview streaming in above it — misroutes then degrade gracefully in both directions.
  4. Retrain quarterly from clicked-overview engagement signals; the labeling pipeline is resumable and costs ~$2 per 10k queries, so refreshing gold data is essentially free.
  5. Keep the LLM out of the routing hot path. Its +1 pt accuracy costs 200× latency; the same LLM budget is better spent generating the overviews themselves.

11Reproducibility

All code is public at github.com/verma7/commerce-query-router (data and model weights gitignored, pipeline fully scripted): src/rubric.py (taxonomy), src/label.py + aggregate_labels.py (ensemble labeling, resumable), train.py / train_transformer.py / train_enriched.py (models, --lodo), gemini_classify.py (LLM baseline), evaluate.py (bootstrap metrics), predict.py (shipping Router), demo/server.py (interactive demo at localhost:8642). Raw-dataset sources and licenses: data/raw/MANIFEST.json. Splits, seeds, and all reported numbers (results/*.json) are committed. Total external cost of the study: ≈ $2 in Gemini 2.5 Flash calls.

Report generated 2026-07-23. Datasets: Amazon ESCI (Apache-2.0), Home Depot (Kaggle mirror), MS MARCO (non-commercial research terms), WANDS (MIT), TREC Product Search 2023. Labels are LLM-ensemble judgments, not human gold.