開始使用免費開始

驗證 Cypher 查詢

當 LLM 產生 Cypher 查詢時,會有圖形結構描述(schema)可供參考;然而,這並不代表查詢一定完全符合該結構。為了提升可靠度,你可以根據結構描述來驗證並修正產生的查詢,這特別適合用來修正關係方向設定錯誤的情況。

本練習屬於課程

使用 LangChain 的 Retrieval Augmented Generation(RAG)

檢視課程

練習說明

  • 建立一個查詢 graph 資料庫的圖形 QA chain,並加入額外的檢查來驗證產生的 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']}")
編輯並執行程式碼