@@ -15,7 +15,7 @@ The notebook shows how to use the `graphdatascience` Python library to
1515create, manage, and use a GDS Session.
1616
1717We consider a graph of people and fruits, which we’re using as a simple
18- example to show how to load data from Pandas DataFrames to a GDS
18+ example to show how to load data from Pandas `DataFrame` to a GDS
1919Session, run algorithms, and inspect the results. We will cover all
2020management operations: creation, listing, and deletion.
2121
@@ -66,16 +66,16 @@ sessions = GdsSessions(api_credentials=AuraAPICredentials(client_id, client_secr
6666== Creating a new session
6767
6868A new session is created by calling `sessions.get++_++or++_++create()`.
69- As the data source, we assume that a self-managed Neo4j DBMS instance
70- has been set up and is accessible. We need to pass the database address,
71- user name and password to the `DbmsConnectionInfo` class.
69+ We also need to specify the session `memory` and `cloud++_++location`.
7270
73- We also need to specify the session size. Please refer to the API
74- reference documentation or the manual for a full list.
71+ Please refer to the API reference
72+ https://neo4j.com/docs/graph-data-science-client/current/api/sessions/gds_sessions/#graphdatascience.session.gds_sessions.GdsSessions.get_or_create[documentation]
73+ or the manual for a full list options.
7574
7675Finally, we need to give our session a name. We will call ours
77- `people-and-fruits-sm'. It is possible to reconnect to an existing session by calling`get++_++or++_++create++`++
78- with the same session name and configuration.
76+ `people-and-fruits-standalone`. It is possible to reconnect to an
77+ existing session by calling `get++_++or++_++create` with the same
78+ session name and configuration.
7979
8080We will also set a time-to-live (TTL) for the session. This ensures that
8181our session is automatically deleted after being unused for 30 minutes.
@@ -84,7 +84,7 @@ delete the session ourselves.
8484
8585[source, python, role=no-test]
8686----
87- from graphdatascience.session import AlgorithmCategory, SessionMemory
87+ from graphdatascience.session import AlgorithmCategory, CloudLocation, SessionMemory
8888
8989# Explicitly define the size of the session
9090memory = SessionMemory.m_4GB
@@ -98,19 +98,24 @@ memory = sessions.estimate(
9898
9999print(f"Estimated memory: {memory}")
100100
101- # Find out and specify where to create the GDS session
101+ # Specify your cloud location
102+ cloud_location = CloudLocation("gcp", "europe-west1")
103+
104+ # You can find available cloud locations by calling
102105cloud_locations = sessions.available_cloud_locations()
103106print(f"Available locations: {cloud_locations}")
104- cloud_location = cloud_locations[0]
105107----
106108
107109[source, python, role=no-test]
108110----
111+ from datetime import timedelta
112+
109113# Create a GDS session!
110114gds = sessions.get_or_create(
111115 # we give it a representative name
112116 session_name="people-and-fruits-standalone",
113117 memory=memory,
118+ ttl=timedelta(minutes=30),
114119 cloud_location=cloud_location,
115120)
116121----
@@ -179,16 +184,15 @@ knows_df["relationshipType"] = "KNOWS"
179184
180185Now that we have imported a graph to our database, we create graphs
181186directly from pandas `DataFrame` objects. We do that by using the
182- `gds.graph.construct()` endpoint .
187+ `gds.graph.construct()` method .
183188
184189[source, python, role=no-test]
185190----
186- nodes = [people_df.drop(columns="name"), fruits_df.drop(columns="name")] # GDS does not support string properties
191+ # Dropping `name` column as GDS does not support string properties
192+ nodes = [people_df.drop(columns="name"), fruits_df.drop(columns="name")]
187193relationships = [likes_df, knows_df]
188194
189195G = gds.graph.construct("people-fruits", nodes, relationships)
190-
191-
192196str(G)
193197----
194198
@@ -222,16 +226,15 @@ print(f"Compute millis: {frp_result['computeMillis']}")
222226# stream back the results
223227result = gds.graph.nodeProperties.stream(G, ["pagerank", "fastRP"], separate_property_columns=True)
224228
225- print( result)
229+ result
226230----
227231
228- To resolve the nodeIds to names , we can merge it back with the source
232+ To resolve each `nodeId` to name , we can merge it back with the source
229233data frames.
230234
231235[source, python, role=no-test]
232236----
233237names = pd.concat([people_df, fruits_df])[["nodeId", "name"]]
234-
235238result.merge(names, how="left")
236239----
237240
0 commit comments