Accessing Cypher statement in final answer (GraphCypherQA)

Hi All,

I am a complete beginner in neo4j and Langchain and I am currently learning how to use neo4j with an LLM to create a chatbot. Please do let me know if this is a question more fit for the LangChain forums.

I am wondering if it is possible for the LLM to access the generated Cypher query when giving the final answer.

The premise of the chatbot is to assume a given senior role and answer an opinionated question as if they have the expertise to do so. For example: "Who do you think is best fit for this task X?", "Which of these tasks is the hardest?". There are multiple attributes that can be chosen and the LLM choses one of them to determine the final answer. However, the attribute is renamed into something else such as: SUM(u.completedTasks) AS bestPerformer, which means the context will have the attribute bestPerformer, with no information as to how that was calculated

So the LLM will answer that X is the best performer, but the LLM does not know why that is. In order to do that, the LLM will need to see that best performer was calculated from completedTasks attribute which is part of the Cypher query.

Is it possible for the LLM to see the query? or is there some other route that I should take to make the LLM be able to explain its answer (e.g. cypher_generation/qa_prompt template examples?)

Thank you for your time.

hi @senmayur03 , this is not an answer to the specifics of your question, but since you are beginning, you might be interested in the following resources about the Cypher - LangChain - chatbot subject

and I guess if you want people who use Neo4j and langChain to answer your question, you need to be more specific about what you do (RAG ? cypher generation ?...)

Hi @v2belleville, apologies for my delay in replying.

I have already taken a look and built a basic chatbot using the neo4j fundamental and chatbot courses and I wish to use them for answering user questions based on the information that is present in the neo4j database. As an example, if we have relationship between a user and a device, I would like to know what device a specific user is using (To my knowledge this is cypher generation to enable RAG?).

I am currently doing this using the GraphCypherQAChain. My current intention with the bot is to allow users to ask questions about the database in a way in which, the LLM has to decide on its own, which attribute it wants to use to answer the question. For example: If I ask "which user has the best performing device?", there are multiple attributes it can use to form an answer (CPU, RAM, etc). Then it will form it's answer and give a reason as to why ("This device has the most RAM").

The problem I am facing with this is that it renames the attribute to something which does not exist in the database itself. For example, it will use the RAM attribute to gauge performance, but it will write "AS best_performance" in the cypher query, so the context only has "best_performance" not "RAM". This means the LLM does not know which attribute was used to calculate this.

Please do let me know if what I am trying to do is something that the GraphCypherQAChain is not intended to perform. This is: Letting the LLM decide which attributes to use in answering ("Which device has the best performance?)", rather than making sure the user writes specific prompts to gain an answer ("What device has the highest RAM capacity?"). If it is capable of doing these kinds of tasks. Can you kindly direct me to resources that help with this?

Hi, I haven't sufficiently looked into the LLM - RAG etc topic to be of anymore help, but now that you have given more details about your problem and your context, someone else might be able to ;-)