Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 71 additions & 2 deletions documentation/graph-analytics.adoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
== Setup Instructions
== Graph Analytics

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
== Graph Analytics
== Introduction

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Graph Analytics" is already the tab name, so this is more specific.


See https://neo4j.com/docs/aura/graph-analytics/[documentation]
Graph Analytics is a powerful feature of Neo4j Aura that allows users to run graph algorithms on their graph data. This includes tasks such as community detection, pathfinding, and centrality analysis.

More information about Aura Graph Analytics can be found in the Neo4j link:https://neo4j.com/docs/aura/graph-analytics[documentation].

You only need to have link:https://neo4j.com/docs/aura/api/authentication/[Aura API credentials] ready before you can start using sessions.
Comment on lines +3 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Graph Analytics is a powerful feature of Neo4j Aura that allows users to run graph algorithms on their graph data. This includes tasks such as community detection, pathfinding, and centrality analysis.
More information about Aura Graph Analytics can be found in the Neo4j link:https://neo4j.com/docs/aura/graph-analytics[documentation].
You only need to have link:https://neo4j.com/docs/aura/api/authentication/[Aura API credentials] ready before you can start using sessions.
link:https://neo4j.com/docs/aura/graph-analytics[Graph Analytics^] allows you to run graph algorithms on your data, for example to detect communities or shortest paths between nodes.
== Requirements
You must create link:https://neo4j.com/docs/aura/api/authentication/[Aura API credentials] to use Aura Graph Analytics.
Optionally, you can create an example dataset in your Neo4j database using the following Cypher query.
[source, cypher, copy=true]
----
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);
----


=== Using the Graph Analytics Cypher API

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=== Using the Graph Analytics Cypher API
== Graph Analytics with Cypher


The Graph Analytics Cypher API provides a straightforward way to execute graph algorithms directly within your Neo4j database using Cypher queries.
You can use the `gds.aura.api.credentials` function to provide your credentials in your Cypher queries.

Assuming you have data in your Neo4j Aura database, the first step is to project a graph into Aura Graph Analytics.
Comment on lines +11 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The Graph Analytics Cypher API provides a straightforward way to execute graph algorithms directly within your Neo4j database using Cypher queries.
You can use the `gds.aura.api.credentials` function to provide your credentials in your Cypher queries.
Assuming you have data in your Neo4j Aura database, the first step is to project a graph into Aura Graph Analytics.
Assuming you already have some data in your AuraDB instance, the first step is to create a remote in-memory graph within an Aura Graph Analytics session using a _remote projection_.


.Projecting a graph to a GDS Session:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.Projecting a graph to a GDS Session:

[source, cypher, copy=true]
----
CYPHER runtime=parallel
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
MATCH (n)
OPTIONAL MATCH (n)-->(m)
RETURN gds.graph.project('myGraph', n, m, {}, {memory: '4GB'})
----

Next you can run different algorithms on the projected graph, such as PageRank to find central nodes in the graph.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Next you can run different algorithms on the projected graph, such as PageRank to find central nodes in the graph.
Once the graph is created, you can run any graph algorithms.
For example, run PageRank to find the central nodes in the graph and assign the result for each node to a new `pageRank` node property.


.Run an algorithm on the projected graph:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.Run an algorithm on the projected graph:

[source, cypher, copy=true]
----
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
WITH gds.aura.api.credentials("<Aura API Client ID>", "<Aura API Client Secret>") AS credentials

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agreed to make auth examples easier by using placeholders rather than query parameters (same for the client examples).

CALL gds.pageRank.stream('myGraph', { mutateProperty: 'pageRank' })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CALL gds.pageRank.stream('myGraph', { mutateProperty: 'pageRank' })
CALL gds.pageRank.mutate('myGraph', { mutateProperty: 'pageRank' })

YIELD nodeId, score
RETURN gds.util.asNode(nodeId), score
----

After running the algorithm, you can inspect the PageRank score assigned to each node using `gds.graph.nodeProperty.stream` function to retrieve the node properties that were mutated by the algorithm.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
After running the algorithm, you can inspect the PageRank score assigned to each node using `gds.graph.nodeProperty.stream` function to retrieve the node properties that were mutated by the algorithm.
After running the algorithm, you can inspect the PageRank score assigned to each node using the `gds.graph.nodeProperty.stream` function.
[source, cypher, copy=true]
----
WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials
CALL gds.graph.nodeProperty.stream('myGraph', 'pageRank')
YIELD nodeId, propertyValue
RETURN nodeId, propertyValue
ORDER BY nodeId
----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also skip this one and just show the algo in stream mode, then do the same with the client examples.


For more information about the Cypher API such as writing back results to the database, refer to the link:https://neo4j.com/docs/graph-data-science/current/aura-graph-analytics/cypher[Graph Data Science documentation].

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more information about the Cypher API such as writing back results to the database, refer to the link:https://neo4j.com/docs/graph-data-science/current/aura-graph-analytics/cypher[Graph Data Science documentation].
For more information about the Graph Analytics Cypher API, refer to the link:https://neo4j.com/docs/graph-data-science/current/aura-graph-analytics/cypher[Graph Data Science documentation].



=== Using the Python Client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=== Using the Python Client
== Graph Analytics with the Python client


To use the Graph Analytics features in Neo4j Aura with Python, you need to install the `graphdatascience` package.
Compared to the Cypher API, the Python client offers the option to run algorithms against non-neo4j data sources, such as Pandas DataFrames.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Compared to the Cypher API, the Python client offers the option to run algorithms against non-neo4j data sources, such as Pandas DataFrames.
Compared to the Cypher API, the Python client offers the option to run algorithms on data from non-Neo4j data sources such as Pandas DataFrames.


[source, bash, copy=true]
----
pip install graphdatascience
----

The entry point for managing Aura Graph Analytics sessions is the `GdsSessions` class.

[source, python, copy=true]
----
import os

from graphdatascience.session import AuraAPICredentials, GdsSessions

# you can also use AuraAPICredentials.from_env() to load credentials from environment variables
api_credentials = AuraAPICredentials(
client_id=os.environ["CLIENT_ID"],
client_secret=os.environ["CLIENT_SECRET"],
# If your account is a member of several project, you must also specify the project ID to use
project_id=os.environ.get("PROJECT_ID", None),
)

sessions = GdsSessions(api_credentials=api_credentials)
Comment on lines +56 to +68

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import os
from graphdatascience.session import AuraAPICredentials, GdsSessions
# you can also use AuraAPICredentials.from_env() to load credentials from environment variables
api_credentials = AuraAPICredentials(
client_id=os.environ["CLIENT_ID"],
client_secret=os.environ["CLIENT_SECRET"],
# If your account is a member of several project, you must also specify the project ID to use
project_id=os.environ.get("PROJECT_ID", None),
)
sessions = GdsSessions(api_credentials=api_credentials)
from graphdatascience.session import GdsSessions, AuraAPICredentials
CLIENT_ID = "<Aura API Client ID>"
CLIENT_SECRET = "<Aura API Client Secret>"
PROJECT_ID = None
# Create a new GdsSessions object
sessions = GdsSessions(api_credentials=AuraAPICredentials(CLIENT_ID, CLIENT_SECRET, PROJECT_ID))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to add the examples for how to create a session and run an algorithm.

----


For more details, explore our client link:https://neo4j.com/docs/graph-data-science-client/current/graph-analytics-serverless/[docs] and the tutorials on link:https://neo4j.com/docs/graph-data-science-client/current/tutorials/graph-analytics-serverless/[attached], and link:https://neo4j.com/docs/graph-data-science-client/current/tutorials/graph-analytics-serverless-standalone/[standalone] sessions).
Comment on lines +71 to +72

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more details, explore our client link:https://neo4j.com/docs/graph-data-science-client/current/graph-analytics-serverless/[docs] and the tutorials on link:https://neo4j.com/docs/graph-data-science-client/current/tutorials/graph-analytics-serverless/[attached], and link:https://neo4j.com/docs/graph-data-science-client/current/tutorials/graph-analytics-serverless-standalone/[standalone] sessions).
For more details, see the Python client link:https://neo4j.com/docs/graph-data-science-client/current/graph-analytics-serverless/[docs] and the link:https://neo4j.com/docs/graph-data-science-client/current/tutorials/graph-analytics-serverless/[tutorial for AuraDB].