exec DBMS_VECTOR.DROP_ONNX_MODEL('MULTILINGUAL_E5_BASE');

-- list onnx models in object storage
SELECT object_name, bytes, checksum, created, last_modified
FROM DBMS_CLOUD.LIST_OBJECTS(
  credential_name => 'OCI$RESOURCE_PRINCIPAL',
  location_uri    => 'https://idi1o0a010nx.objectstorage.us-chicago-1.oci.customer-oci.com/n/idi1o0a010nx/b/uploads/o/'
);

-- load onnx model into vector database
declare
    model_source blob := NULL;
    model_uri varchar2(1000) := 'https://idi1o0a010nx.objectstorage.us-chicago-1.oci.customer-oci.com/n/idi1o0a010nx/b/uploads/o/multilingual-e5-base.onnx';
begin
    model_source := DBMS_CLOUD.GET_OBJECT(credential_name => 'OCI$RESOURCE_PRINCIPAL', object_uri => model_uri); 

    DBMS_VECTOR.LOAD_ONNX_MODEL(
        'MULTILINGUAL_E5_BASE', -- 768 dimensions
        model_source,
        metadata => JSON('{"function" : "embedding", "embeddingOutput" : "embedding", "input": {"input": ["DATA"]}}')
    );
END;
/

-- test using onnx model
SELECT VECTOR_EMBEDDING(
        MULTILINGUAL_E5_BASE 
        USING 'la veloce volpe marrone saltò' as DATA) 
    AS embedding;


-- test using external provider
SELECT DBMS_VECTOR.UTL_TO_EMBEDDING(
    'la veloce volpe marrone saltò',
    JSON('{
            "provider"        : "ocigenai",
            "credential_name" : "OCI$RESOURCE_PRINCIPAL",
            "url"             : "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/embedText",
            "compartmentId"   : "ocid1.compartment.oc1..aaaaaaaa33ogmhasyvcqzuvkrfzo5mavh3q2le7mgwmy74yzpyqi7byxgrlq",
            "model"           : "openai.text-embedding-3-large"
        }')
) AS emb;