Connecting to Neo4j

As you learned in the Initializing the LLM lesson of Neo4j & LLM Fundamentals, Langchain uses the Neo4jGraph class to communicate with Neo4j.

You will need to create an instance of the Neo4jGraph class and connect to the Neo4j Sandbox instance created for you when you enrolled in the course.

To complete this challenge, you will need to:

  1. Add the Neo4j Credentials to .streamlit/secrets.toml

  2. Create a new Neo4jGraph instance using these credentials

Set the Neo4j Secrets

Here are the credentials for your Neo4j Sandbox instance.



Connection URL





Set these as secrets in the Streamlit app by opening the .streamlit/secrets.toml and adding the following values.

OPENAI_API_KEY = "sk-..."
OPENAI_MODEL = "gpt-4"

NEO4J_URI = "bolt://"
NEO4J_USERNAME = "neo4j"
NEO4J_PASSWORD = "volume-mattress-twig"

Connect to the database

Open the file in the project root, import the Neo4jGraph class, and create a new instance with your credentials.

Unresolved directive in lesson.adoc - include::[tag=graph]

Using the Neo4jGraph Instance

Once you have completed the steps, you can import the graph and use the Neo4jGraph instance in other modules within the project.

from graph import graph


In this lesson, you added your Neo4j Sandbox credentials to the app and used them to create a Neo4jGraph object.

In the next lesson, you will create an Agent to communicate with the LLM.