.ipynb
.pdf
GraphCypherQAChain
 Contents 
Seeding the database
Refresh graph schema information
Querying the graph
Limit the number of results
Return intermediate results
Return direct results
GraphCypherQAChain#
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 will need to have a running Neo4j instance. One option is to create a free Neo4j database instance in their Aura cloud service. You can also run the database locally using the Neo4j Desktop application, or running a docker container.
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:latest
If you are using the docker container, you need to wait a couple of second for the database to start.
from langchain.chat_models import ChatOpenAI
from langchain.chains import GraphCypherQAChain
from langchain.graphs import Neo4jGraph
graph = Neo4jGraph(
    url="bolt://localhost:7687", username="neo4j", password="pleaseletmein"
)
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 m
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/graph_cypher_qa.html