DecisionMaker class

MediaPipe Task that performs semantic decision making.

Signature:

export declare class DecisionMaker extends TaskRunner 

Properties

Property Modifiers Type Description
contextWindow number Maximum token window supported by the active model/session.
contextUsage number Estimated token usage of the active schema and most recent evaluation.

Methods

Method Modifiers Description
createFromOptions(wasmFileset, options) static Initializes the Wasm runtime and creates a new Decision based on options.
createFromModelPath(wasmFileset, modelAssetPath, backendType, maxNumTokens) static Initializes the Wasm runtime and creates a new Decision from model asset path.
createFromModelBuffer(wasmFileset, modelAssetBuffer, backendType, maxNumTokens) static Initializes the Wasm runtime and creates a new Decision from model buffer.
setSchema(schema) Updates the session-bound ClassifierSchema used by classify().
prewarm(schema) Prewarms the underlying engine KV/prefix cache for the given schema.
measureContextUsage(input, options) Estimates the total token usage for evaluating input (and optional per-call context) against the session schema.
setOptions(options) Sets the options for the DecisionMaker and initializes the underlying engine. Options cannot be updated once the engine has been created.
evaluateBoolean(text, question) Evaluates a Boolean Predicate condition against input text or multimodal context.
evaluateChoice(text, question) Evaluates a Categorical Choice against input text or multimodal context.
evaluateScore(text, question) Evaluates an Ordinal Score rubric against input text or multimodal context.
evaluate(input, schema, options) Evaluates a multi-question ClassifierSchema against input and returns a unified ClassifierResult record keyed by question id (compatible with window.Classifier).
evaluateBatch(inputs, schema, options) Evaluates a multi-question ClassifierSchema across a batch of inputs.
classify(input, options) Evaluates input against the session-bound ClassifierSchema configured via DecisionMakerOptions or setSchema().
evaluateBooleanBatch(texts, question, sharedPrefix) Evaluates a Boolean Predicate condition against a batch of input texts (with an optional sharedPrefix for candidate batching).
evaluateChoiceBatch(texts, question, sharedPrefix) Evaluates a Categorical Choice against a batch of input texts (with an optional sharedPrefix for candidate batching).
evaluateScoreBatch(texts, question, sharedPrefix) Evaluates an Ordinal Score rubric against a batch of input texts (with an optional sharedPrefix for candidate batching).
close() Closes the DecisionMaker and releases the native engine and model memory.

DecisionMaker.contextWindow

Maximum token window supported by the active model/session.

Signature:

get contextWindow(): number;

DecisionMaker.contextUsage

Estimated token usage of the active schema and most recent evaluation.

Signature:

get contextUsage(): number;

DecisionMaker.createFromOptions()

Initializes the Wasm runtime and creates a new Decision based on options.

Signature:

static createFromOptions(wasmFileset: WasmFileset, options: DecisionMakerOptions): Promise<DecisionMaker>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
options DecisionMakerOptions The options for the DecisionMaker. Note that either a path to the model or the model itself needs to be provided (via baseOptions).

Returns:

Promise<DecisionMaker>

DecisionMaker.createFromModelPath()

Initializes the Wasm runtime and creates a new Decision from model asset path.

Signature:

static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string, backendType?: number, maxNumTokens?: number): Promise<DecisionMaker>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetPath string The path to the model asset.
backendType number The backend type (0=AUTO, 1=ENCODER, 2=DIRECT_LOGIT, 3=EMBEDDING).
maxNumTokens number The maximum number of tokens in prompt context.

Returns:

Promise<DecisionMaker>

DecisionMaker.createFromModelBuffer()

Initializes the Wasm runtime and creates a new Decision from model buffer.

Signature:

static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader, backendType?: number, maxNumTokens?: number): Promise<DecisionMaker>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetBuffer Uint8Array | ReadableStreamDefaultReader An array or a stream containing a binary representation of the model.
backendType number The backend type (0=AUTO, 1=ENCODER, 2=DIRECT_LOGIT, 3=EMBEDDING).
maxNumTokens number The maximum number of tokens in prompt context.

Returns:

Promise<DecisionMaker>

DecisionMaker.setSchema()

Updates the session-bound ClassifierSchema used by classify().

Signature:

setSchema(schema: ClassifierSchema): void;

Parameters

Parameter Type Description
schema ClassifierSchema The schema to bind to this session.

Returns:

void

DecisionMaker.prewarm()

Prewarms the underlying engine KV/prefix cache for the given schema.

Signature:

prewarm(schema: ClassifierSchema): Promise<void>;

Parameters

Parameter Type Description
schema ClassifierSchema The schema whose shared prefix should be prewarmed.

Returns:

Promise<void>

DecisionMaker.measureContextUsage()

Estimates the total token usage for evaluating input (and optional per-call context) against the session schema.

Signature:

measureContextUsage(input: string, options?: ClassifierEvaluateOptions): Promise<number>;

Parameters

Parameter Type Description
input string The input text to be evaluated.
options ClassifierEvaluateOptions Optional per-call evaluation options.

Returns:

Promise<number>

DecisionMaker.setOptions()

Sets the options for the DecisionMaker and initializes the underlying engine. Options cannot be updated once the engine has been created.

Signature:

setOptions(options: DecisionMakerOptions): Promise<void>;

Parameters

Parameter Type Description
options DecisionMakerOptions The options for the DecisionMaker.

Returns:

Promise<void>

DecisionMaker.evaluateBoolean()

Evaluates a Boolean Predicate condition against input text or multimodal context.

Signature:

evaluateBoolean(text: string | DecisionContextInput, question: BooleanQuestion): Promise<BooleanResult>;

Parameters

Parameter Type Description
text string | DecisionContextInput The input text or multimodal context to be evaluated.
question BooleanQuestion The boolean question to evaluate.

Returns:

Promise<BooleanResult>

DecisionMaker.evaluateChoice()

Evaluates a Categorical Choice against input text or multimodal context.

Signature:

evaluateChoice(text: string | DecisionContextInput, question: ChoiceQuestion): Promise<ChoiceResult>;

Parameters

Parameter Type Description
text string | DecisionContextInput The input text or multimodal context to be evaluated.
question ChoiceQuestion The choice question to evaluate.

Returns:

Promise<ChoiceResult>

DecisionMaker.evaluateScore()

Evaluates an Ordinal Score rubric against input text or multimodal context.

Signature:

evaluateScore(text: string | DecisionContextInput, question: ScoreQuestion): Promise<ScoreResult>;

Parameters

Parameter Type Description
text string | DecisionContextInput The input text or multimodal context to be evaluated.
question ScoreQuestion The score question to evaluate.

Returns:

Promise<ScoreResult>

DecisionMaker.evaluate()

Evaluates a multi-question ClassifierSchema against input and returns a unified ClassifierResult record keyed by question id (compatible with window.Classifier).

Signature:

evaluate(input: string | DecisionContextInput, schema: ClassifierSchema, options?: ClassifierEvaluateOptions): Promise<ClassifierResult>;

Parameters

Parameter Type Description
input string | DecisionContextInput The input text or multimodal context to be evaluated.
schema ClassifierSchema The schema containing the questions to evaluate.
options ClassifierEvaluateOptions Optional per-call evaluation options.

Returns:

Promise<ClassifierResult>

DecisionMaker.evaluateBatch()

Evaluates a multi-question ClassifierSchema across a batch of inputs.

Signature:

evaluateBatch(inputs: Array<string | DecisionContextInput>, schema: ClassifierSchema, options?: ClassifierEvaluateOptions): Promise<ClassifierResult[]>;

Parameters

Parameter Type Description
inputs Array The input texts or multimodal contexts to be evaluated.
schema ClassifierSchema The schema containing the questions to evaluate.
options ClassifierEvaluateOptions Optional per-call evaluation options.

Returns:

Promise<ClassifierResult[]>

DecisionMaker.classify()

Evaluates input against the session-bound ClassifierSchema configured via DecisionMakerOptions or setSchema().

Signature:

classify(input: string | DecisionContextInput, options?: ClassifierEvaluateOptions): Promise<ClassifierResult>;

Parameters

Parameter Type Description
input string | DecisionContextInput The input text or multimodal context to be evaluated.
options ClassifierEvaluateOptions Optional per-call evaluation options.

Returns:

Promise<ClassifierResult>

DecisionMaker.evaluateBooleanBatch()

Evaluates a Boolean Predicate condition against a batch of input texts (with an optional sharedPrefix for candidate batching).

Signature:

evaluateBooleanBatch(texts: string[], question: BooleanQuestion, sharedPrefix?: string): Promise<BooleanResult[]>;

Parameters

Parameter Type Description
texts string[] The input texts to be evaluated.
question BooleanQuestion The boolean question to evaluate.
sharedPrefix string An optional prefix shared by all inputs.

Returns:

Promise<BooleanResult[]>

DecisionMaker.evaluateChoiceBatch()

Evaluates a Categorical Choice against a batch of input texts (with an optional sharedPrefix for candidate batching).

Signature:

evaluateChoiceBatch(texts: string[], question: ChoiceQuestion, sharedPrefix?: string): Promise<ChoiceResult[]>;

Parameters

Parameter Type Description
texts string[] The input texts to be evaluated.
question ChoiceQuestion The choice question to evaluate.
sharedPrefix string An optional prefix shared by all inputs.

Returns:

Promise<ChoiceResult[]>

DecisionMaker.evaluateScoreBatch()

Evaluates an Ordinal Score rubric against a batch of input texts (with an optional sharedPrefix for candidate batching).

Signature:

evaluateScoreBatch(texts: string[], question: ScoreQuestion, sharedPrefix?: string): Promise<ScoreResult[]>;

Parameters

Parameter Type Description
texts string[] The input texts to be evaluated.
question ScoreQuestion The score question to evaluate.
sharedPrefix string An optional prefix shared by all inputs.

Returns:

Promise<ScoreResult[]>

DecisionMaker.close()

Closes the DecisionMaker and releases the native engine and model memory.

Signature:

close(): void;

Returns:

void