You can run a local docker container by running the executing the following script:docker run \    --name neo4j \    -p 7474:7474 -p 7687:7687 \    -d \    -e NEO4J_AUTH=neo4j/pleaseletmein \    -e NEO4J_PLUGINS=\[\"apoc\"\]  \    neo4j:latestIf you are using the docker container, you need to wait a couple of second for the database to start.from langchain.chat_models import ChatOpenAIfrom langchain.chains import GraphCypherQAChainfrom langchain.graphs import Neo4jGraphgraph = Neo4jGraph(    url="bolt://localhost:7687", username="neo4j", password="pleaseletmein")    /home/tomaz/neo4j/langchain/libs/langchain/langchain/graphs/neo4j_graph.py:52: ExperimentalWarning: The configuration may change in the future.      self._driver.verify_connectivity()Seeding the database‚ÄãAssuming your database is empty, you can populate it using Cypher query language. The following Cypher statement is idempotent, which means the database information will be the same if you run it one or multiple times.graph.query(    """MERGE (m:Movie {name:"Top Gun"})WITH mUNWIND ["Tom Cruise", "Val Kilmer", "Anthony Edwards", "Meg Ryan"] AS actorMERGE (a:Actor {name:actor})MERGE (a)-[:ACTED_IN]->(m)""")    []Refresh graph schema information‚ÄãIf the schema of database changes, you can refresh the schema information needed to generate Cypher statements.graph.refresh_schema()print(graph.schema)                Node properties are the following:            [{'properties': [{'property': 'name', 'type': 'STRING'}], 'labels': 'Movie'}, {'properties': [{'property': 'name', 'type': 'STRING'}], 'labels': 'Actor'}]            Relationship properties are the following:            []            The relationships are the following:            ['(:Actor)-[:ACTED_IN]->(:Movie)']            Querying the graph‚ÄãWe can now use the graph cypher QA chain to ask question of the graphchain = GraphCypherQAChain.from_llm(    ChatOpenAI(temperature=0), graph=graph, verbose=True)chain.run("Who played in Top Gun?")
This notebook shows how to use LLMs to provide a natural language interface to a graph database you can query with the Cypher query language.
This notebook shows how to use LLMs to provide a natural language interface to a graph database you can query with the Cypher query language. ->: You can run a local docker container by running the executing the following script:docker run \    --name neo4j \    -p 7474:7474 -p 7687:7687 \    -d \    -e NEO4J_AUTH=neo4j/pleaseletmein \    -e NEO4J_PLUGINS=\[\"apoc\"\]  \    neo4j:latestIf you are using the docker container, you need to wait a couple of second for the database to start.from langchain.chat_models import ChatOpenAIfrom langchain.chains import GraphCypherQAChainfrom langchain.graphs import Neo4jGraphgraph = Neo4jGraph(    url="bolt://localhost:7687", username="neo4j", password="pleaseletmein")    /home/tomaz/neo4j/langchain/libs/langchain/langchain/graphs/neo4j_graph.py:52: ExperimentalWarning: The configuration may change in the future.      self._driver.verify_connectivity()Seeding the database‚ÄãAssuming your database is empty, you can populate it using Cypher query language. The following Cypher statement is idempotent, which means the database information will be the same if you run it one or multiple times.graph.query(    """MERGE (m:Movie {name:"Top Gun"})WITH mUNWIND ["Tom Cruise", "Val Kilmer", "Anthony Edwards", "Meg Ryan"] AS actorMERGE (a:Actor {name:actor})MERGE (a)-[:ACTED_IN]->(m)""")    []Refresh graph schema information‚ÄãIf the schema of database changes, you can refresh the schema information needed to generate Cypher statements.graph.refresh_schema()print(graph.schema)                Node properties are the following:            [{'properties': [{'property': 'name', 'type': 'STRING'}], 'labels': 'Movie'}, {'properties': [{'property': 'name', 'type': 'STRING'}], 'labels': 'Actor'}]            Relationship properties are the following:            []            The relationships are the following:            ['(:Actor)-[:ACTED_IN]->(:Movie)']            Querying the graph‚ÄãWe can now use the graph cypher QA chain to ask question of the graphchain = GraphCypherQAChain.from_llm(    ChatOpenAI(temperature=0), graph=graph, verbose=True)chain.run("Who played in Top Gun?")