|
1 |
| -== Setup Instructions |
| 1 | +== Graph Analytics |
2 | 2 |
|
3 |
| -See https://neo4j.com/docs/aura/graph-analytics/[documentation] |
| 3 | +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. |
| 4 | + |
| 5 | +More information about Aura Graph Analytics can be found in the Neo4j link:https://neo4j.com/docs/aura/graph-analytics[documentation]. |
| 6 | + |
| 7 | +You only need to have link:https://neo4j.com/docs/aura/api/authentication/[Aura API credentials] ready before you can start using sessions. |
| 8 | + |
| 9 | +=== Using the Graph Analytics Cypher API |
| 10 | + |
| 11 | +The Graph Analytics Cypher API provides a straightforward way to execute graph algorithms directly within your Neo4j database using Cypher queries. |
| 12 | +You can use the `gds.aura.api.credentials` function to provide your credentials in your Cypher queries. |
| 13 | + |
| 14 | +Assuming you have data in your Neo4j Aura database, the first step is to project a graph into Aura Graph Analytics. |
| 15 | + |
| 16 | +.Projecting a graph to a GDS Session: |
| 17 | +[source, cypher, copy=true] |
| 18 | +---- |
| 19 | +CYPHER runtime=parallel |
| 20 | +WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials |
| 21 | +MATCH (n) |
| 22 | +OPTIONAL MATCH (n)-->(m) |
| 23 | +RETURN gds.graph.project('myGraph', n, m, {}, {memory: '4GB'}) |
| 24 | +---- |
| 25 | + |
| 26 | +Next you can run different algorithms on the projected graph, such as PageRank to find central nodes in the graph. |
| 27 | + |
| 28 | +.Run an algorithm on the projected graph: |
| 29 | +[source, cypher, copy=true] |
| 30 | +---- |
| 31 | +WITH gds.aura.api.credentials($clientId, $clientSecret) AS credentials |
| 32 | +CALL gds.pageRank.stream('myGraph', { mutateProperty: 'pageRank' }) |
| 33 | +YIELD nodeId, score |
| 34 | +RETURN gds.util.asNode(nodeId), score |
| 35 | +---- |
| 36 | + |
| 37 | +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. |
| 38 | + |
| 39 | +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]. |
| 40 | + |
| 41 | + |
| 42 | +=== Using the Python Client |
| 43 | + |
| 44 | +To use the Graph Analytics features in Neo4j Aura with Python, you need to install the `graphdatascience` package. |
| 45 | +Compared to the Cypher API, the Python client offers the option to run algorithms against non-neo4j data sources, such as Pandas DataFrames. |
| 46 | + |
| 47 | +[source, bash, copy=true] |
| 48 | +---- |
| 49 | +pip install graphdatascience |
| 50 | +---- |
| 51 | + |
| 52 | +The entry point for managing Aura Graph Analytics sessions is the `GdsSessions` class. |
| 53 | + |
| 54 | +[source, python, copy=true] |
| 55 | +---- |
| 56 | +import os |
| 57 | +
|
| 58 | +from graphdatascience.session import AuraAPICredentials, GdsSessions |
| 59 | +
|
| 60 | +# you can also use AuraAPICredentials.from_env() to load credentials from environment variables |
| 61 | +api_credentials = AuraAPICredentials( |
| 62 | + client_id=os.environ["CLIENT_ID"], |
| 63 | + client_secret=os.environ["CLIENT_SECRET"], |
| 64 | + # If your account is a member of several project, you must also specify the project ID to use |
| 65 | + project_id=os.environ.get("PROJECT_ID", None), |
| 66 | +) |
| 67 | +
|
| 68 | +sessions = GdsSessions(api_credentials=api_credentials) |
| 69 | +---- |
| 70 | + |
| 71 | + |
| 72 | +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). |
0 commit comments