建立關係
《Building Knowledge Graphs》一書有兩位作者,Jesus Barrasa 和 Jim Webber。除了你已經建立的 book 節點外,我們另外建立了兩個節點 jesus 和 jim,分別代表這兩位作者。
在這個練習中,你要用迴圈走訪作者節點,為每位作者與這本書之間建立一條 WRITTEN_BY 關係。
本練習屬於課程
使用 LangChain 與 Neo4j 的 Graph RAG
練習說明
- 建立
"WRITTEN_BY"類型的關係,從book節點連到每個author節點。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from langchain_neo4j.graphs.graph_document import Relationship
relationships = []
for author in [jesus, jim]:
# Create a Relationship between book and each author
relationships.append(____(
____=book,
____=author,
____="____"
))
visualize_graph([book, jesus, jim], relationships)