验证 Cypher 查询
当 LLM 生成 Cypher 查询时,会提供图的模式(schema)供参考;不过,这并不意味着查询一定完全符合该模式。为提升可靠性,您可以基于模式对生成的查询进行验证并修复,尤其适合纠正关系方向错误等问题。
本练习是课程的一部分
使用 LangChain 的 Retrieval Augmented Generation (RAG)
练习说明
- 创建一个针对
graph数据库进行查询的图问答链,并包含对生成的 Cypher 查询的额外校验;llm已为您定义,且应设置verbose=True。 - 使用提供的输入调用
graph_qa_chain。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create the graph QA chain, validating the generated Cypher query
graph_qa_chain = ____
# Invoke the chain with the input provided
result = ____({"query": "Who won the Nobel Prize In Physics?"})
print(f"Final answer: {result['result']}")