การรัน Cypher Statement
กราฟที่ให้มานี้ถูกเติมข้อมูลด้วย node ของบุคคลและบริษัท schema ของกราฟแสดงให้เห็นว่ามี node ประเภท Person และ Company และมีความสัมพันธ์ชื่อ WORKS_FOR เชื่อมระหว่าง node ทั้งสองประเภท
มีการเตรียม Cypher statement ไว้ให้แล้วในตัวแปร cypher โดย statement นี้จะค้นหา node (:Person) ที่มี property ชื่อตรงกับพารามิเตอร์ $name และคืนค่า property ชื่อบริษัทที่บุคคลนั้นทำงานอยู่
รัน Cypher statement นี้บน graph เพื่อค้นหาว่า Jo Cornelissen ทำงานที่ไหน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Graph RAG ด้วย LangChain และ Neo4j
คำแนะนำการฝึกหัด
- รัน Cypher statement ที่เก็บอยู่ในตัวแปร
cypherบนgraph - ดึงค่า
'company'จากผลลัพธ์แต่ละรายการเพื่อคืนค่าบริษัทที่ตรงกัน
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
cypher = """MATCH (p:Person {name: $name})-[:WORKS_FOR]->(c:Company)
RETURN c.name AS company"""
# Execute the Cypher statement
result = graph.____(____, {"name": "Jo Cornelissen"})
# Extract the company
for row in result:
print(row[____])