DAG classification: how we taught search to determine the right category step by step

12 Dec 2025

Problem

Magnit Market, a marketplace, routes some search queries around the standard retrieval pipeline. If a query is mapped to a product category (a "catpred"), search either goes straight to that category or runs normally but is filtered to it. This raises relevance and cuts response time, and suits high-revenue, high-conversion queries. The catpred table was maintained manually by content moderators, which was slow, prone to human error, and catpreds appeared after complaints, not before. The team wanted wider coverage, created automatically before complaints arrive.

Example from the article: for "iphone 16 pro", a catpred to "Electronics/Smartphones and accessories/Smartphones" makes search run among smartphones only.

Solution in brief

Instead of one classifier over about 3500 categories, the team trained five gradient-boosting models, one per level of the category tree. Each model receives the query embedding plus the prediction from the previous level, and the chain stops as soon as a level is not confident enough. Heuristics corrected a gender bias, and an experiment showed a statistically significant rise in monetary metrics.

Questions this case answers
  • How to classify short text into a deep hierarchy with thousands of leaf classes when a single flat classifier is too hard and predictions must stay high-precision
  • How to replace a manually maintained query-to-category rule table with a model without losing control over business-critical queries
  • How to map a free-text search query to a node of a deep product category tree automatically instead of by hand?
  • How to classify into thousands of hierarchical classes when one flat classifier is too hard?

Tools and methods

  • Query embedding — in-house vector search model; its embeddings are the features
  • Gradient boosting (CatBoost in the article's diagram) — one classifier per category level
  • Confidence thresholds — decide per level whether to continue or stop
  • Rule-based heuristics — keyword roots that fix gender bias
  • Apache Airflow — DAG for automatic inference on new queries
Continue reading — it's free

Google or a one-time email code. No password.