체인의 마지막 고리
1장에 나온 text-to-cypher 체인과 이번 장에서 만든 벡터 리트리버를 합치면, 지식 그래프의 정보를 벡터와 노드/관계 두 가지 방식으로 조회하는 체인을 만들 수 있어요.
text_to_cypher_chain과 line_retriever(Neo4j 벡터 리트리버) 변수가 준비되어 있으며, 하이브리드 검색을 위한 질문-응답 프롬프트 graphrag_qa_prompt도 함께 사용할 수 있어요.
이 연습은 강의의 일부입니다
LangChain과 Neo4j로 배우는 Graph RAG
연습 안내
- 벡터 검색을 사용해 관련 결과를 얻을 수 있도록, 벡터 리트리버(
line_retriever)에"question"키를 전달하세요. text_to_cypher_chain이 생성한 Cypher 구문을 실행할 수 있도록,graph객체의 쿼리를 추출하세요.- 제공된 입력으로
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)