การบันทึก graph documents
ตอนนี้มี nodes สามตัวและ relationships สองตัวในแอปพลิเคชันแล้ว แต่ยังคงอยู่ในหน่วยความจำเท่านั้น
ในแบบฝึกหัดนี้ คุณจะเชื่อมต่อกับ Neo4j instance (ที่เตรียมไว้ให้แล้ว) และบันทึก nodes กับ relationships ลงในฐานข้อมูล
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Graph RAG ด้วย LangChain และ Neo4j
คำแนะนำการฝึกหัด
- เชื่อมต่อกับฐานข้อมูล Neo4j โดยใช้ข้อมูล credentials ที่กำหนดให้
- สร้าง graph document จาก nodes (
book,jesus,jim) และ relationships (written_by_jesus,written_by_jim) ที่กำหนดไว้ - บันทึก graph document ลงในฐานข้อมูล
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# 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)