Quickstart
Here is a full example of how to use the Cypher API to load data from an AuraDB instance into a remote session, run two algorithms, then write the results back to AuraDB.
You can find more details on each step and procedure in the Cypher API page.
Projecting a graph
Start by adding some example data into the AuraDB database.
CREATE
(a:User {name: 'Alice', age: 23}),
(b:User {name: 'Bridget', age: 34}),
(c:User {name: 'Charles', age: 45}),
(d:User {name: 'Dana', age: 56}),
(e:User {name: 'Eve', age: 67}),
(f:User {name: 'Fawad', age: 78}),
(a)-[:LINK {weight: 0.5}]->(b),
(b)-[:LINK {weight: 0.2}]->(a),
(a)-[:LINK {weight: 4}]->(c),
(c)-[:LINK {weight: 2}]->(e),
(e)-[:LINK {weight: 1.1}]->(d),
(e)-[:LINK {weight: -2}]->(f);

The next step is to project the data into a graph within a remote session. The following example shows how to run a Cypher projection and create a session at the same time.
Make sure that the credentials you use here are the Aura API keys (client ID and client secret), not your AuraDB credentials (username and password). |
CYPHER runtime=parallel (1)
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials (2)
MATCH (source:User)
OPTIONAL MATCH (source)-[r:LINK]->(target:User)
WITH gds.graph.project('myGraph', source, target, {
sourceNodeProperties: source { .age },
targetNodeProperties: target { .age },
relationshipProperties: r { .weight }
}, {
memory: '4GB', ttl: duration({minutes: 5}) (3)
}) AS g
RETURN g.graphName, g.nodeCount, g.relationshipCount
1 | The Cypher parallel runtime is recommended but not mandatory. |
2 | Add the gds.aura.api.credentials function before the actual query.
You need to set the clientId and clientSecret query parameters first. |
3 | Set the memory (mandatory) and ttl (optional) parameters. |
graphName | nodeCount | relationshipCount |
---|---|---|
"myGraph" |
6 |
6 |
After this completes, the session is ready to use. If you have the Aura Console open, you can see the session listed in the Graph Analytics view.
You can also get details on the projected graph using the gds.graph.list()
procedure.
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.graph.list()
YIELD graphName, nodeCount, relationshipCount
RETURN graphName, nodeCount, relationshipCount
graphName | nodeCount | relationshipCount |
---|---|---|
"myGraph" |
6 |
6 |
Running algorithms
Run the PageRank algorithm in mutate
mode on the remote graph to create the pageRank
node property from its results.
mutate
modeWITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.pageRank.mutate('myGraph', { mutateProperty: 'pageRank' })
YIELD ranIterations, nodePropertiesWritten
RETURN ranIterations, nodePropertiesWritten
ranIterations | nodePropertiesWritten |
---|---|
1 |
6 |
Use the new pageRank
node property as input to the FastRP algorithm and create the fastrp
node property.
mutate
modeWITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.fastRP.mutate('myGraph', {
featureProperties: ['pageRank'],
relationshipWeightProperty: 'weight',
iterationWeights: [1, 1, 1],
randomSeed: 42,
embeddingDimension: 8,
mutateProperty: 'fastrp'
})
YIELD nodePropertiesWritten
RETURN nodePropertiesWritten
nodePropertiesWritten |
---|
6 |
Inspect the values of the new node properties.
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.graph.nodeProperty.stream('myGraph', 'fastrp')
YIELD nodeId, propertyValue
RETURN nodeId, propertyValue
ORDER BY nodeId
nodeId | propertyValue |
---|---|
0 |
[-0.8200507164, -0.0124960952, 0.2896471024, -0.2785570323, -0.8645128608, -0.1037763357, 0.0, 0.4556654692] |
1 |
[-0.3894904256, -0.5124961138, 0.9440460801, -0.9576280117, 0.0673641935, -1.0132695436, 0.0, 0.4451318979] |
2 |
[-0.4223886132, 0.0, 0.3452976346, 0.190074876, -0.4223886132, 0.4223886132, 0.0, 0.0] |
3 |
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] |
4 |
[-0.4223886132, 0.0, -0.6547023654, 0.190074876, -0.4223886132, 0.4223886132, 0.0, 0.0] |
5 |
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] |
Writing results to the database
You can write new properties to the source AuraDB database in two ways:
-
Using the
gds.graph.nodeProperty.write()
procedure (see Writing node properties and labels for more details).Write thefastrp
propertyWITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials CALL gds.graph.nodeProperties.write('myGraph', ['fastrp']) YIELD propertiesWritten RETURN propertiesWritten
Table 6. Results propertiesWritten 6
-
Running an algorithm in
write
mode.Run the Louvain algorithm inwrite
modeWITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials CALL gds.louvain.write('myGraph', { writeProperty: 'louvain' }) YIELD communityCount, modularity RETURN communityCount, modularity
Table 7. Results communityCount modularity 2
0.3333333333333333
Cleaning up
When you do not need to run any more algorithms, drop the projected graph. Since the session was created implicitly (together with the graph), dropping the graph will also delete the session and tear down its corresponding Aura instance.
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.graph.drop('myGraph')
YIELD graphName
RETURN graphName
graphName |
---|
"myGraph" |
After this completes, the session is no longer visible in the Aura Console and no more costs are incurred for its use.
If you do not explicitly drop the graph, the session will automatically expire after the configured ttl
time has passed.