passdrill
AI & LLM Engineering · RAG & Embeddings · Card 011/012 hard

A user asks a RAG-based support bot 'my payment keeps bouncing,' but the underlying documents describe the same problem using the phrase 'transaction declined by issuing bank.' A dense-embedding search using the literal query text sometimes misses these documents because of this vocabulary mismatch. A technique called HyDE (Hypothetical Document Embeddings) was designed to address exactly this kind of mismatch. How does it work?

  1. It expands the query by appending every synonym of each query word found in a static thesaurus, then searches using the combined, longer query text
  2. It retrains the embedding model on the specific vocabulary of the document collection immediately before each individual query is issued
  3. It prompts a language model to generate a hypothetical answer to the query first, then embeds that generated hypothetical answer, rather than the original query, and uses that embedding to search the index, on the theory that a plausible answer is likely to use vocabulary closer to the real documents than the short original query does
  4. It translates the query into several other languages and searches the index once per language before merging all of the results together
Next card → Shuffle