开始使用免费开始使用

理解 BM25

在将 BM25 稀疏检索器集成到您的 RAG 架构之前,先在一些短字符串上测试,直观感受检索器如何选择文档会更好。

我们为您提供了 3 个字符串,您将用它们来构建 BM25 检索器。本练习所需的功能已为您加载完成。

本练习是课程的一部分

使用 LangChain 的 Retrieval Augmented Generation (RAG)

查看课程

练习说明

  • 从文档初始化 BM25 检索器,并将其配置为每次检索「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(____)
编辑并运行代码