Cypher projection uses Cypher statements to select, filter, and transform nodes and relationships into an optimized in-memory graph for graph algorithms. It can create virtual relationships without storing them in the database, making it useful for exploratory graph analysis. section 5.2 section 6.1
A Cypher projection workflow typically involves:
- Match the source and target nodes for the relationships to project. section 6.1.1
- Define existing or virtual relationships, optionally calculating properties such as weights. section 6.1 section 6.1.1
- Call gds.graph.project with a graph name, source nodes, target nodes, and optional configuration. section 6.1.1
- Reuse the named in-memory graph for multiple algorithm runs when appropriate. section 5.2
Projecting an amplified retweet network
Match paths from a publishing user through a retweet to another publishing user, count each source–target pair as a weight, and project the result as amplify. The resulting example contains 1,828 nodes and 2,719 relationships. A second projection named amplify-noselfloops can exclude relationships whose source and target are the same node. section 6.3.1
Listing 6.2 Cypher projection syntax
MATCH (sourceNode)-[relationship]->(targetNode) #1
RETURN gds.graph.project(
'graph', #2
sourceNode, #3
targetNode, #4
{dataConfig}, #5
{configuration} #6
) YIELD
graphName,
nodeCount,
relationshipCount
Use the syntax listing to see how MATCH supplies projected relationships and how gds.graph.project returns the graph name and counts. section 6.1.1
