Model repository and model stores

Overview

A model store can be used to persist trained pgx machine learning models (see MLib overview) along with a model name (a unique identifier of the model in this particular model store) and a description.

The model repository provides the API to

  • list all available model stores in the model repository,

  • create new and delete existing model stores,

  • list all models in a given model store,

  • get the model description for a model that is stored in the given model store,

  • delete a model from the given model store.

Multiple model stores can coexist next to each other (e.g. one for each user or one for dev, staging and production).

DB backed model repository

In a db backed model repository, each model store corresponds to a table in the database. Internally, the tables are prefixed by GMLS_.

The following code block illustrates the usage of the model repository api and shows how

  • a model store can be created

  • the existing model stores can be listed

  • a model can be persisted in a model store along with a name and a description

  • models stored in a model store can be listed

  • a model can be loaded from the model store

  • the description of a stored model can be retrieved from a model store

  • a model can be deleted from a model store

  • a model store can be deleted

 1username = 'username'
 2password = 'password'
 3modelstore = 'modelstore'
 4modelname = 'deepwalk_model'
 5jdbc_url = 'jdbc:oracle:thin:@localhost:1521:rdbmsod'
 6model_description = 'some description'
 7# create a db backed model repository object
 8mr = analyst.model_repository().db(
 9    # DB user to use for storing the model
10    username=username,
11    # password of the DB user
12    password=password,
13    # jdbc url to the DB
14    jdbc_url=jdbc_url
15)
16
17# list model stores
18mr.list_model_stores_names()
19
20# create a model store
21mr.create("modelstore")
22
23# list model stores and see that there are no models yet
24mr.list_model_stores_names()
25mr.list_model_stores_names_matching("modelstore")
26mr.list_models("modelstore")
27
28# create and fit a model
29model = analyst.deepwalk_builder(
30    window_size=3,
31    walks_per_vertex=6,
32    walk_length=4
33)
34model.fit(small_graph)
35
36model.export().db(
37    # name of the model store table
38    modelstore,
39    # name to give to the model (primary key of model store table)
40    modelname,
41    # DB user to use for storing the model
42    username=username,
43    # password of the DB user
44    password=password,
45    # jdbc url to the DB
46    jdbc_url=jdbc_url,
47    # description to store alongside the model
48    model_description=model_description,
49    overwrite=True
50)
51
52# verify that the model is now stored in the model store
53mr.list_models(modelstore)
54
55# load the model from the model store
56analyst.get_deepwalk_model_loader().db(
57    username="user",
58    password="password",
59    model_store="modelstore",
60    model_name="deepwalk_model",
61    jdbc_url="jdbc_url"
62)
63
64# get the model description for the model
65mr.get_model_description("modelstore", "deepwalk_model")
66# delete the model from the model store
67mr.delete_model("modelstore", "deepwalk_model")
68# delete the whole model store
69mr.delete_model_store("modelstore")

File backed model repository

The model repository api is currently not supported for file based model persistence.