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)