The ClusteringSolutionVersion API is a scriptable object used in Predictive Intelligence stores.

This API requires the Predictive Intelligence plugin (com.glide.platform_ml) and is provided within the sn_ml namespace.

It is used for working with solution versions based on ClusteringSolution API objects in the ClusteringSolution store.

The system creates a solution version each time you train a solution definition. Most versions are created during scheduled solution training.

Methods in this API are accessible using the following ClusteringSolution methods:

ClusteringSolutionVersion - cancelUpdateJob()

Cancels an update job on a trainer.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
None

Example

The following example shows how to cancel an active training job that has been submitted using the submitTrainingJob() method.

var myCluster = new sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");
var mlSolutionVersion = myCluster.getActiveVersion();

mlSolutionVersion.cancelUpdateJob();

ClusteringSolutionVersion - deleteClusterAssignments(Object options)

Deletes cluster assignments from rows by position in table sequence or GlideDateTime.

Table 3. Parameters
Name Type Description
options Object Object defining one option for deleting cluster assignments.
Note: Only one delete option is valid.
options.updatedUntil String Deletes rows for clusters with updated_since values occurring before this value. Format must be provided as GlideDateTime.
{ "updatedUntil" : "String" }
options.sequenceUntil String Deletes rows for clusters with insert_sequence values occurring before this value in the ML Cluster Detail [ml_cluster_detail] table. The sequence position starting point value is 1.
{ "sequenceUntil" : Number }
Table 4. Returns
Type Description
Number Number of rows deleted from the ML Cluster Detail [ml_cluster_detail] table.

Example

The following example shows how to delete rows for clusters with updated_since time preceding '2020-06-28 02:50:53'.

var mlSolution = sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

var mlSolutionVersion = mlSolution.getActiveVersion();

var options = {};
options.updatedUntil = '2020-06-28 02:50:53';

var results = mlSolutionVersion.deleteClusterAssignments(options);

gs.print("Number of deleted rows: "+results);

Output:

Number of deleted rows: 6417

Example

The following example shows how to delete rows for clusters with updated_since that are sequentially positioned prior to 1000.

var mlSolution = sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

var mlSolutionVersion = mlSolution.getActiveVersion();

var options = {};
options.sequenceUntil = 1000;

var results = mlSolutionVersion.deleteClusterAssignments(options);

gs.print("Number of deleted rows: "+results);

Output:

Number of deleted rows: 999

ClusteringSolutionVersion - getClusterAssignments(Object options)

Gets assignments for a clustering solution.

Example

The following example shows how to use the options object to filter clustering results.

var mlSolution = sn_ml.ClusteringSolutionStore.get("solution_name");

var mlSolutionVersion = mlSolution.getActiveVersion();

var options = {};
options.clusterId = 56;
options.topNPerCluster = 10;
options.updatedUntil = '2020-01-17 23:16:14'; 
options.updatedSince = '2020-01-17 23:16:13'; 
options.sequenceUntil = 1000; 
options.sequenceSince = 1100; 
options.limit = 100;

var results = mlSolutionVersion.getClusterAssignments(options)

gs.print(results);

Output:

[{"cluster_id":"1","rec_display_id":"Incident": "INC0014483","rec_sys_id":"04e33e7adb401300864adfea5e961900","group_by":"network"},
 {"cluster_id":"1","rec_display_id":"Incident": "INC0011133","rec_sys_id":"5bd23af2db401300864adfea5e96194d","group_by":"network"}]

ClusteringSolutionVersion - getClusterInfo(Object options)

Gets information for a specified clustering solution in the store. The purity measurement provides insights as a percentage for the clustering fields on which the purity is based.

Example

The following example shows how to set the options object parameter and print the filtered cluster results.

var mlSolution = sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

var mlSolutionVersion = mlSolution.getActiveVersion();

var options = {};
options.updatedSince = '2020-05-28 02:09:53'; 
options.updatedUntil = '2020-05-28 03:15:00';
options.sequenceSince = 1;
options.limit = 10;

var results = mlSolutionVersion.getClusterInfo(options);

gs.print(JSON.stringify(JSON.parse(results), null, 2));

Output:

[
  {
    "cluster_id": "1",
    "cluster_quality": "100",
    "cluster_size": "17",
    "purity": "",
    "insert_sequence": "8",
    "group_by": "VPN   Customer",
    "sys_updated_on": "2020-05-28 02:09:53",
    "cluster_concept": "vpn instance connection ldap user log unable usability tunnel"
  },
  {
    "cluster_id": "1",
    "cluster_quality": "100",
    "cluster_size": "10",
    "purity": "",
    "insert_sequence": "24",
    "group_by": "Live Feed",
    "sys_updated_on": "2020-05-28 02:09:53",
    "cluster_concept": "feed live user note work disable group default usability sort"
  },
  {
    "cluster_id": "1",
    "cluster_quality": "100",
    "cluster_size": "18",
    "purity": "",
    "insert_sequence": "40",
    "group_by": "Integrations",
    "sys_updated_on": "2020-05-28 02:09:53",
    "cluster_concept": "integrate usability certificate error"
  },
...
]

ClusteringSolutionVersion - getProperties()

Gets solution object properties and version number.

Table 9. Parameters
Name Type Description
None

Example

The following example gets properties of the active object version in the store.

// Get properties
var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering_solution');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getProperties()), null, 2));

Output:

*** Script: {
  "algorithmConfig": {
    "algorithm": "kmeans",
    "targetCoverage": "90"
  },
  "datasetProperties": {
    "tableName": "incident",
    "fieldNames": [
      "category",
      "short_description",
      "state",
      "description"
    ],
    "encodedQuery": "activeANYTHING"
  },
  "domainName": "global",
  "encoderProperties": {
    "datasetsProperties": [
      {
        "tableName": "incident",
        "fieldNames": [
          "assignment_group",
          "short_description",
          "description"
        ],
        "encodedQuery": "activeANYTHING"
      }
    ],
    "domainName": "global",
    "isActive": "true",
    "label": "my encoder definition",
    "name": "ml_x_snc_global_global_my_encoder_definition",
    "processingLanguage": "en",
    "stopwords": [
      "Default English Stopwords"
    ],
    "versionNumber": "1"
  },
  "groupByFieldName": "category",
  "inputFieldNames": [
    "short_description"
  ],
  "isActive": "true",
  "label": "clustering solution",
  "minRecordsPerCluster": 2,
  "name": "ml_x_snc_global_global_clustering_solution",
  "processingLanguage": "en",
  "stopwords": [
    "Default English Stopwords"
  ],
  "updateFrequency": "do_not_update",
  "versionNumber": "1"
}

ClusteringSolutionVersion - getStatus(Boolean includeDetails)

Gets training completion status.

Table 11. Parameters
Name Type Description
includeDetails Boolean Flag that indicates whether to return status details.
Valid values:
  • true: Return additional details.
  • false: Don't return additional details.

Default: False

Example

The following example shows a successful result with training complete.

// Get status
var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_cluster_solution');

gs.print(JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getStatus(true), null, 2)));

Output:

{
 "state":"solution_complete",
 "percentComplete":"100",
 "hasJobEnded":"true",
 "details":{"stepLabel":"Solution Complete"} // This information is only returned if getStatus(true);
}

Example

The following example shows an unsuccessful result with training complete.

// Get status
var solutionName = 'ml_x_snc_global_global_cluster_solution';
var mlSolution = sn_ml.ClusteringSolutionStore.get(solutionName);
var trainingStatus = mlSolution.getLatestVersion().getStatus();

gs.print(JSON.stringify(JSON.parse(trainingStatus), null, 2));

Output:

{
 "state":"solution_error",
 "percentComplete":"100",
 "hasJobEnded":"true"
}

ClusteringSolutionVersion - getTopNPurityInfo(Object options)

Gets the top purity results for a clustering solution. The purity measurement provides insights as a percentage for the clustering fields on which the purity is based.

Example

The following example shows how to get the top two purity results for the category field in specific cluster solutions.

var solution = new GlideRecord('ml_solution');
solution.addQuery('sys_id', '<clustering_solution_sys_id>');
solution.addQuery('active', 'true');
solution.query();

while (solution.next()) {

  var options = {};
  options.clusterIds = ['1', '3', '5'];
  options.purityFields = ['category'];
  options.topN = '2';
  options.topNFields = '2';

  var clustering = new sn_ml.ClusteringSolutionVersion(solution);
  var results = clustering.getTopNPurityInfo(options);

  gs.info(results);
}

Output displays purity insights based on the settings provided in the options parameter.

{"1":[{"category":[{"network":"99.96"},{"inquiry":"0.04"}]}],"3":[{"category":[{"Systems Engineering":"100"}]}],
"5":[{"category":[{"Security":"100"}]}]}

ClusteringSolutionVersion - getUpdateStatus()

Gets the status of the most recent clustering solution update job.

Table 15. Parameters
Name Type Description
None
Table 16. Returns
Type Description
String State of the clustering solution update.
States:
  • Configuration or network error
  • Error while updating solution
  • Fetching files for updating
  • Preparing data
  • Unauthorized
  • Update complete
  • Updating is cancelled
  • Updating request received
  • Updating request timed out
  • Updating solution
  • Uploading
  • Waiting

Example

The following example shows how to get the update status of a clustering solution.

var myCluster = new sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

gs.print(JSON.stringify(myCluster.getActiveVersion().getUpdateStatus()));

Output:

"Update Complete"

ClusteringSolutionVersion - getVersionNumber()

Gets the version number of a solution object.

Table 17. Parameters
Name Type Description
None
Table 18. Returns
Type Description
String Version number.

Example

The following example shows how to get a version number.

// Get version number
var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_x_snc_global_global_clustering_solution');

gs.print("Version number: "+JSON.stringify(JSON.parse(mlSolution.getActiveVersion().getVersionNumber()), null, 2));

Output:

Version number: 1

ClusteringSolutionVersion - predict(Object input, Object options)

Gets the input data for a prediction.

Example

The following example shows how to display prediction results for a predict() method that takes a GlideRecord by sys_id for input and includes optional parameters to restrict to top three results and exclude the threshold value.

var mlSolution = sn_ml.ClusteringSolutionStore.get('ml_incident_categorization');

// single GlideRecord input
var input = new GlideRecord("incident");
input.get("<sys_id>");

// configure optional parameters
var options = {};
options.top_n = 3;
options.apply_threshold = false;

var results = mlSolution.getVersion(1).predict(input, options);
// pretty print JSON results
gs.print(JSON.stringify(JSON.parse(results), null, 2));
{
  "<sys_id/gr>": [
    {
      "confidence": 62.10782320780268,
      "threshold": 20.36,
      "predictedValue": "Clone Issues",
      "predictedSysId": ""
    },
    {
      "confidence": 6.945237375770391,
      "threshold": 16.63,
      "predictedValue": "Instance Administration",
      "predictedSysId": ""
    },
    {
      "confidence": 5.321061076300759,
      "threshold": 23.7,
      "predictedValue": "Administration",
      "predictedSysId": ""
    }
  ]
}

Example

The following example shows how to display prediction results for a predict() method that takes an array of field names as key-value pairs for input and includes optional parameters to restrict to top three results and exclude the threshold value.

var mlSolution = sn_ml.ClusteringSolutionStore.get("ml_incident_categorization");

// key-value pairs input
var input = [{"short_description":"my email is not working"}, {short_description:"need help with password"}];

// configure optional parameters
var options = {};
options.top_n = 3;
options.apply_threshold = false;
var results = mlSolution.predict(input, options);

// pretty print JSON results
gs.print(JSON.stringify(JSON.parse(results), null, 2));
{
  "1": [
    {
      "confidence": 37.5023032262591,
      "threshold": 10.72,
      "predictedValue": "Authentication",
      "predictedSysId": ""
    },
    {
      "confidence": 24.439964862166583,
      "threshold": 23.7,
      "predictedValue": "Administration",
      "predictedSysId": ""
    },
    {
      "confidence": 11.736320486031047,
      "threshold": 100,
      "predictedValue": "Security",
      "predictedSysId": ""
    }
  ],
  "2": [
    {
      "confidence": 99,
      "threshold": 17.77,
      "predictedValue": "Email",
      "predictedSysId": ""
    },
    {
      "confidence": 3.182137005157543,
      "threshold": 10.72,
      "predictedValue": "Authentication",
      "predictedSysId": ""
    },
    {
      "confidence": 2.8773826570713514,
      "threshold": -1,
      "predictedValue": "Email (I/f)",
      "predictedSysId": ""
    }
  ]
}

ClusteringSolutionVersion - submitUpdateJob(Object options)

Submits clustering update jobs with options to narrow results to a specific table and filter for matching records.

Table 21. Parameters
Name Type Description
options Object JavaScript object containing options on which to base a clustering solution update.
{
        "filter" : "String",
        "table" : "String"
    }
options.filter String Encoded query string in standard Glide format. See Encoded query strings. Enables running an update job based on the filter provided.
options.table String Name of the table on which to run an update job.
Table 22. Returns
Type Description
None

Example

The following example shows how to submit an update job.

var myCluster = new sn_ml.ClusteringSolutionStore.get("ml_x_snc_global_global_clustering_solution");

var options = {"filter" : "precision", "table" : "incident"};

myCluster.getActiveVersion().submitUpdateJob(options);