开始使用免费开始使用

验证 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']}")
编辑并运行代码