BM25の仕組みを理解する
BM25の疎検索ツールをRAGアーキテクチャに統合する前に、短い文字列でテストして、リトリーバーがどのようにドキュメントを選択するかを把握しておきましょう。
ここにBM25リトリーバーの基盤として使用する3つのテキストがあります。この演習に必要な機能はすでに読み込まれています。
この演習はコースの一部です
LangChainで学ぶ検索拡張生成(RAG)
演習の手順
- ドキュメントからBM25 retrieverを初期化し、「3件」のドキュメントを一度に取得するよう設定してください。
- 提示されたクエリでリトリーバーを実行してください。
- 最初の結果のページコンテンツを出力してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
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(____)