串鏈中的最後一環
結合第 1 章的 text-to-cypher 鏈與本章前面建立的向量擷取器,現在你已經具備打造一條能以多種方式——同時透過向量,以及節點與關係——存取知識圖譜資訊的鏈。
text_to_cypher_chain 與 line_retriever(Neo4j 的向量擷取器)兩個變數已可使用,並附有混合式擷取的問答提示 graphrag_qa_prompt。
本練習屬於課程
使用 LangChain 與 Neo4j 的 Graph RAG
練習說明
- 將
"question"鍵傳給向量擷取器(line_retriever),以向量搜尋取得相關結果。 - 從
graph物件擷取查詢,以執行由text_to_cypher_chain產生的 Cypher 陳述式。 - 針對提供的輸入執行
graphrag_qa_chain。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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)