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.

Scheme

bolt

Connection URL

3.231.31.140

Username

neo4j

Password

volume-mattress-twig

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

toml
.streamlit/secrets.toml
OPENAI_API_KEY = "sk-..."
OPENAI_MODEL = "gpt-4"

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

Connect to the database

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

python
graph.py
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/llm-vectors-unstructured/main/solutions/graph.py[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.

python
from graph import graph

Summary

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.