Machine LearningQuery pipeline stage configuration specifications
The Machine Learning query pipeline stage uses a trained machine learning model to analyze a field or fields of a Request object and stores the results of analysis in a new field added to either the Request or the Context object.
In order to use the Machine Learning Stage, you must train a machine learning model. There are two different ways to train a model:
-
Use a Managed Fusion job that trains a model, like
This stage requires that you use JavaScript to construct a model input object from the Request and/or Context. This JavaScript is defined in the "Model input transformation script" property. This script must construct a HashMap containing fields and values to be sent to the model. The field names and values will depend on the input schema of the model.
Value types supported are:
-
String
-
Double
-
String[]
-
double[]
-
List<String>
-
List<Number>
The JavaScript interpreter that executes the script will have the following variables available in scope:
The last line of the script must be a reference to the HashMap object you created.
Example 1: Single string parameter from request to modelInput HashMap
var modelInput = new java.util.HashMap()
modelInput.put("input_1", request.getFirstParam("q"))
modelInput
Example 2: List of strings from request to modelInput HashMap
var modelInput = new java.util.HashMap()
modelInput.put("input_1", request.getParam("q")) // request.getParam returns a Collection
modelInput
Example 3: List of numeric values from request to modelInput HashMap
var modelInput = new java.util.HashMap()
var list = new java.util.ArrayList()
list.add(Double.parseDouble(request.getFirstParam("numeric_1")))
list.add(Double.parseDouble(request.getFirstParam("numeric_2")))
modelInput.put("input_1", list)
modelInput
Similarly, you will need to use JavaScript to store the predictions into the Request and/or Context from the model output object. The model output object is a HashMap containing fields and values produced by the model.
The JavaScript interpreter that executes the script will have the following variables available in scope:
Example: Place predictedLabel (string) on request
request.putSingleParam("sentiment", modelOutput.get("predictedLabel"))
Lucidworks offers free training to help you get started. The Course for Intro to Machine Learning in Fusion focuses on using machine learning to to infer the goals of customers and users in order to deliver a more sophisticated search experience: Visit the LucidAcademy to see the full training catalog. |
Query pipeline stage condition examples
Stages can be triggered conditionally when a script in the Condition field evaluates to true. Some examples are shown below.
Run this stage only for mobile clients:
params.deviceType === "mobile"
Run this stage when debugging is enabled:
params.debug === "true"
Run this stage when the query includes a specific term:
params.q && params.q.includes("sale")
Run this stage when multiple conditions are met:
request.hasParam("fusion-user-name") && request.getFirstParam("fusion-user-name").equals("SuperUser");
!request.hasParam("isFusionPluginQuery")
The first condition checks that the request parameter "fusion-user-name" is present and has the value "SuperUser". The second condition checks that the request parameter "isFusionPluginQuery" is not present.