Scaling Search Query Understanding with LLMs: From POC to Production

yelp · Tech · 2025 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: local search query understanding

Yelp needed to use LLMs for search-query understanding tasks such as segmentation, spell correction, canonicalization, and review-highlight generation without paying GPT-4 latency and cost on every search.

Constraints:

Architecture

Yelp prototyped query-understanding prompts with high-end LLMs, enriched prompts with business names or categories when useful, generated golden datasets from representative queries, fine-tuned smaller models such as GPT-4o-mini for offline precomputation, stored cached query-understanding signals in datastores, and used BERT/T5-style models for realtime long-tail query handling.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  A["User search query"] --> B["LLM prototyping workflow"]
  B --> C["RAG enrichment layer"]
  C --> D["Golden dataset builder"]
  B --> D
  D --> E["Fine-tuned GPT-4o-mini batch model"]
  E --> F["Query understanding datastore"]
  F --> G["Search ranking and review highlighting systems"]
  H["BERT/T5 realtime tail model"] --> G
  I["Offline and A/B evaluation"] --> B
  I --> D
  G --> I
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
User search query The raw query text and associated behavioral context that needs interpretation. LLM prototyping workflow
LLM prototyping workflow Uses GPT-4/o1-class prompts to scope tasks, test output formats, and generate candidate labels. User search query, RAG enrichment layer, Golden dataset builder, Offline and A/B evaluation
RAG enrichment layer Adds viewed business names or predicted business categories to ambiguous raw queries. LLM prototyping workflow, Golden dataset builder
Golden dataset builder Turns representative high-end LLM outputs into quality-checked fine-tuning data. LLM prototyping workflow, RAG enrichment layer, Fine-tuned GPT-4o-mini batch model, Offline and A/B evaluation
Fine-tuned GPT-4o-mini batch model Runs offline at large scale for head queries and cached query-understanding signals. Golden dataset builder, Query understanding datastore
BERT/T5 realtime tail model Serves less expensive realtime query-understanding for long-tail queries. Search ranking and review highlighting systems
Query understanding datastore Stores precomputed segmentation, expansion, and highlight signals for low-latency retrieval. Fine-tuned GPT-4o-mini batch model, Search ranking and review highlighting systems
Search ranking and review highlighting systems Consume query-understanding signals to improve matching, ranking, implicit location rewrite, and review highlights. Query understanding datastore, BERT/T5 realtime tail model, Offline and A/B evaluation
Offline and A/B evaluation Compares LLM outputs to labeled datasets and online user metrics before wider rollout. LLM prototyping workflow, Golden dataset builder, Search ranking and review highlighting systems

Data flow

A user query enters the query-understanding workflow; the team prototypes the task with a powerful GPT-4/o1-class prompt, optionally enriches the input with viewed business names or category predictions, uses high-end model outputs to create a golden dataset, fine-tunes a smaller model for batch precomputation on head queries, uploads quality-checked outputs into query-understanding datastores, and feeds downstream search ranking, segmentation, spell correction, and review-highlight systems.

3 supporting quotes
“In this step, our initial goals are to: (1) determine if an LLM is the appropriate tool for the problem, (2) define the ideal scope and output format for the task”article, stated
“On the RAG side, we augment the input query text with the names of businesses that have been viewed for that query.”article, stated
“The generated outputs were quality checked and uploaded to our query understanding datastores.”article, stated

Why this architecture

Yelp chose a staged architecture because powerful LLMs were useful for task discovery and label generation, while production search needed cached or smaller-model paths to control cost and latency across millions of queries.

3 supporting quotes
“query understanding was the pioneering project and has become the most refined, laying the groundwork for Yelp’s innovative use of LLMs to improve user search experiences.”article, stated
“the query distribution follows the power law - a small number of queries are very popular.”article, stated
“Because fine-tuned query understanding models only require very short inputs and outputs, we have seen up to a 100x savings in cost”article, stated

Models used: GPT-4 · o1 · o1-mini · o1-preview · GPT-4o-mini · BERT · T5

Scale

Alternatives considered (roads not taken)

Run complex GPT-4 prompts directly in production search

Rejected because: Yelp moved to fine-tuned smaller models because direct complex prompting was too costly for production scale.

“Because fine-tuned query understanding models only require very short inputs and outputs, we have seen up to a 100x savings in cost”article, stated

Apply LLMs to every query before proving value

Rejected because: The team first scoped whether an LLM fit the problem, then used proof-of-concept and online experiments before scaling.

“By caching (pre-computing) high-end LLM responses for only head queries above a certain frequency threshold, we can effectively cover a substantial portion of the traffic and run a quick experiment”article, stated

Use only offline subjective judgment for review highlights

Rejected because: Subjective offline evaluation was insufficient, so Yelp cross-checked humans, quantitative methods, and online A/B tests.

“Offline evaluation of the quality of generated phrases is subjective and requires very strong human annotators with good product, qualitative, and engineering understanding.”article, stated

Treat spell correction and segmentation as fully separate prompts

Rejected because: Yelp found a sufficiently powerful model could handle them together and added a meta tag for spell-corrected sections.

“spell-correction and segmentation can be done together by a sufficiently powerful model, so we added a meta tag to mark spell corrected sections”article, stated

Patterns

rag-retrieval (retrieval)

Yelp enriched raw queries with business names or categories so the model could disambiguate names, topics, misspellings, and review-highlight phrases.

“On the RAG side, we augment the input query text with the names of businesses that have been viewed for that query.”article, stated
“On the RAG side, we enhanced the input raw query text with the most relevant business categories with respect to that query (from our in-house predictive model).”article, stated

semantic-caching (serving)

The production strategy cached precomputed LLM outputs for frequent head queries and stored them in query-understanding datastores.

“By caching (pre-computing) high-end LLM responses for only head queries above a certain frequency threshold, we can effectively cover a substantial portion of the traffic”article, stated
“Cache-based systems such as key/value DBs were used to improve retrieval latency due to the power law distribution of search queries.”article, stated

fine-tuning-adaptation (model-adaptation)

High-end model outputs became a golden dataset for fine-tuning smaller models that could run cheaply at Yelp's traffic scale.

“We ran the GPT-4 prompt on a representative sample of input queries. The sample size should be large (but not unmanageably so, since quality > quantity)”article, stated
“Fine tune a smaller model (GPT4o-mini) that we can run offline at the scale of tens of millions, and utilize this as a pre-computed cache to support that vast bulk of all traffic.”article, stated

eval-driven-development (evaluation)

Yelp used human-labeled offline datasets, specialized review by strong annotators, online A/B tests, and query-level metrics to decide what to teach or scale.

“We compared the accuracy of LLM provided segmentation with the status quo system on human labeled datasets of name match and location intent.”article, stated
“One approach we used to narrow down our search for problematic responses was tracking the query level metrics to find those queries that have nontrivial traffic and that their metric is obviously worse than status-quo.”article, stated

batch-offline-processing (serving)

Yelp shifted the expensive LLM work into offline batch precomputation for common queries and kept realtime serving for the tail.

“After fine-tuning our model and validating the responses on a diverse and random test set, we scaled to 95% of traffic by pre-computing snippet expansions for those queries using OpenAI’s batch calls. The generated outputs were quality checked and uploaded to our query understanding datastores.”article, stated
“Specifically, at Yelp, we have used BERT and T5 to serve as our real time LLM model. These models are optimized for speed and efficiency, allowing us to process user queries rapidly and accurately during the complete rollout phase.”article, stated

Tradeoffs

Use head-query precomputation before broader realtime rollout.

Chose cached high-end LLM responses for frequent queries over directly serving high-end LLMs for all queries.

Rationale: Power-law traffic made head-query caching a low-latency, lower-cost way to prove value over a large traffic share.

“By caching (pre-computing) high-end LLM responses for only head queries above a certain frequency threshold, we can effectively cover a substantial portion of the traffic”article, stated

Fine-tune smaller models for production scale.

Chose fine-tuned GPT-4o-mini and optional BERT/T5 tail models over keeping the complex GPT-4 prompt as the production path.

Rationale: The production tasks used short inputs/outputs, making smaller models cheaper and fast enough for search serving.

“Because fine-tuned query understanding models only require very short inputs and outputs, we have seen up to a 100x savings in cost”article, stated
“These models are optimized for speed and efficiency, allowing us to process user queries rapidly and accurately during the complete rollout phase.”article, stated

Combine spell correction and segmentation in one prompt.

Chose a joint prompt with a meta tag for corrected sections over separate spell-correction and segmentation passes.

Rationale: The tasks were conceptually related and a sufficiently powerful model could handle both.

“spell-correction and segmentation can be done together by a sufficiently powerful model, so we added a meta tag to mark spell corrected sections”article, stated

Gotchas (what bit them)

Subjective review-highlight quality was hard to validate offline.

Root cause: Generated phrases needed product and qualitative judgment, not just lexical or automatic checks.

Resolution: Yelp cross-checked human annotators, used quantitative phrase-commonness checks, and then ran online A/B experiments.

“Offline evaluation of the quality of generated phrases is subjective and requires very strong human annotators with good product, qualitative, and engineering understanding.”article, stated
“We cross-checked the opinion of human annotators as well as performed some quantitative methods for snippets like looking at how common the phrases are.”article, stated

Scaling LLM query understanding to the long tail faced cost and infrastructure pressure.

Root cause: A power-law query distribution means marginal traffic coverage can require disproportionately high investment.

Resolution: Yelp precomputed head-query signals, fine-tuned smaller models, and used faster realtime models for long-tail coverage.

“scaling to millions of queries (or to a real-time model, in order to support never-before-seen queries) poses cost and infra challenges.”article, stated
“scaling up to millions of queries may require a disproportionately high investment to achieve only a marginal increase in traffic coverage.”article, stated

Fine-tuning data quality could be worse than the expensive model's raw output.

Root cause: Representative GPT-4 samples can still contain mislabeled subsets that would propagate into the smaller production model.

Resolution: Yelp isolated likely mislabeled inputs and targeted them for human relabeling or removal before fine-tuning.

“Improve the quality of the dataset if possible, prior to using it for fine tuning. With hard work here, it can be possible (for many tasks) to improve upon GPT-4’s raw output. Try to isolate sets of inputs that are likely to have been mislabeled and target these for human re-labeling or removal.”article, stated
“Try to isolate sets of inputs that are likely to have been mislabeled and target these for human re-labeling or removal.”article, stated

Evaluation

Yelp evaluated query-understanding outputs with human-labeled datasets, downstream search metrics, specialized human review, query-level metrics, and online A/B experiments.

Metrics: accuracy against human-labeled name-match and location-intent datasets · Session / Search CTR · query-level metric regressions versus status quo · traffic coverage for precomputed snippets

3 supporting quotes
“We compared the accuracy of LLM provided segmentation with the status quo system on human labeled datasets of name match and location intent.”article, stated
“By highlighting the relevant phrase to the user’s query, we increased Session / Search CTR across our platforms.”article, stated
“After fine-tuning our model and validating the responses on a diverse and random test set, we scaled to 95% of traffic”article, stated

Outcomes

The deployment exploited the power-law query distribution: head-query batch computation covered most traffic, while realtime smaller models handled the remaining long tail.

3 supporting quotes
“After fine-tuning our model and validating the responses on a diverse and random test set, we scaled to 95% of traffic by pre-computing snippet expansions for those queries using OpenAI’s batch calls. The generated outputs were quality checked and uploaded to our query understanding datastores.”article, stated
“Because fine-tuned query understanding models only require very short inputs and outputs, we have seen up to a 100x savings in cost, compared to using a complex GPT-4 prompt directly.”article, stated
“By highlighting the relevant phrase to the user’s query, we increased Session / Search CTR across our platforms.”article, stated