ComeçarComece de graça

The final link in the chain

With the text-to-cypher chain from Chapter 1 and the vector retriever from earlier in this Chapter, you now have the components to create a chain that provides multiple ways—both vectors and nodes and relationships—to access the information in your knowledge graph.

The text_to_cypher_chain and line_retriever (the Neo4j vector retriever) variables are available for you to use, along with a question-answering prompt for hybrid retrieval, graphrag_qa_prompt.

Este exercício faz parte do curso

Graph RAG with LangChain and Neo4j

Ver curso

Instruções do exercício

  • Pass the "question" key to the vector retriever (line_retriever) to get relevant results using vector search.
  • Extract the query from the graph object to execute the Cypher statement generated by the text_to_cypher_chain.
  • Execute graphrag_qa_chain on the input provided.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

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)
Editar e executar o código