LoslegenKostenlos starten

Saving graph documents

You now have three nodes and two relationships in your application, but at the moment they are only held in memory.

In this exercise, you'll connect to your Neo4j instance (which has already been spun-up for you), and save the nodes and relationships to the database.

Diese Übung ist Teil des Kurses

<Kurs>Graph RAG with LangChain and Neo4j</Kurs>
Kurs ansehen

Übungsanweisungen

  • Connect to the Neo4j database using the credentials provided.
  • Create a graph document from the nodes (book, jesus, jim) and relationships (written_by_jesus, written_by_jim) defined.
  • Save the graph document to the database.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Connect to the Neo4j Database
graph = ____(url=NEO4J_URL, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)

# Define the collection of graph documents
graph_document = ____(
    ____=[book, jesus, jim], 
    ____=[written_by_jesus, written_by_jim]
)

# Save the data to your graph
graph.____([graph_document])

graph.refresh_schema()
print(graph.schema)
Code bearbeiten und ausführen