或叫做 Query Expansion、Query Rewriting、Query Transformation
由於用戶的原始查詢很可能不是最好的查詢字串,因此我們可以改寫再去向量資料庫搜尋
做法是將原先用戶的 Query,產生多種變形 Queries,每個再去撈出結果 (後面還需要接 [[Reranking]] 技巧將多個結果列表進行合併排序)
* Florian 的 Advanced RAG 06: Exploring Query Rewriting (2024/3/4)
* https://medium.com/@florian_algo/advanced-rag-06-exploring-query-rewriting-23997297f2d1
* RAG - Say what? https://div.beehiiv.com/p/rag-say
* [[HyDE Retriever]]
* [[Rewrite-Retrieve-Read]]
* [[Sub Question Query]]
* [[Advanced Retrieval for AI with Chroma]] 課程
* Expansion with generated answers
* https://arxiv.org/abs/2305.03653
* 這 paper 中有 prompting template 可以參考
* Expansion with multiple queries
* 跟 [[Rephrase and Respond (RaR)]] 類似的思路
https://akash-mathur.medium.com/advanced-rag-query-augmentation-for-next-level-search-using-llamaindex-d362fed7ecc3#46d4
* Query Expansion https://twitter.com/virattt/status/1759711417291190518 有個 prompt 可參考
* https://gist.github.com/virattt/9099bf1a32ff2b99383b2fabba0ae763
```
You are a helpful assistant that expands a user query into sub-queries. The sub-queries should be mutually exclusive and collectively exhaustive. Your response will be a JSON object with a `queries` field, which is a list of `query` objects.
```
* Query Rewriting (2024/5/17)
* https://generativeai.pub/advanced-rag-retrieval-strategy-query-rewriting-a1dd61815ff0
* Sub-Question Querying
* HyDE
* Step-Back Prompting
* paper: A Survey of Query Optimization in Large Language Models (2024/12)
* https://arxiv.org/abs/2412.17558
* https://ihey.cc/rag/rag-query-optimization-howto/
* Query Optimization 分成四類: Expansion、Decomposition、Disambiguation、Abstraction
## Langchain
* https://blog.langchain.dev/query-transformations/
* [[Rewrite-Retrieve-Read]]
* [[Step-Back Prompting]]
* Follow Up Questions
* Multi-Query Retrieval https://python.langchain.com/docs/modules/data_connection/retrievers/MultiQueryRetriever
* [[Multi-Query Retriever]]
* [[Reranking]]
* Query analysis
* https://python.langchain.com/docs/use_cases/query_analysis/
* Rag From Scratch: Query Transformations
* https://github.com/langchain-ai/rag-from-scratch/blob/main/rag_from_scratch_5_to_9.ipynb
* 這有 prompt 可以參考
* 官方文件 https://python.langchain.com/v0.2/docs/concepts/#retrieval
## llamaindex
* https://docs.llamaindex.ai/en/stable/optimizing/advanced_retrieval/query_transformations.html
* 單步驟
* HyDE
* Sub Question
* 多步驟
* https://towardsdatascience.com/advanced-query-transformations-to-improve-rag-11adca9b19d1
* HyDE
* Sub Questions
* Multi-Step Query Transformation (MultiStepQueryEngine)
* self-ask method
* 就是 [[Self-Ask prompting]] 思路吧
* 用 RouterQueryEngine 判斷用哪一種策略ㄔㄧㄛ