链中的最后一环
结合第 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)