liveBook · Manning

Graph projection

As explained in Graph Algorithms for Data Science

A projected in-memory graph is an in-memory graph representation created from stored graph data for graph algorithm execution.

A graph projection creates a separate, optimized in-memory graph from stored graph data so Graph Data Science algorithms can run scalably and in parallel. Algorithms operate on this projected graph rather than directly on the database graph. A projection can be named and reused for several algorithm runs. section 5.2 section 5.6

Choose a projection approach based on the analysis need:

  • Use native projection when labels and relationship types are enough to select the graph. It reads directly from Neo4j storage and is the higher-performing option. section 5.2
  • Use Cypher projection when a query must filter or transform the selected nodes and relationships, including virtual connections not stored in the database. Its flexibility comes with slower performance, so it suits exploration rather than large production graphs. section 6.1.1
  • Use subgraph projection to create a new named graph from an existing in-memory graph by filtering nodes and relationships with predicates. section 7.5

Project a weighted retweet network

Match source and target users through retweet activity, count each connection as a weight, then pass the nodes and relationship property to gds.graph.project. The resulting named graph, amplify, reports its node and relationship counts and is ready for algorithms. section 6.1.1

Include the labels, relationship types, and properties that later algorithms need. For example, a follower-network projection includes precalculated node features before betweenness centrality mutates a score back into the in-memory graph; a shared-audience network includes relationship weight and can be configured as undirected for node2vec. section 8.1.2 section 9.3.3

Listing 6.3 Loading the amplify retweet network as an in-memory graph using Cypher projection
MATCH (source:User)-[:PUBLISH]->()-[:RETWEETS]->()<-[:PUBLISH]-(target:User)
WITH source, target, count(*) AS weight      #1
WITH gds.graph.project(
    'amplify',
    source,
    target,                                  #2
   {relationshipProperties:{weight:weight}}
) AS g
RETURN g.graphName AS graph,
       g.nodeCount AS nodes,
       g.relationshipCount AS rels   

This query shows a Cypher projection that derives weighted user-to-user retweet connections and returns the name and size of the in-memory graph. section 6.1.1

Projected graphs consume memory. After the planned algorithm sequence finishes, release a named graph with gds.graph.drop(), or list projected graphs and drop each one to free memory for later analyses. section 5.4.3 section 6.3.3

How Graph Algorithms for Data Science covers it

How deep it goes
Explains native, Cypher, and filtered subgraph projections with parameters, trade-offs, properties, and cleanup procedures.
Examples
Demonstrates weighted retweet, hashtag-community, follower, and shared-audience network projections.
What it assumes
Applies Cypher matching and predicates while introducing projection as the required setup for algorithm execution.
What you can do after
Operate/configure it by creating named graphs, selecting properties and orientations, filtering subgraphs, and releasing memory afterward.
How it connects
Connects Graph Data Science to Cypher, graph algorithms, graph catalogs, PageRank, betweenness centrality, and node2vec.

Also explained in

Compare how 2 books explain graph projection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.