RecSys & Search

Query Understanding & Expansion

Parsing user search queries via intent classification, entity extraction, and query rewriting.

🟡 intermediate5 min readretrieval
Query Understanding processes short, ambiguous user search inputs before executing database retrieval. Raw user queries suffer from typos, acronyms, short token lengths, and vocabulary mismatch. Pipelines execute Query Spelling Correction, Intent Classification, Named Entity Recognition (NER), Synonym Expansion, and Query Rewriting to maximize downstream retrieval recall.

What is Query Understanding?

In web search and e-commerce, user search queries are notoriously difficult to process:

Query Understanding is the pre-retrieval pipeline that converts noisy raw text into structured search intent:

  Raw Noisy User Query: "red nke running shos size 10"
                            │
                            ▼
  [ QUERY UNDERSTANDING PIPELINE ]
  1. Spelling Correction:  "red nike running shoes size 10"
  2. Intent Classification: Category = Footwear / Shopping
  3. Slot Tagging (NER):   Brand=Nike, Color=Red, Style=Running, Size=10
  4. Query Expansion:      Synonyms += ["sneakers", "athletic footwear"]
                            │
                            ▼
  Structured Filter Query ──► [ SEARCH RETRIEVAL ENGINE ]

The 4 Stages of Query Understanding

┌──────────────────────────┬──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. SPELLING CORRECTION   │ 2. INTENT CLASSIFICATION │ 3. SLOT FILLING (NER)    │ 4. QUERY EXPANSION       │
├──────────────────────────┼──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Corrects typos using     │ Predicts global user goal│ Extracts structured      │ Adds synonyms and LLM    │
│ Levenshtein distance or  │ (Transactional,          │ attributes (Brand,       │ rewrites to eliminate    │
│ masked Transformer models│ Informational, Nav).     │ Product, Color, Size).   │ vocabulary mismatch.     │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

Stage 1: Spelling Correction & Normalization

Uses character-level Levenshtein edit distance, SymSpell, or BERT Masked LM ("nke" $\to$ "Nike").

Stage 2: Intent Classification

Classifies the global search goal using a fast text classifier:

Stage 3: Named Entity Recognition (NER) / Slot Filling

Parses raw query tokens into structured key-value filters:

Input Query:  "blue Samsung 4k television under $500"
Named Entities:
- Brand:     Samsung
- Color:     Blue
- Resolution: 4k
- Category:  Television
- Max_Price: 500

Structured slots are passed directly to SQL or ElasticSearch structured filters (WHERE brand='Samsung' AND price <= 500).

Stage 4: Query Expansion & LLM Rewriting

To fix Vocabulary Mismatch:

Say this out loud

Query Understanding transforms noisy raw user queries into structured search intent. It uses spelling correction for typos, intent classification for user goals, Named Entity Recognition for structured slot filling, and query expansion or LLM rewriting to bridge vocabulary mismatch gaps before database retrieval.

Followups to expect

  1. What is PRF (Pseudo Relevance Feedback) in Query Expansion? Running an initial search query, extracting top 5 retrieved documents, selecting high TF-IDF terms from those documents, and appending them to expand the original search query.
  2. What is Query Relaxation? If a structured query with 5 slot filters (Brand=Nike AND Color=Red AND Size=14 AND Style=Tennis) returns 0 search results, Query Relaxation systematically drops strict filters to return close matches.

Check yourself

Question 1 of 3

What primary search retrieval problem does Query Expansion solve?

More in RecSys & Search

See all →
Collaborative Filtering5 minThe Cold Start Problem4 minTwo-Stage: Retrieval then Ranking5 min