PredictFromModel
Returns the predicted value from a trained regression model for the specified text embedding vector.
Format
PredictFromModel ( modelName ; v1 )
Parameters
modelName
- any text expression that specifies the name of a trained regression model that has been loaded into memory.
v1
- any text expression, field, or container field that contains the input features for prediction. Can be provided as a JSON array (for example, [1.2, 3.4, 5.6]
) or as binary container data containing embedding vectors.
Data type returned
number
Originated in version
22.0
Description
PredictFromModel generates numerical predictions using regression models that have been trained and loaded with the Configure Regression Model script step. The function takes input features (which can be embedding vectors) and returns a single numerical prediction based on the patterns derived during model training.
Before using this function, you must:
-
Train a regression model using the Configure Regression Model script step.
-
Ensure the model is loaded in memory. Models remain loaded until explicitly unloaded or the FileMaker session ends.
-
Provide input features that match the same structure and dimensionality as the training data used to create the model.
The v1
parameter accepts input features in two formats:
-
Text containing a JSON array of numerical values, such as
[1.2, 3.4, 5.6, 7.8]
. This format is human-readable and suitable for simple use cases. The JSON array can also consist of an embedding vector generated by an AI model. -
An embedding vector stored as binary container data. This format typically provides better performance for large-scale operations and is the preferred format when working with an embedding vector generated by an AI model.
Notes
-
Input features in
v1
must have the same number of dimensions and be in the same order as the training data used to create the model. -
To use AI models to generate embedding vectors to use for v1, you can use the Insert Embedding script step, Insert Embedding in Found Set script step, or the GetEmbedding function.
-
Using binary container data for embedding vectors generally provides better performance than JSON arrays, especially for high-dimensional feature vectors.
-
Model names are case-sensitive and must match exactly the name of the model loaded using the Configure Regression Model script step.
-
Models remain in memory until explicitly deleted, so multiple predictions can be made efficiently without reloading.
-
The function returns "?" if:
-
The specified model name doesn't exist or isn't currently loaded in memory.
-
The input features have incorrect dimensions or format compared to the model's training data.
-
Example 1
An expression that makes a simple prediction using the house price model trained in Example 1 in Configure Regression Model. The input features are for square footage, bedrooms, and age.
PredictFromModel ( "HousePriceModel" ; "[1600, 3, 20]" )
Returns a predicted house price based on 1600 square feet, 3 bedrooms, and 20 years of age. A possible returned value is 256.96153846153845279 (in the same price units as the target values used in the training data).
Example 2
Predicts a customer's star rating based on the text of their review using the model trained in Example 2 in Configure Regression Model. The script asks the user to enter a review ($reviewInput), configures an AI account, then uses the account to get text embedding vectors for $reviewInput. Next, it loads the regression model stored in the global field Reviews::ReviewModel, then displays the predicted rating using the loaded model "ReviewModel" and the embedding vector for the user's review ($reviewEmbedding). When done, the script unloads the model from memory.
Show Custom Dialog ["Enter Your Review"; $reviewInput ]
Configure AI Account [ Account Name: "AI_Model_Server" ; Model Provider: Custom ; Endpoint: "https://myserver.example.com:8080/" ; Verify SSL Certificates ; API key: Global::API_Key ]
Insert Embedding [ Account Name: "AI_Model_Server" ; Embedding Model: "all-MiniLM-L12-v2" ; Input: $reviewInput ; Target: $reviewEmbedding ]
Configure Regression Model [ Action: Load Model ; Model Name: "ReviewModel" ; Load Model From: Reviews::ReviewModel ]
Show Custom Dialog [ "Predicted Rating"; PredictFromModel ( "ReviewModel" ; $reviewEmbedding ) ]
Configure Regression Model [ Action: Unload Model ; Model Name: "ReviewModel" ]
A possible predicted rating for a positive review is 4.8700974666666665414 for target values used in training that range from 1 to 5.