-
Checked other resources
Commit to Help
Example Codefrom langchain_community.graphs import Neo4jGraph
from langchain.chains import GraphCypherQAChain
from langchain.prompts import PromptTemplate
# llm = "" # use llm of your choice
kg = Neo4jGraph(url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD, database=NEO4J_DATABASE)
prompt = PromptTemplate.from_template(
"""You are an intelligent agent. You should check the Book and Category nodes.
When question is asked on similarity then you should check for CLOSENESS in their embeddings, donot perform CRISP match.
""")
chain = GraphCypherQAChain.from_llm(llm, graph=kg, prompt=prompt, verbose=True)
chain.run("which books are similar to Learning ML?") DescriptionThe example code provided results in a bad Cypher query because the GraphCypherQAChain generates queries using either deprecated functions or functions that do not exist. An example of the error message encountered is shown below. Proposed Solution
Next Steps
CypherSyntaxError Traceback (most recent call last) System Info
platform = windows python version = 3.11.4 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello, @schatterjeecs! I'm here to help you with the issue you've encountered. Let's work together to resolve this! To resolve the issue with the
Here is an updated version of your code with a corrected prompt template: from langchain_community.graphs import Neo4jGraph
from langchain.chains import GraphCypherQAChain
from langchain.prompts import PromptTemplate
# llm = "" # use llm of your choice
kg = Neo4jGraph(url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD, database=NEO4J_DATABASE)
prompt = PromptTemplate.from_template(
"""You are an intelligent agent. You should check the Book and Category nodes.
When a question is asked about similarity, you should check for CLOSENESS in their embeddings using the GDS library functions.
Use the gds.alpha.similarity.cosine function for similarity checks.
"""
)
chain = GraphCypherQAChain.from_llm(llm, graph=kg, prompt=prompt, verbose=True)
chain.run("which books are similar to Learning ML?") This updated prompt ensures that the generated Cypher query uses the Additionally, make sure that the GDS library is installed and properly configured in your Neo4j database. You can refer to the Neo4j Graph Data Science documentation for more details on installing and using GDS functions. By following these steps, you can avoid using deprecated or non-existent functions and ensure that your Cypher queries are correctly generated and compatible with Neo4j [1][2]. |
Beta Was this translation helpful? Give feedback.
-
I have another simple questions pertaining to the above issue -
Output:
|
Beta Was this translation helpful? Give feedback.
To ensure that the
GraphCypherQAChain
generates correct and consistent Cypher queries without requiring specific function names to be passed, you can utilize thecypher_query_corrector
attribute. This attribute allows for optional Cypher validation, which can help in correcting and validating the generated Cypher queries.Here is how you can set up the
cypher_query_corrector
:Set Up Cypher Query Corrector: Use the
CypherQueryCorrector
to validate and correct the generated Cypher queries.Update the Chain Configuration: Configure the
GraphCypherQAChain
to use thecypher_query_corrector
.Here is an example of how to implement this: