LOAD_ONNX_MODEL

This procedure enables you to load an ONNX-format embedding model into your database.

Syntax

DBMS_VECTOR.LOAD_ONNX_MODEL (
     directory                IN  VARCHAR2,
     file_name                IN  VARCHAR2,
     model_name               IN  VARCHAR2,
     metadata                 IN  JSON DEFAULT JSON('{"function" : "embedding", '|| 
                                       '"embeddingOutput" : "embedding", "input": {"input":["DATA"]}}'),
     external_data_file_name  IN  VARCHAR2  DEFAULT NULL);
DBMS_VECTOR.LOAD_ONNX_MODEL(
    model_name        IN  VARCHAR2,
    model_data        IN  BLOB,
    metadata          IN  JSON DEFAULT JSON('{"function" : "embedding", '|| 
                               '"embeddingOutput" : "embedding", "input": {"input":["DATA"]}}'));

Parameters

Table 12-8 LOAD_ONNX_MODEL Procedure Parameters

Parameter Description

directory

The directory name of the data dump. For example, DM_DUMP.

file_name

A VARCHAR2 type parameter that specifies the file name of the ONNX model.

model_name

The user-defined name of the model in the form [schema_name.]model_name. This is the name the model will have in OML as a first-class database object. If you do not specify a schema, then your own schema is used.

model_data

It is a BLOB holding the ONNX representation of the model. The BLOB contains the identical byte sequence as the one stored in an ONNX file.

metadata

A JSON description of the metadata describing the model. The metadata at minimum must describe the machine learning function supported by the model. The model's metadata parameters are described in JSON Metadata Parameters for ONNX Models.
external_data_file_name

A VARCHAR2 type parameter used to provide the file name of the external data file metadata if the file name does not match the expected format, which is <file_name>_external_data.json.

The default value is NULL.

Examples

The following examples illustrates a code snippet that uses the DBMS_VECTOR.LOAD_ONNX_MODEL procedure. The complete step-by-step example is illustrated in Import ONNX Models and Generate Embeddings.

EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL(
    directory  => 'DM_DUMP', 
    file_name  => 'my_embedding_model.onnx', 
    model_name => 'doc_model', 
    metadata   => JSON('{"function" : "embedding", 
                   "embeddingOutput" : "embedding", 
                   "input": {"input": ["DATA"]}}'));
DBMS_VECTOR.LOAD_ONNX_MODEL(
    model_name => 'my_embedding_model.onnx',
    model_data => :blob_bind_variable, 
    metadata   => JSON('{"function" : "embedding", 
                   "embeddingOutput" : "embedding", 
                   "input":{"input": ["DATA"]}}'));

For a complete example to illustrate how you can define a BLOB variable and use it in the LOAD_ONNX_MODEL procedure, you can have the following:

CREATE OR REPLACE MY_LOAD_EMBEDDING_MODEL(embedding_model_name VARCHAR2, onnx_blob BLOB) IS 
BEGIN
DBMS_VECTOR.LOAD_ONNX_MODEL(embedding_model_name,
                            onnx_blob, 
                            JSON('{"function" : "embedding", 
                                   "embeddingOutput" : "embedding" ,
                                   "input":{"input": ["DATA"]}}'));
END;
/

Usage Notes

  • The name of the model follows the same restrictions as those used for other machine learning models, namely:
    • The schema name, if provided, is limited to 128 characters.
    • The model name is limited to 123 characters and must follow the rules of unquoted identifiers: they contain only alphanumeric characters, the underscore (_), dollar sign ($), and pound sign (#). The initial character must be alphabetic.
  • The model size is limited to 2 GB.
  • There are default input and output names for input and output attributes for models that are prepared by the Python utility. You can load those models without the JSON parameters. For example:

    EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL('DM_DUMP', 'my_embedding_model.onnx', 'doc_model'));
  • To be loaded as an ONNX model with external initializers, there must exist in the specified directory a file with the format <file_name>_external_data.json. If a file with that name does not exist, and the external_data_file_name parameter has not been used to specify an alternate file name, the ONNX model will load without external initializers. If the file does exist, it is verified and the model is imported as an ONNX model with external initializers. The cumulative size of the .onnx file and each of the external data files can be more than 2 GB. However, loading may fail if there is not enough PGA aggregate memory. For information about the parameter used to control the PGA limit, see PGA_AGGREGATE_LIMIT in Oracle AI Database Reference.
  • When the LOAD_ONNX_MODEL syntax using a BLOB format for model_data is used, the model_data argument can be up to 2 GB in size. Loading may fail if there is not enough PGA aggregate memory to load the model. This version of the procedure syntax can only load a model without external initializers.

See Also: