链式调用,Graph RAG 风格!
现在把一切串起来,创建一个 Graph RAG 问答链!我们为您提供了与本章一直使用的相同 graph(具体节点和关系可能略有不同)。您将把它与另一个 LLM 连接,用来生成 Cypher 查询,并返回自然语言的答案。
本练习是课程的一部分
使用 LangChain 的 Retrieval Augmented Generation (RAG)
练习说明
- 使用一个 OpenAI 聊天模型和您之前创建的
graph来创建 Graph Cypher QA 链。 - 使用给定的输入调用该链。
- 从返回的
result中提取并打印结果文本。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the Graph Cypher QA chain
graph_qa_chain = ____.____(
____=ChatOpenAI(api_key="", model="gpt-4o-mini", temperature=0), ____, verbose=True
)
# Invoke the chain with the input provided
result = ____({"query": "Who discovered the element Radium?"})
# Print the result text
print(f"Final answer: {result['____']}")