Text-to-Cypher 검색 체인
이제 자연어를 Cypher 구문으로 변환할 수 있는 체인이 준비되었어요. 이를 더 큰 체인에 연결해, LLM이 생성한 Cypher를 실행하고 검색된 정보를 바탕으로 사용자 질문에 답해 봅시다.
이 연습은 강의의 일부입니다
LangChain과 Neo4j로 배우는 Graph RAG
연습 안내
text_to_cypher_chain이 생성한 Cypher 구문을 실행하도록 코드를 수정하고, 그 결과를QA_PROMPT에서 사용하는"context"변수에 할당하세요.- 입력값은 변경 없이
"question"변수로 그대로 전달하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
qa_prompt = ChatPromptTemplate.from_messages([
SystemMessagePromptTemplate.from_template(QA_PROMPT),
HumanMessagePromptTemplate.from_template("Question: {question}")
])
qa_chain = {
# Use output of text_to_cypher to get database results
"context": text_to_cypher_chain | ____(lambda cypher: graph.____(cypher)),
# Pass the user input through to the "question" variable
"question": ____
} | qa_prompt | llm | StrOutputParser()
res = qa_chain.invoke({"question": "What companies is Harrison Chase connected to?"})
print(res)