2.3. Named graphs

This section describes named graphs, which are stored only in memory. When Neo4j is restarted, named graphs are lost and will need to be reloaded.

As it can take some time to load large graphs into the algorithm data structures, you can pre-load graphs and then later refer to them by name when calling graph algorithm procedures. After usage, they can be removed from memory to free resources used.

2.3.1. Loading a named graph

We can load named graphs using any of the approaches described in the projected graph model section.

The following will load a graph with the name my-graph, for node label Label and relationship type REL_TYPE

CALL algo.graph.load('my-graph','Label','REL_TYPE',{graph:'heavy' /*, ... other config */})
YIELD name, graph, direction, undirected, sorted, nodes, loadMillis, alreadyLoaded,
      nodeWeight, relationshipWeight, nodeProperty, loadNodes, loadRelationships;

If we want to load a graph based on a Cypher projection, we should specify graph:'cypher' in the config.

The following will load a named graph using Cypher projections for nodes and relationships. 

CALL algo.graph.load('my-graph',
  'MATCH (n) RETURN id(n) AS id',
  'MATCH (a)-->(b) RETURN id(a) AS source, id(b) AS target',
  {graph:'cypher' /*, ... other config */})
YIELD name, graph, direction, undirected, sorted, nodes, loadMillis, alreadyLoaded,
      nodeWeight, relationshipWeight, nodeProperty, loadNodes, loadRelationships;

Once we’ve loaded a named graph we can return details about it.

The following will return details about a named graph: 

CALL algo.graph.info('my-graph')
YIELD name, type, exists, removed, nodes;

Besides node and relationship counts, the procedure can compute information about degree distributions, i.e. the number of relationships per node. By default, the distribution values are not computed.

The following will enable computing information about degree distributions: 

CALL algo.graph.info('my-graph', true)
YIELD name, type, exists, removed, nodes, min, max, mean, p50, p75, p90, p95, p99, p999;

In order to set the direction and concurrency for the degree computation, we can provide a parameter map instead: 

CALL algo.graph.info('my-graph', {direction: 'OUTGOING', concurrency: 8 })
YIELD name, type, exists, removed, nodes, min, max, mean, p50, p75, p90, p95, p99, p999;

2.3.2. Using a named graph

We can use our named graph in queries by specifying its name in the graph key of config.

The following will run the PageRank algorithm on the my-graph named graph: 

CALL algo.pageRank(null,null,{graph:'my-graph' /*, ... */})

2.3.3. Remove named graph

Once we’ve finished using the named graph we can remove them to free up memory.

The following will remove the my-graph named graph: 

CALL algo.graph.remove('my-graph')
YIELD name, type, exists, removed, nodes;