ลิงก์สุดท้ายในเชน
เมื่อมี text-to-cypher chain จากบทที่ 1 และ vector retriever จากแบบฝึกหัดก่อนหน้าในบทนี้แล้ว ตอนนี้มีส่วนประกอบครบพร้อมสร้าง chain ที่เปิดให้เข้าถึงข้อมูลใน knowledge graph ได้หลายวิธี—ทั้งผ่าน vector และผ่าน node และ relationship
ตัวแปร text_to_cypher_chain และ line_retriever (Neo4j vector retriever) พร้อมใช้งานแล้ว รวมถึง prompt สำหรับการตอบคำถามแบบ hybrid retrieval อย่าง graphrag_qa_prompt
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Graph RAG ด้วย LangChain และ Neo4j
คำแนะนำการฝึกหัด
- ส่ง key
"question"ให้กับ vector retriever (line_retriever) เพื่อดึงผลลัพธ์ที่เกี่ยวข้องโดยใช้ vector search - ดึง query จาก object
graphเพื่อรัน Cypher statement ที่text_to_cypher_chainสร้างขึ้น - รัน
graphrag_qa_chainบน input ที่กำหนดให้
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
graphrag_qa_chain = RunnablePassthrough.assign(
# Pass the "question" key to the retriever
vectors = RunnableLambda(lambda x: line_retriever.invoke(____)),
# Execute the generated Cypher statement
records = text_to_cypher_chain | graph.____
) | graphrag_qa_prompt | llm | StrOutputParser()
# Execute the hybrid chain
output = graphrag_qa_chain.____({"question": "Does Sampson bite his thumb at Gregory?"})
print(output)