{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "$id" : "https://voltdb.com/voltsp/schemas/processor/onnx",
  "title" : "Onnx Processor Configuration",
  "description" : "Runs ONNX model inference for general machine learning tasks. This processor can either\nuse an existing model reference defined in the ` resources ` section or\ncreate a new model instance using the provided URI.\n\nBoth input and output labels can be found using https://netron.app/.\n\n## Input\nThe `onnx` processor accepts `float` arrays (tensors) and uses the `inputTensorName`\nsetting to present them to the model as a named input.\n\n## Outputs\nThe inference result is post-processed to convert some of the ONNX specific data types to Java\n(e.g. `OnnxSequence`). Note that most models will already output data as map and rarely return OnnxMap as a single field.\nThe output event emitted to the next operator is produced by the user-supplied `computeFunction` from the\noriginal input and the post-processed tensor map.\n\nWhen `outputTensorNames` is provided the results will be filtered by those names which improve performance.\nThis is because ONNX is storing result data of-heap and accessing result values comes with the cost.\n\n## Models\nSupports standard ONNX models (`.onnx` files) for various machine learning tasks including\nclassification, regression, and anomaly detection.\n\n## Downloads\nThe `modelUri` can point to a location on a local disk (using `file://` scheme) or on a remote storage.\nRemote storage support depends on available plugins, e.g., S3 plugin allows downloads from an S3-compatible bucket.\n\n## Hot Reload\nSome resources such as MLflow model or ONNX-resource notify the processor about model changes. The processor can\nautomatically reload the model.\n",
  "type" : "object",
  "properties" : {
    "onnx" : {
      "type" : "object",
      "properties" : {
        "modelResource" : {
          "description" : "Reference to an existing model resource. When specified, modelUri must not be configured.\nInline configuration creates an ONNX resource, while named references can point to other types of resoruces.",
          "anyOf" : [ {
            "type" : "string"
          }, {
            "$ref" : "resource-onnx.schema.json#/properties/onnx"
          } ]
        },
        "modelUri" : {
          "type" : "string",
          "format" : "uri",
          "description" : "URI to the ONNX model file. Required if modelResource is not specified."
        },
        "inputTensorName" : {
          "type" : "string",
          "description" : "Name of the input tensor in the ONNX model."
        },
        "outputTensorNames" : {
          "description" : "Specifies the names of output tensors to retrieve from the ONNX model.\nWhen provided, only the tensors matching these names are included in the results.\nIf omitted, all available output tensors are passed to the next operator.",
          "anyOf" : [ {
            "type" : "string"
          }, {
            "type" : "array",
            "items" : {
              "type" : "string"
            }
          } ]
        },
        "printDownloadProgress" : {
          "type" : "boolean",
          "description" : "Whether to display progress information during model file downloads.",
          "default" : "false"
        },
        "cache" : {
          "type" : "object",
          "description" : "This configuration controls how model files are cached locally, including the cache location,\nsize limits, expiration policy, and cleanup behavior. If not provided files will be cached in the /tmp directory.",
          "properties" : {
            "directory" : {
              "type" : "string",
              "description" : "Directory where files will be cached. If not specified, a temporary directory will be created."
            },
            "maxCacheSize" : {
              "type" : "integer",
              "description" : "Maximum size of the cache in bytes. Files will be evicted when the cache exceeds this size. Use 0 for unlimited.",
              "default" : "0",
              "minimum" : -9223372036854775808,
              "maximum" : 9223372036854775807
            },
            "expirationTime" : {
              "type" : "string",
              "pattern" : "^(\\d+[smhd]|P(T|\\d+[YMD]).*)",
              "description" : "Duration after which cached files are considered stale and will not be used by the system."
            },
            "cleanupOnStart" : {
              "type" : "boolean",
              "description" : "Whether to clean up expired or invalid cache entries when the cache is initialized.",
              "default" : "false"
            }
          },
          "additionalProperties" : false
        },
        "sessionOptions" : {
          "type" : "object",
          "description" : "Configuration options for OrtSession.SessionOptions.",
          "properties" : {
            "intraOpNumThreads" : {
              "type" : "integer",
              "description" : "Number of threads used to parallelize the execution within nodes.",
              "minimum" : -2147483648,
              "maximum" : 2147483647
            },
            "interOpNumThreads" : {
              "type" : "integer",
              "description" : "Number of threads used to parallelize the execution of the graph (across nodes).",
              "minimum" : -2147483648,
              "maximum" : 2147483647
            },
            "graphOptimizationLevel" : {
              "type" : "string",
              "description" : "Optimization level enum. Allowed values are:\n- NO_OPT - disable all optimizations\n- BASIC_OPT - enable basic optimizations\n- EXTENDED_OPT = enable all optimizations,\n- ALL_OPT = enable all optimizations and also enable extended optimizations.",
              "default" : "ALL_OPT",
              "enum" : [ "no_opt", "basic_opt", "extended_opt", "all_opt", "NO_OPT", "BASIC_OPT", "EXTENDED_OPT", "ALL_OPT" ]
            },
            "executionMode" : {
              "type" : "string",
              "description" : "Execution mode. Supported values are: sequential, parallel.",
              "default" : "PARALLEL",
              "enum" : [ "sequential", "parallel", "SEQUENTIAL", "PARALLEL" ]
            },
            "memoryPatternOptimization" : {
              "type" : "boolean",
              "description" : "Enable memory pattern optimization.",
              "default" : "true"
            },
            "enableCpuMemArena" : {
              "type" : "boolean",
              "description" : "Enable CPU memory arena. Default is true.",
              "default" : "true"
            },
            "profilerFilePath" : {
              "type" : "string",
              "description" : "The file to write profile information to. Enables profiling."
            },
            "enableCuda" : {
              "type" : "boolean",
              "description" : "Enable CUDA execution provider.",
              "default" : "false"
            },
            "cudaDeviceId" : {
              "type" : "integer",
              "description" : "CUDA device ID to use.",
              "default" : "0",
              "minimum" : -2147483648,
              "maximum" : 2147483647
            },
            "cudaExecutionProviderOptions" : {
              "type" : "object",
              "description" : "CUDA execution provider options as key-value pairs.",
              "additionalProperties" : {
                "type" : "string"
              }
            },
            "enableCpu" : {
              "type" : "boolean",
              "description" : "Enable CPU execution provider. Default is true.",
              "default" : "true"
            },
            "enableMemoryReuse" : {
              "type" : "boolean",
              "description" : "Enable memory reuse. Default is true.",
              "default" : "true"
            },
            "logSeverityLevel" : {
              "type" : "integer",
              "description" : "Log severity level. 0 = verbose, 1 = info, 2 = warning, 3 = error, 4 = fatal.",
              "minimum" : -2147483648,
              "maximum" : 2147483647
            },
            "logId" : {
              "type" : "string",
              "description" : "Log ID."
            },
            "onnxSessionConfigurator" : {
              "type" : "string",
              "description" : "This consumer is optional and complements the existing options exposed by the VoltSp builder.\nIt enables full configuration of the ONNX session, including memory management, execution behavior, and optimization settings."
            }
          },
          "additionalProperties" : false
        },
        "tensorExtractor" : {
          "type" : "string",
          "description" : "Transforms the incoming input event into an InferenceRequest.\n\nJava:\n  .withTensorExtractor(event -> new InferenceRequest(\n          new float[][]{event.features()}, float[][].class))\n\nYAML — the JS function may return a plain JS object matching InferenceRequest's shape:\n  tensorExtractor: |\n    function process(event) {\n      var Float2D = Java.type('float[][]');\n      var matrix = new Float2D(1);\n      matrix[0] = event.features;\n      return { tensorData: matrix, dataClass: Float2D.class };\n    }"
        },
        "computeFunction" : {
          "type" : "string",
          "description" : "Computes the result event emitted to the next operator from the original input and the\nONNX inference output (a map of tensor name to tensor value)."
        }
      },
      "required" : [ "inputTensorName", "tensorExtractor", "computeFunction" ],
      "additionalProperties" : false
    }
  },
  "required" : [ "onnx" ],
  "additionalProperties" : false
}
