Removing graphs

This section details how to remove graphs stored in the graph catalog of the Neo4j Graph Data Science library.

To free up memory, we can remove unused graphs. In order to do so, the gds.graph.drop procedure comes in handy.

1. Syntax

Remove a graph from the catalog:
CALL gds.graph.drop(
  graphName: String,
  failIfMissing: Boolean,
  dbName: String,
  username: String
) YIELD
  graphName: String,
  database: String,
  nodeProjection: Map,
  relationshipProjection: Map,
  nodeQuery: String,
  relationshipQuery: String,
  nodeFilter: String,
  relationshipFilter: String,
  nodeCount: Integer,
  relationshipCount: Integer,
  schema: Map,
  density: Float,
  creationTime: Datetime,
  modificationTime: Datetime,
  sizeInBytes: Integer,
  memoryUsage: String
Table 1. Parameters
Name Type Optional Description

graphName

String

no

The name under which the graph is stored in the catalog.

failIfMissing

Boolean

true

By default, the library will raise an error when trying to remove a non-existing graph. When set to false, the procedure returns empty result.

dbName

String

active database name

Then name of the database that was used to project the graph. When empty, the current database is used.

username

String

active user

The name of the user who projected the graph. Can only be used by GDS administrator.

Table 2. Results
Name Type Description

graphName

String

Name of the removed graph.

database

String

Name of the database in which the graph has been created.

nodeProjection

Map

Node projection used to create the graph. If a Cypher projection was used, this will be a derived node projection.

relationshipProjection

Map

Relationship projection used to create the graph. If a Cypher projection was used, this will be a derived relationship projection.

nodeQuery

String

Node query used to create the graph. If a native projection was used, this will be null.

relationshipQuery

String

Relationship query used to create the graph. If a native projection was used, this will be null.

nodeFilter

String

The node filter used when creating this subgraph from another in-memory graph.

relationshipFilter

String

The relationship filter used when creating this subgraph from another in-memory graph.

nodeCount

Integer

Number of nodes in the graph.

relationshipCount

Integer

Number of relationships in the graph.

schema

Map

Node labels, Relationship types and properties contained in the in-memory graph.

density

Float

Density of the graph.

creationTime

Datetime

Time when the graph was created.

modificationTime

Datetime

Time when the graph was last modified.

sizeInBytes

Integer

Number of bytes used in the Java heap to store the graph.

memoryUsage

String

Human readable description of sizeInBytes.

2. Examples

In this section we are going to demonstrate the usage of gds.graph.drop. All the graph names used in these examples are fictive and should be replaced with real values.

2.1. Basic usage

Remove a graph from the catalog:
CALL gds.graph.drop('my-store-graph') YIELD graphName;

If we run the example above twice, the second time it will raise an error. If we want the procedure to fail silently on non-existing graphs, we can set a boolean flag as the second parameter to false. This will yield an empty result for non-existing graphs.

Try removing a graph from the catalog:
CALL gds.graph.drop('my-fictive-graph', false) YIELD graphName;

2.2. Multi-database support

If we want to drop a graph created on another database, we can set the database name as the third parameter.

Try removing a graph from the catalog:
CALL gds.graph.drop('my-fictive-graph', true, 'my-other-db') YIELD graphName;

2.3. Multi-user support

If we are a GDS administrator and want to drop a graph that belongs to another user we can set the username as the fourth parameter to the procedure. This is useful if there are multiple users with graphs of the same name.

Remove a graph from a specific user’s graph catalog:
CALL gds.graph.drop('my-fictive-graph', true, '', 'another-user') YIELD graphName;

See Administration for more details on this.