儲存圖形文件
你現在在應用程式中已經有 3 個節點和 2 條關係,但目前它們只存在於記憶體中。
在這個練習中,你將連線到你的 Neo4j 執行個體(已為你啟動),並把這些節點與關係儲存到資料庫。
本練習屬於課程
使用 LangChain 與 Neo4j 的 Graph RAG
練習說明
- 使用提供的認證連線到 Neo4j 資料庫。
- 從已定義的節點(
book、jesus、jim)與關係(written_by_jesus、written_by_jim)建立一個圖形文件。 - 將該圖形文件儲存到資料庫。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Connect to the Neo4j Database
graph = ____(url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)
# Define the collection of graph documents
graph_document = ____(
____=[book, jesus, jim],
____=[written_by_jesus, written_by_jim]
)
# Save the data to your graph
graph.____([graph_document])
graph.refresh_schema()
print(graph.schema)