認識 BM25
在把 BM25 稀疏檢索器整合進你的 RAG 架構之前,先用幾個短字串試試看,幫助你直觀理解檢索器如何挑選文件。
已經為你準備了三個字串,會作為建立 BM25 檢索器的基礎。本練習所需的功能都已經替你載入。
本練習屬於課程
使用 LangChain 的 Retrieval Augmented Generation(RAG)
練習說明
- 以文件初始化 BM25 檢索器,並設定一次檢索「三個」文件。
- 以提供的查詢執行檢索器。
- 列印第一個結果的頁面內容。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
chunks = [
"RAG stands for Retrieval Augmented Generation.",
"Graph Retrieval Augmented Generation uses graphs to store and utilize relationships between documents in the retrieval process.",
"There are different types of RAG architectures; for example, Graph RAG."
]
# Initialize the BM25 retriever
bm25_retriever = ____.from_texts(____)
# Invoke the retriever
results = bm25_retriever.____("Graph RAG")
# Extract the page content from the first result
print("Most Relevant Document:")
print(____)