Predictions

Retrieve real-time scores prediction for a machine learning use case.

Components of AI Accelerator Predictions API 

The components that make up the AI Accelerator real-time scoring API are:

  • Configuration Resolution
  • Feature Extractor
  • Scorer
  • DB Writer

Configuration Resolution

For each API request, the API resolves the configuration values at run time in the following order:

  • API request (highest priority)
  • Admin configurations in setup BPOs. See AI Accelerator.
  • Use case configuration file setting

Feature Extractor

This component is applicable to only those use cases where it’s necessary to derive or calculate some features during run time. Just to clarify, features are the inputs to an ML model.

As an example, let’s consider an ML use case that predicts the price of a real estate property. To do so, the ML model requires features, such as the property’s square feet area, carpet area, location, number of bedrooms, construction year, and construction age.

Say all these features are available in the property’s record except the construction age feature. In this case, the API invokes Feature Extractor to calculate the construction age in runtime by subtracting the construction year feature from the current year.

Scorer

Scorer accepts features and uses the Einstein Discovery Predict API to interact with the ED platform for scoring the records.

DB Writer

If you configure an ML use case for persistence, DB Writer persists the features, scores, and insights in the specified object and as per the specified field mapping in the AIUsecaseFieldMapping object.

The AI Accelerator Predictions API returns the following output components:

  • A single prediction score per record, rawdata, recordoverrides, extractedrawdata, or extractedrecordoverrides.
  • Details on how the score was arrived at through a maximum of three prediction insights, which helps end users understand the impact of various features on the scores.
  • Prediction improvements to improve the score.

Resource 

1/connect/aiaccelerator/predictions

Resource Example 

1https://{yourInstance}.salesforce.com/services/data/vXX.X/connect/​​​aiaccelerator/predictions

{yourInstance} is the domain name of your Salesforce instance.

Available Version 

55.0

Requires Chatter 

No

HTTP Methods 

POST

Request Body for POST 

JSON Example 

An example of inputType as Records.

1{
2  "usecaseDevname": "AIUsecaseDefinitionIdentifier",
3  "predictionDefinition": "PredictionDefinitionIdentifier",
4  "inputType": "Records",
5  "records": {
6    "wrappedList": [
7      "a00x0000000CHa0AAG"
8    ]
9  },
10  "insightsSettings": {
11    "insightsSettings": {
12      "maxSuggestionCount": 1,
13      "maxInsights": 1,
14      "suggestionImpactMinimumPct": 0
15    }
16  },
17  "insightColumnMap": {
18    "columnMap": {
19      "INSIGHT1.Name": "Demo__c.InsightName1Override__c",
20      "INSIGHT1.Value": "Demo__c.InsightValue1__c",
21      "INSIGHT1.Impact": "Demo__c.InsightImpact1__c"
22    }
23  },
24  "suggestionColumnMap": {
25    "columnMap": {
26      "SUGGESTION1.Name": "Demo__c.RecommendationName1__c",
27      "SUGGESTION1.Value": "Demo__c.RecommendationValue1__c",
28      "SUGGESTION1.Impact": "Demo__c.RecommendationImpact1Override__c"
29    }
30  },
31..”scorePersistenceColumn”:”Demo__c.Score__c”,
32..”enableInsightPersistence”:true,
33  "enableScorePersistence": true,
34..”enableSuggestionPersistence”:true,
35  "async": false
36}

An example of inputType as RawData.

1{
2  "usecaseDevname": "AIUsecaseDefinitionIdentifier",
3  "predictionDefinition": "PredictionDefinitionIdentifier",
4  "inputType": "RawData",
5  "columnNames": {
6    "wrappedList": [
7      "corp_year_week__c",
8      "sap_source_id__c",
9      "sap_ppg_id__c",
10      "sales_units__c"
11    ]
12  },
13  "rawData": {
14    "rawData": [
15      {
16        "rawDataInputWrap": {
17          "rawDataInput": [
18            "202016",
19            "0YQx0000000CaS8GAK",
20            "01tx00000006j2DAAQ",
21            "20"
22          ]
23        }
24      },
25      {
26        "rawDataInputWrap": {
27          "rawDataInput": [
28            "202016",
29            "0YQx0000000CaS8GAK",
30            "01tx00000006j2DAAQ",
31            "20000"
32          ]
33        }
34      }
35    ]
36  },
37  "featureColumnMap": {
38    "columnMap": {
39      "corp_year_week__c": "Demo__c.YearWeekFeature__c",
40      "sap_source_id__c": "Demo__c.StoreIdFeature__c",
41      "sap_ppg_id__c": "Demo__c.ProductIdFeature__c",
42      "sales_units__c": "Demo__c.SalesUnitsFeatureOverride__c"
43    }
44  },
45  "enableFeaturePersistence": true
46}

An example of inputType as RecordOverrides.

1{
2  "usecaseDevname": "AIUsecaseDefinitionIdentifier",
3  "predictionDefinition": "PredictionDefinitionIdentifier",
4  "inputType": "RecordOverrides",
5  "records": {
6    "wrappedList": [
7      "a00x0000000CHa0AAG"
8    ]
9  },
10  "columnNames": {
11    "wrappedList": [
12      "corp_year_week__c",
13      "sap_source_id__c",
14      "sap_ppg_id__c",
15      "sales_units__c"
16    ]
17  },
18  "rawData": {
19    "rawData": [
20      {
21        "rawDataInputWrap": {
22          "rawDataInput": [
23            "202016",
24            "0YQx0000000CaS8GAK",
25            "01tx00000006j2DAAQ",
26            "20"
27          ]
28        }
29      },
30      {
31        "rawDataInputWrap": {
32          "rawDataInput": [
33            "202016",
34            "0YQx0000000CaS8GAK",
35            "01tx00000006j2DAAQ",
36            "20000"
37          ]
38        }
39      }
40    ]
41  }
42}

An example of inputType as ExtractedRawData.

1{
2  "usecaseDevname": "AIUsecaseDefinitionIdentifier",
3  "predictionDefinition": "PredictionDefinitionIdentifier",
4  "inputType": "ExtractedRawData",
5..”featureExtractorDevName”: “featureExtractorIdentifier”,
6  "featureExtractionParameters": {
7    "featureExtractionParameters": [
8      {
9        "featureExtractionParametersMapValue": {
10          "recordId": "01tx00000006j2DAAQ1",
11          "rawData": {
12            "corp_year_week__c": "202016"
13          }
14        }
15      }
16    ]
17  },
18  "enableFeaturePersistence": true
19}

An example of inputType as ExtractedRecordOverrides.

1{
2  "usecaseDevname": "AIUsecaseDefinitionIdentifier",
3  "predictionDefinition": "PredictionDefinitionIdentifier",
4  "inputType": "ExtractedRecordOverrides",
5  "records": {
6    "wrappedList": [
7      "a00x0000000CHa0AAG"
8    ]
9  },
10..”featureExtractorDevName”: “featureExtractorIdentifier”,
11  "featureExtractionParameters": {
12    "featureExtractionParameters": [
13      {
14        "featureExtractionParametersMapValue": {
15          "recordId": "01tx00000006j2DAAQ1"
16        }
17      }
18    ]
19  }
20}

Properties 

NameTypeDescriptionRequired or OptionalAvailable Version
asyncBooleanIndicates whether the execution mode is async (true) or not (false).Optional55.0
columnNamesString[]Comma-separated list of column names representing the columns that the model analyzes. These are the features that are inputs to the model for predicting the scores.Optional
Note: This field is required when type is rawdata or recordOverrides.
55.0
enableFeaturePersistenceBooleanIndicates whether you want to persist the features (true) or not (false).Optional
Note: This field is required only if raw data or when features are extracted.
55.0
enableInsightPersistenceBooleanIndicates whether you want to persist the insights (true) or not (false).
Note: The enableScorePersistence field must be enabled to persist insights.
Optional55.0
enableScorePersistenceBooleanIndicates whether you want to persist the prediction scores (true) or not (false).Optional55.0
enableSuggestionPersistenceBooleanIndicates whether you want to persist the suggestions (true) or not (false).
Note: The enableScorePersistence field must be enabled to persist suggestions.
Optional55.0
enrichModelClassificationBooleanIndicates whether you want to retrieve the classification model type and the classification threshold (true) or not (false).Optional55.0
enrichModelFeaturesBooleanIndicates whether you want to retrieve the model feature details, including label and data type (true) or not (false).Optional55.0
enrichPredictionDefinitionBooleanIndicates whether you want to retrieve the prediction definition label (true) or not (false).Optional55.0
featureColumnMapMap<String, String>Represents the map that contains which features must be persisted and where they must be persisted. The key-value pair must contain:
  • key—Feature name
  • value—ResponseObjects (configured in the Admin UI setup).FieldName
Optional55.0
featureExtractorDevNameStringThe API name of the feature extractor record.Optional
Note: This field is required when the usecaseModel doesn’t have a default Feature Extractor and the input type is ExtractedRawData or ExtractedRecordOverrides.
55.0
featureExtractionParametersFeature Extraction Parameters Field Map Value[]Represents the input parameters that are required by the Feature Extractor to extract the features that a model requires to make the prediction. Supports a maximum of 200 records.Optional
Note: This field is required when the input type is ExtractedRawData or ExtractedRecordOverrides.
55.0
featureExtractorIdStringThe ID of the feature extractor record from the AIFeatureExtractor object. The specified feature extractor is used to extract the features for the prediction.
For information on the custom feature extractor interface implementation, see CustomFeatureExtractor Interface.
Optional55.0
historyReferencePointStringRepresents a reference point for a comparison between current and previous prediction scores.Optional55.0
inputTypeStringThe type of input used to make the prediction. Supports a maximum of 200 records.
Possible values are:
  • Records—All the features for a model are present in the Salesforce database.
  • RawData—All the features for a model are provided in the API request itself.
  • RecordOverrides—The API reads a part of the features for the model from the Salesforce database by using the specified record Id. The remaining features are provided in the API request as raw data.
  • ExtractedRawData—The API computes some or all the features for the model at runtime using the configured Feature Extractor, others can be passed as raw data in the API request.
  • ExtractedRecordOverrides—The API computes some features for the model at run time by using the configured Feature Extractor. For the remaining features, the API refers to the Salesforce database through the specified record ID.
Required55.0
insightColumnMapMap<String, String>Represents the map that contains which insight’s Name/Value must be persisted, and to which object they must be persisted. The key-value pair must contain:
  • key—INSIGHT1.Name / INSIGHT1.Value (up to maximum of 3 insights Name/Value)
  • value—ResponseObjects (configured in the Admin UI setup).FieldName
Optional55.0
insightsSettingsMap<String, Integer>A map for configuring insight settings.
Here are the settings that contribute to the prediction score:
  • maxInsights—Maximum number of insights that you want the machine learning model to generate.
  • maxSuggestionCount—Maximum number of suggestions that you want the machine learning model to generate.
  • suggestionImpactMinimumPct—Minimum eligible percentage for improving the prediction score based on suggestions.

For more information, see Define Maximum Suggestions and Insights in the AI Accelerator Admin Guide.
Optional55.0
predictionDefinitionStringThe developer name or API name from the DiscoveryGoal object.Required55.0
rawDataRaw Data Input Wrap[]A two-dimensional array of row values in which each row is a comma-separated list of values for features provided in columnNames. Supports a maximum of 200 records.Optional
Note: This field is required when the input type is RawData or RecordOverrides.
55.0
recordsString[]The IDs of the Salesforce record that is used as input features for model to make the prediction.Optional
Note: This field is required when the input type is Records, RecordOverrides, or ExtractedRecordOverrides.
55.0
scorePersistenceColumnStringThe name and value of the score that must be persisted, and to which object it must be persisted. The valid format is ResponseObject.FieldName.Optional.
Note: This field is required when enableScorePersistence is set to true. If enableScorePersistence is true and the value isn’t specified, the score column map from the setup page is used by default.
55.0
suggestionColumnMapMap<String, String>Represents the map that contains which suggestions Name/Value must be persisted, and to which object they must be persisted. The key-value pair must contain:
  • key—SUGGESTION1.Name / SUGGESTION1.Value (maximum of 5 suggestions Name/Value)
  • value—ResponseObjects (configured in the Admin UI setup).FieldName
Optional55.0
usecaseDefinitionStringThe ID of the usecase definition record from the AIUsecaseDefinition object.Optional55.0
usecaseDevnameStringThe API name of the usecase definition record.Required55.0

Response Body for POST 

Prediction Output