Melange
API ReferenceAndroid

ZeticMLangeDecisionModel

API reference for structured decision inference on Android.

This page describes the API planned for ZeticMLange Android 1.13.0.

ZeticMLangeDecisionModel loads a Decision model using your personal key and model name. The server selects the compatible package and run configuration for the device. Unlike text generation, Decision inference returns typed answers to structured questions.

Load a model

import com.zeticai.mlange.core.model.decision.DecisionInitOption
import com.zeticai.mlange.core.model.decision.DecisionModelMode
import com.zeticai.mlange.core.model.decision.ZeticMLangeDecisionModel

ZeticMLangeDecisionModel(
    context: Context,
    personalKey: String,
    name: String,
    version: Int? = null,
    modelMode: DecisionModelMode = DecisionModelMode.RUN_AUTO,
    cacheHandlingPolicy: ModelCacheHandlingPolicy = ModelCacheHandlingPolicy.REMOVE_OVERLAPPING,
    initOption: DecisionInitOption = DecisionInitOption(),
    onDownload: ((Float) -> Unit)? = null,
)

name is in account_name/project_name form; version = null selects the default version. The callback reports download progress from 0.0 to 1.0. Loading includes network, cache, and native work and must run off the main thread. A ZeticMLangeException is thrown on the main thread or if no selected candidate can open.

DecisionInitOption(nCtx = 2048) is an example context setting, not a universal model limit. Its default nCtx = 0 uses the package's maximum context when present, otherwise the engine default. A larger context can use more memory; the package and backend determine supported limits. Backend selection chooses the run configuration.

Evaluate questions

import com.zeticai.mlange.core.model.decision.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

val result = withContext(Dispatchers.IO) {
    val model = ZeticMLangeDecisionModel(
        context = context,
        personalKey = PERSONAL_KEY,
        name = "account_name/project_name",
        initOption = DecisionInitOption(nCtx = 2048),
    )
    try {
        val request = ZeticMLangeDecisionRequest(
            state = ZeticMLangeDecisionValue.StringValue(
                "I was charged twice. Please refund one charge."
            ),
            questions = linkedMapOf(
                "refund" to ZeticMLangeNoulQuestion(
                    instructions = "Is the customer asking for a refund?"
                ),
                "team" to ZeticMLangeChoiceQuestion(
                    instructions = "Which team should handle this?",
                    criteria = linkedMapOf(
                        "billing" to ZeticMLangeDecisionValue.StringValue("Charges and refunds"),
                        "technical" to ZeticMLangeDecisionValue.StringValue("App issues"),
                    ),
                ),
            ),
        )
        model.evaluate(request)
    } finally {
        model.close()
    }
}

val refund = result.answers["refund"] as? ZeticMLangeDecisionAnswer.Noul
val team = result.answers["team"] as? ZeticMLangeDecisionAnswer.Choice

evaluate(request) also must run off the main thread. The request's state is a typed value (string, number, boolean, object, array, or null), and questions maps identifiers to questions:

QuestionCriteriaAnswer
ZeticMLangeNoulQuestionOptional true and false criteriaNoul.noul, probability of true
ZeticMLangeChoiceQuestionMap of option keys to typed valuesChoice.choice, confidence and per-option probabilities
ZeticMLangeScoreQuestionOrdered list of typed valuesScore.score, confidence, legend and probabilities

For llama.cpp D1 models, choice/score confidence is the probability of the selected answer, and score is the median level; other engines can report expected level with a different confidence definition. result.usage is optional and, when available, contains input token count, truncation, and stage timings.

Optional media and lifecycle

ZeticMLangeDecisionRequest.media accepts one ZeticMLangeDecisionImage(rgb, width, height) or ZeticMLangeDecisionAudio(samples, sampleRateHz). Images are packed RGB bytes with length width * height * 3; audio requires a 16 kHz sample rate. Check model.capabilities.imageSupported and audioSupported, as well as maxImages, maxAudio, and maxSequenceLength. Support depends on the selected model and backend. An unsupported input fails; it is not silently ignored.

Call close() when finished. isClosed reports whether the model has been closed.

On this page