Search Suggestions: The Generator-Discriminator Approach

Fedor Kurushin8 Aug 2025

Problem

Marketplace users often search for a product and get nothing useful, or no results at all. The platform still has to show something: a "did you mean" query after a failed search, or a suggestion based on earlier purchases. Finding a similar query is hard because one token can change the intent. "macbook pro 16 2025" and "macbook pro 14 2025" look almost identical to a text-embedding model but are not interchangeable. Often it is safer to broaden the query ("washing powder") than to guess.

Example from the article: "washing powder 9 kg" and "washing powder 20 kg" are near-identical for most models but not interchangeable for a buyer.

Solution in brief

Split the task into two models. A generator, a query embedding model, retrieves candidate queries from an index. A discriminator then classifies the relation between the original query and each candidate into one of six types (paraphrase, broadening, narrowing, attribute change, complementary, irrelevant). Each business scenario ranks these types in its own order, so one pair of models serves several products.

Questions this case answers
  • How to find, for a failed or rare query, the nearest queries in an index and label how each one relates to it when plain vector similarity cannot separate near-identical queries that mean different things
  • How to rank replacement queries by a business-specific order of relation types, where the best order differs between scenarios that share one model
  • How to suggest a useful alternative query when a user's search returns nothing or irrelevant results?
  • How to tell a paraphrase of a query from a query that differs by one decisive token, such as 16 vs 14 inches or 9 kg vs 20 kg?

Tools and methods

  • Dual-encoder query model (Q2QDENSLR) — the generator, trained on failed-query to successful-query pairs.
  • In-batch negatives, dual-margin cosine loss — generator training.
  • Three-encoder GRU discriminator — classifies the relation between two queries.
  • E5, fastText — generator baselines.
Continue reading — it's free

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