微信扫码
添加专属顾问
我要投稿
大多数现有方法仅从检索语料库中检索短的连续块,限制了对整个文档上下文的整体理解。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.git
cd raptor
pip install -r requirements.txt
# 开始使用 RAPTOR,请按照以下步骤操作:
# 首先,设置您的 OpenAI API 密钥并初始化 RAPTOR 配置:
import os
os.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)
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-09-12
Meta如何给RAG做Context Engineering,让模型上下文增加16倍
2025-09-12
检索器江湖:那些让RAG神功大成的武林绝学
2025-09-12
Dify + Oracle + MCP:轻松构建 RAG 与 MCP Agent 智能应用
2025-09-11
做好 RAG 落地最后环节 —— 评估 RAG 应用
2025-09-10
企业级RAG系统实战心得:来自10多个项目的深度总结
2025-09-10
您应该为您的 RAG 系统使用哪种分块技术?
2025-09-10
关于多模态应用的几个疑问,以及多模态应该怎么应用于RAG?
2025-09-10
MiniMax RAG 技术:从推理、记忆到多模态的演进与优化
2025-06-20
2025-06-20
2025-07-15
2025-06-24
2025-06-24
2025-07-16
2025-06-23
2025-07-09
2025-06-15
2025-06-20
2025-09-10
2025-09-10
2025-09-03
2025-08-28
2025-08-25
2025-08-20
2025-08-11
2025-08-05