HyDE(Hypothetical Document Embeddings、Gao et al. 2022)是 RAG retrieval 階段的 query 端增強技術。核心觀察:query 跟 document 在 embedding 空間的距離往往比 document 跟 document 之間更遠——這是典型 query-document gap。HyDE 的做法是先用 LLM 對 query 生成「假設的答案文件」、對假文件做 embedding 拿去 retrieve、而不是直接 embed 原 query。

概念位置

HyDE 三步:

 1User query
 2 3[Step 1] LLM 生成 hypothetical document
 4         (可能 hallucinate、事實正確性不重要)
 5 6[Step 2] Embed 假文件
 7 8[Step 3] 用假文件 embedding 去 vector DB retrieve 真文件
 910真實 top-k chunks → 主 LLM 回答

為什麼比直接 embed query 好:假文件的 phrasing、長度、結構都更接近真文件的分佈、embedding 距離更可靠。重點是假文件當 embedding 的代理、不是當答案——hallucinate 出錯誤事實 OK、但語意 / 領域要落對。

設計責任

讀 RAG paper 或工具看到「HyDE」「hypothetical document」「query-side augmentation」就是這個機制。實作判讀:

  1. 適用 phrasing 落差顯著的場景:問句 vs 陳述、口語 vs 正式、抽象 vs 技術詞彙。HyDE 原論文跨多領域都有提升、不限技術 / 學術。
  2. 失效在假文件偏離主題:LLM hallucinate 到別領域、retrieve 拿到完全不相關的東西。緩解:生成多個假文件取平均 embedding、或用 query + 假文件兩個 embedding 合併 retrieve。
  3. Cost:每 query 多一個 LLM call(生假文件)、latency 加 500ms-1s,屬於明顯的 retrieval cost。對 latency 敏感場景考慮 query rewriting 等較輕量的替代。
  4. hybrid search 互補:HyDE 解語意 phrasing 落差、hybrid 解語意 / 字面互補、可以同時用。

完整 RAG 檢索增強技術 landscape 見 4.2 RAG 檢索增強