開始使用免費開始

把鏈串起來,Graph RAG 風格!

現在把前面所學整合起來,建立一個 Graph RAG QA chain!你已經拿到與本章練習相同的 graph(節點與關係的細節可能略有不同),接著你會把它與另一個 LLM 連接,用來產生 Cypher 查詢並回傳自然語言的回答。

本練習屬於課程

使用 LangChain 的 Retrieval Augmented Generation(RAG)

檢視課程

練習說明

  • 使用 OpenAI chat 模型與你先前建立的 graph 建立一個 Graph Cypher QA chain。
  • 以提供的輸入來叫用(invoke)此 chain。
  • 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['____']}")
編輯並執行程式碼