Securely Generate Vector Embeddings from within the Oracle AI Database 26ai using the Oracle Private AI Services Container

Introduction

I have previously shared how to install the Oracle Private AI Services Container, configure the Oracle Linux certificate store, and set-up Oracle AI Database 26ai ACLs.

In this post I show how the we can call securely generate Vector Embeddings from within the Oracle AI Database 26ai using the DBMS_VECTOR package and the Oracle Private AI Services Container.

What is the DBMS_VECTOR package?

The Oracle AI Database 26ai DBMS_VECTOR package provides APIs to support common operations with Oracle AI Vector Search, such as extracting chunks or embeddings from user data, generating text for a given prompt, creating a vector index, or reporting on index accuracy.

    Using the DBMS_VECTOR.UTL_TO_EMEDDING database package we can securely, off-load the generation of Vector embeddings.

    Create Credential

    We will start by using DBMS_VECTOR.CREATE_CREDENTIAL procedure to create a credential name for storing user authentication details in Oracle AI Database 26ai for the Private AI Services Container.

    The CREDENTIAL_NAME stores authentication parameters, for example user name, password, access token, private key, or fingerprint.

    The DBMS_VECTOR.CREATE_CREDENTIAL supports authentication with Cohere, Google AI, Hugging Face, Oracle Cloud Infrastructure (OCI) Generative AI, OpenAI, Vertex AI and the Private AI Services Container.

    Consult the Oracle AI Database 26ai DBMS_VECTOR.CREATE_CREDENTIAL documentation for other services.

    Setup Private AI Credentials

    Provide a CREDENTIAL_NAME for the credential and provide the authentication parameters.

    The DBMS_VECTOR package expects the PARMS authentication parameters to be passed as in a JSON format.

    DBMS_VECTOR.CREATE_CREDENTIAL (
    CREDENTIAL_NAME IN VARCHAR2,
    PARAMS IN JSON DEFAULT NULL
    );

    Run the below into your PDB to create a credential called PRIVATEAI_CRED providing the access_token for the Private AI Services Container.

    create_credential.sql
    SET SERVEROUTPUT ON
    BEGIN
    DBMS_VECTOR.DROP_CREDENTIAL('PRIVATEAI_CRED');
    EXCEPTION
    WHEN OTHERS THEN NULL;
    END;
    /
    DECLARE
    jo json_object_t;
    BEGIN
    jo := json_object_t();
    jo.put('access_token', '216c5e9c6242881ded41479688a9bbbe3bb22d771a356d28659e3d726fa1a285');
    DBMS_VECTOR.CREATE_CREDENTIAL(
    credential_name => 'PRIVATEAI_CRED',
    params => json(jo.to_string));
    END;
    /
    EXIT;

    Using Private AI Services Container

    Now we have configured our Private AI credential we can use the DBMS_VECTOR.UTL_TO_EMEDDING database package to securely, off-load the generation of Vector embeddings to the Private AI Service Containers

    create_embedding_ext.sql
    SET SERVEROUTPUT ON
    DECLARE
    input clob;
    v vector;
    BEGIN
    input := '"A lovestruck Romeo sang the streets a serenade","Laying everybody low with a love song that he made"';
    v := DBMS_VECTOR.UTL_TO_EMBEDDING(
    input,
    json('{"provider": "privateai",
    "url": "https://z-re-ora1.uklab.purestorage.com:8443/v1/embeddings",
    "credential_name": "PRIVATEAI_CRED",
    "model": "all-MiniLM-L12-v2" }'));
    DBMS_OUTPUT.PUT_LINE(vector_serialize(v));
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE (SQLERRM);
    DBMS_OUTPUT.PUT_LINE (SQLCODE);
    END;
    /
    EXIT

    For example:

    Summary

    In this post I have shared how an Oracle AI Database 26ai can securely generate Vector embeddings without any dependancy on the public cloud or internet through the use of the Private AI Services Container.

    Leave a Reply

    Create a website or blog at WordPress.com

    Up ↑

    Discover more from Ron Ekins' - Oracle Technology, DevOps and Kubernetes Blog

    Subscribe now to keep reading and get access to the full archive.

    Continue reading