Enhancing Search Retrieval with Large Language Models (LLMs)

Maarten Sukel24 Apr 2024

Problem

Picnic, an online grocer in the Netherlands, Germany and France, fits tens of thousands of products and many recipes into a phone app. Customers search with millions of different terms, including typos ("jogurt"), random extra letters and intent phrases such as a birthday party. The same word must work across languages: a Dutch customer typing "fromage" should find French cheeses. Results must appear as the user types, while an LLM call takes seconds. Weak retrieval means customers do not find products the shop sells.

Example from the article: a customer searching for "ice" should learn that Picnic sells ice-making utilities, not blocks of ice.

Solution in brief

An LLM turns each search term into a description of matching products or recipes, and that description is embedded and compared with embeddings of the catalog. Picnic computes this offline for the search terms customers have used before and stores the vectors in OpenSearch. At query time the engine does only a vector lookup.

Questions this case answers
  • How to add semantic retrieval from a large language model to a search system that must answer within milliseconds on every keystroke
  • How to make retrieval robust to typos, multiple languages and intent-style queries when the catalog mixes several entity types
  • How to add LLM-based semantic retrieval to product search without making as-you-type results slow?
  • How to match short, misspelled or intent-driven queries to a catalog that mixes products and recipes?

Tools and methods

  • GPT-3.5-turbo — writes the product description for a search term (chosen because it performed as well as the slower GPT-4-Turbo)
  • text-embedding-3-small (OpenAI Embeddings) — embeds the generated descriptions
  • OpenSearch — holds two indexes and serves precomputed vectors with low latency
  • Streamlit — internal app for trying models and prompts
  • Dense retrieval by vector search — nearest-neighbor lookup of description embeddings against catalog embeddings
Continue reading — it's free

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