Problem
A grocery search page returns products that match the query, but users also want ideas: a complement to what they found, or a substitute when the store has no exact match. The "Related Items" section did this poorly, pulling products from the same department or matching broader keywords. A search for "croissant" with no exact match returned cookies, and "vegan burger" found a good match but suggested nothing that pairs with it. The team needed discovery content that adds products the engine would not retrieve.
Example from the article: for the query "swordfish" with no direct matches, the page shows a substitute carousel with tilapia, salmon and mahi-mahi.
Solution in brief
An LLM writes substitute, complementary and theme lists with titles offline for each historical query. Each list item goes through the existing search engine to get real catalog products, stored by query. The prompt is enriched with query annotations, categories users bought for that query, and the terms searched next in the same sessions.
Questions this case answers
- How to add inspirational and substitute content next to precise search results when the retrieval engine can only return items matching the query
- How to ground LLM-generated recommendations in a domain's own behavior data so that generic world knowledge does not mislead them
- How to add discovery content to a search results page when the engine only returns direct matches?
- How to suggest substitutes for queries with no or few exact matches?
Tools and methods
- Few-shot prompt with JSON output — three lists of five items per query.
- Query annotations and purchased categories — domain context in the prompt.
- Next-converted search terms — frequent follow-up searches grouped into bundles by the LLM.
- Offline batch pipeline — responses mapped to products, refreshed daily.
- Diversity-based reranking — removes duplicates and irrelevant products.
- LLM as a judge — scores the generated content.
Google or a one-time email code. No password.