目的: 可以節省成本、增加 signal-to-noise ratio 訊噪比
* 作法比較文章
* https://medium.com/@SrGrace_/contextual-compression-langchain-llamaindex-7675c8d1f9eb
* https://towardsdatascience.com/how-to-cut-rag-costs-by-80-using-prompt-compression-877a07c6bedb
* [[Prompt Compression]] LLMLingua 也可以做 Contextual Compression
* 和 Cohere Re-Ranker 結合使用 https://medium.aiplanet.com/advanced-rag-cohere-re-ranker-99acc941601c
## langchain
> Normal retrieval but with an extra step of pulling out relevant information from each returned document. This makes each relevant document smaller for your final prompt (which increases information density)
>
https://python.langchain.com/docs/modules/data_connection/retrievers/contextual_compression/
## llamaindex
SentenceEmbeddingOptimizer
## [[LangChain Chat with Your Data]]
多一步 Compression LLM 來縮減內容 (縮減 chunk 內容,不是合併chunks)
壓縮並只返回與特定查詢最相關的部分檢索文檔
Blog: https://blog.langchain.dev/improving-document-retrieval-with-contextual-compression/
## 相關的反面論述
* The Power of Noise https://arxiv.org/abs/2401.14887 (2024/1)
* 這篇 paper 的實驗提出 包括不相關的文檔可能會意外地使準確性提高超過 30%,與我們最初的假設相矛盾
## RECOMP
* 在 https://arxiv.org/abs/2407.01219 這篇 paper 中推薦
* https://arxiv.org/abs/2310.04408
* https://github.com/carriex/recomp