LOAD_ONNX_MODEL

This procedure enables you to load an ONNX-format embedding model or a rerank 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 8 LOAD_ONNX_MODEL Procedure

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 _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;
/

The following example illustrates a code snippet that uses the DBMS_VECTOR.LOAD_ONNX_MODEL procedure to load a rerank model:

EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL(
    directory  => 'DM_DUMP',
    file_name  => 'my_rerank_model.onnx',
    model_name => 'rerank_model',
    metadata   => JSON('{"function" : "regression"}'));

Usage Notes

EXECUTE DBMS_VECTOR.LOAD_ONNX_MODEL('DM_DUMP', 'my_embedding_model.onnx', 'doc_model'));

See Also: