Storing models on disk

The model catalog exists as long as the Neo4j instance is running. When Neo4j is restarted, models are no longer available in the catalog and need to be trained again. This can be prevented by storing a model on disk.

The location of the stored models can be configured via the configuration parameter gds.model.store_location in the neo4j.conf. The location must be a directory and writable by the Neo4j process.

The gds.model.store_location parameter must be configured for this feature.

Storing models from the catalog on disk

Models that can be stored

Syntax

Store a model from the catalog:
CALL gds.model.store(
    modelName: String,
    failIfUnsupported: Boolean
)
YIELD
    modelName: String,
    storeMillis: Integer
Table 1. Parameters
Name Type Default Optional Description

modelName

String

n/a

no

The name of a model.

failIfUnsupported

Boolean

true

yes

By default, the library will raise an error when trying to store a non-supported model. When set to false, the procedure returns an empty result.

Table 2. Results
Name Type Description

modelName

String

The name of the stored model.

storeMillis

Integer

The number of milliseconds it took to store the model.

Example

Store a model on disk:
CALL gds.model.store('my-model')
YIELD
  modelName,
  storeMillis

Loading models from disk

GDS will discover available models from the configured store location upon database startup. During discovery, only model metadata is loaded, not the actual model data. In order to use a stored model, it has to be explicitly loaded.

Syntax

Load a model from disk:
CALL gds.model.load(modelName: String)
YIELD
    modelName: String,
    loadMillis: Integer
Table 3. Parameters
Name Type Default Optional Description

modelName

String

n/a

no

The name of a model.

Table 4. Results
Name Type Description

modelName

String

The name of the loaded model.

loadMillis

Integer

The number of milliseconds it took to load the model.

Example

Load a model from disk:
CALL gds.model.load('my-model')
YIELD
  modelName,
  loadMillis

To verify if a model is loaded, we can use the gds.model.list procedure. The procedure returns flags to indicate if the model is stored and if the model is loaded into memory. The operation is idempotent, and skips loading if the model is already loaded.

Deleting models from disk

To remove a stored model from disk, it has to be deleted. This is different from dropping a model. Dropping a model will remove it from the in-memory model catalog, but not from disk. Deleting a model will remove it from disk, but keep it in the in-memory model catalog if it was already loaded.

Syntax

Delete a stored model from disk:
CALL gds.model.delete(modelName: String)
YIELD
    modelName: String,
    deleteMillis: Integer
Table 5. Parameters
Name Type Default Optional Description

modelName

String

n/a

no

The name of a model.

Table 6. Results
Name Type Description

modelName

String

The name of the loaded model.

deleteMillis

Integer

The number of milliseconds it took to delete the model.

Example

Delete a model from disk:
CALL gds.model.delete('my-model')
YIELD
  modelName,
  deleteMillis

Models from older GDS versions

Before GDS 2.4, node classification and link prediction models could only be stored if they were trained with a Logistic Regression trainer method.

Any stored models from older GDS versions can be loaded in the most recent GDS version.