大多数现有方法仅从检索语料库中检索短的连续块,限制了对整个文档上下文的整体理解。RAPTOR(Recursive Abstractive Processing for Tree-Organized Retrieval)引入了一种新方法,即递归嵌入、聚类和总结文本块,从下往上构建具有不同总结级别的树。在推理时,RAPTOR 模型从这棵树中检索,整合不同抽象级别的长文档中的信息。RAPTOR(Recursive Abstractive Processing for Tree-Organized Retrieval)比传统的检索增强型 LM 性能与绝对准确度上提高 20%。
# 安装,在使用 RAPTOR 之前,请确保已安装 Python 3.8+。克隆 RAPTOR 存储库并安装必要的依赖项:git clone https://github.com/parthsarthi03/raptor.gitcd raptorpip install -r requirements.txt# 开始使用 RAPTOR,请按照以下步骤操作:# 首先,设置您的 OpenAI API 密钥并初始化 RAPTOR 配置:import osos.environ["OPENAI_API_KEY"] = "your-openai-api-key"from raptor import RetrievalAugmentation# Initialize with default configuration. For advanced configurations, check the documentation. [WIP]RA = RetrievalAugmentation()# 将您的文本文档添加到 RAPTOR 进行索引:with open('sample.txt', 'r') as file:text = file.read()RA.add_documents(text)# 现在可以使用 RAPTOR 根据索引文档回答问题:question = "How did Cinderella reach her happy ending?"answer = RA.answer_question(question=question)print("Answer: ", answer)# 将构造好的树保存到指定路径:SAVE_PATH = "demo/cinderella"RA.save(SAVE_PATH)# 将保存的树重新加载到 RAPTOR 中:RA = RetrievalAugmentation(tree=SAVE_PATH)answer = RA.answer_question(question=question)
| 欢迎光临 链载Ai (http://www.lianzai.com/) | Powered by Discuz! X3.5 |