チェーンの最後のリンク
第1章の text-to-cypher チェーンと、本章前半のベクトルリトリーバーを組み合わせることで、ナレッジグラフ内の情報にアクセスする複数の手段(ベクトル検索とノード・リレーションシップの両方)を備えたチェーンを作成できます。
text_to_cypher_chain と line_retriever(Neo4j のベクトルリトリーバー)変数に加えて、ハイブリッド検索用の質問応答プロンプト graphrag_qa_prompt が利用可能です。
この演習はコースの一部です
Graph RAG with LangChain and Neo4j
演習の手順
- ベクトルリトリーバー(
line_retriever)に"question"キーを渡し、ベクトル検索で関連結果を取得します。 text_to_cypher_chainが生成した Cypher 文を実行するため、graphオブジェクトから query を取り出して実行します。- 提供された入力で
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)