导入模块
学习如何在代码中直接导入模块以使用 NodeRAG。
less than a minute
导入模块
通过最简单的设置快速构建搜索引擎:
from NodeRAG import NodeConfig, NodeSearch
# 从主文件夹加载配置
config = NodeConfig.from_main_folder(r"C:\Users\Terry_Xu\Desktop\HP")
# 初始化搜索引擎
search = NodeSearch(config)
回答问题
# 查询系统
ans = search.answer('who is harry potter?')
# 'ans' 是一个包含多个可访问属性的对象:
# response:对您问题的生成答案
print(ans.response)
# 答案中的 token 数量
print(ans.response_tokens)
# 检索信息:用于生成答案的上下文
print(ans.retrieval_info)
# 检索上下文中的 token 数量
print(ans.retrieval_tokens)
注意事项
search.answer()
返回一个对象,该对象同时包含答案和检索上下文,以及有用的元数据。- 这种方法非常适合快速集成到 Python 脚本或 Jupyter notebook 中,无需设置 API 服务器。
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.