Manage AI Profiles

You can create and manage your AI profiles through DBMS_ACLOUD_AI package.

Use DBMS_CLOUD_AI to Configure AI Profiles

Oracle Autonomous Database Serverless uses AI profiles to facilitate and configure access to an LLM and to setup for generating, running, and explaining SQL based on natural language prompts. It also facilitates retrieval-augmented generation using vector stores and allows for chatting with the LLM.

AI profiles include database objects that are the target for natural language queries. Metadata used from these targets can include database table names, column names, column data types, and comments. You create and configure AI profiles using the DBMS_CLOUD_AI.CREATE_PROFILE and DBMS_CLOUD_AI.SET_PROFILE procedures.

In addition to specifying tables and views in the AI profile, you can also specify tables mapped with external tables, including those described in Query External Data with Data Catalog. This enables you to query data not just inside the database, but also data stored in a data lake's object store.

Perform Prerequisites for Select AI

Before you use Select AI, here are the steps to enable DBMS_CLOUD_AI.

The following are required to use DBMS_CLOUD_AI:

  • Access to an Oracle Cloud Infrastructure cloud account and to an Autonomous Database instance.
  • A paid API account for a supported AI provider, one of:
    AI Provider API Keys

    OpenAI

    See Use OpenAI to get your API keys.

    Cohere

    See Use Cohere to get your secret API keys.

    Azure OpenAI Service

    See Use Azure OpenAI Service for more information on how to configure Azure OpenAI Service.

    OCI Generative AI.

    See Use OCI Generative AI.

    Google

    See Use Google to get your API keys.

  • Network ACL privileges to access your external AI provider.

    Note:

    Network ACL privileges are not required for OCI Generative AI.
  • A credential that provides access to the AI provider.

Enable DBMS_CLOUD_AI

To configure DBMS_CLOUD_AI:
  1. Grant the EXECUTE privilege on the DBMS_CLOUD_AI package to the user who wants to use Select AI.

    By default, only the system administrator is granted the EXECUTE privilege. The administrator can grant EXECUTE privilege to other users.

  2. Grant network ACL access to the user who wants to use Select AI and for the AI provider endpoint.

    The system administrator can grant network ACL access. See APPEND_HOST_ACE Procedure for more information.

  3. Create a credential to enable access to your AI provider.

    See CREATE_CREDENTIAL Procedure for more information.

The following example grants the EXECUTE privilege to ADB_USER:
grant execute on DBMS_CLOUD_AI to ADB_USER;

The following example grants ADB_USER the privilege to use the api.openai.com endpoint.

BEGIN  
    DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
         host => 'api.openai.com',
         ace  => xs$ace_type(privilege_list => xs$name_list('http'),
                             principal_name => 'ADB_USER',
                             principal_type => xs_acl.ptype_db)
   );
END;
/

The parameters are:

  • host: The host, which can be the name or the IP address of the host. You can use a wildcard to specify a domain or an IP subnet. The host or domain name is not case sensitive.

    AI Provider Host

    OpenAI

    api.openai.com

    Cohere

    api.cohere.ai

    Azure OpenAI Service

    <azure_resource_name>.openai.azure.com

    See Profile Attributes to know more about azure_resource_name.

    Google

    generativelanguage.googleapis.com

  • ace: The access control entries (ACE). The XS$ACE_TYPE type is provided to construct each ACE entry for the ACL. For more details, see Creating ACLs and ACEs.

The following example creates a credential to enable access to OpenAI.

EXEC DBMS_CLOUD.CREATE_CREDENTIAL('OPENAI_CRED', 'OPENAI', 'your_api_token');

The parameters are:

  • credential_name: The name of the credential to be stored. The credential_name parameter must conform to Oracle object naming conventions, which do not allow spaces or hyphens.

  • username: The username and password arguments together specify your AI provider credentials.

    The username is a user-specified user name.

  • password: The username and password arguments together specify your AI provider credentials.

    The password is your AI provider secret API key, and depends on the provider:

    AI Provider API Keys

    OpenAI

    See Use OpenAI to get your API keys.

    Cohere

    See Use Cohere to get your API keys.

    Azure OpenAI Service

    See Use Azure OpenAI Service to get your API keys and to configure the service.

    Note:

    If you are using the Azure OpenAI Service principle to authenticate, you can skip the DBMS_CLOUD.CREATE_CREDENTIAL procedure. See Examples of Using Select AI for an example of authenticating using Azure OpenAI Service principle.

    OCI Generative AI

    See Use OCI Generative AI to generate API signing keys.

    Google

    See Use Google to generate your API keys.

Topics

Use OpenAI

To enable OpenAI to generate SQL and text responses to your natural language prompts, obtain API keys from your OpenAI paid account.

You can find your secret API key in your User settings.

Use Cohere

To enable Cohere to generate SQL and text responses to your natural language prompts, obtain API keys from your Cohere paid account.

  1. Login to Cohere's website with your credentials. Cohere Dashboard appears by default.

  2. Alternately,click Dashboard.

  3. Click API Keys on the left navigation. Copy the default API key or create another key. See API-Keys for more information.

Use Azure OpenAI Service

To enable Azure OpenAI Service to generate SQL and text responses to your natural language prompts, configure and provide access to the AI provider.

To use Azure OpenAI Service, perform the following steps:
  1. Obtain your secret API keys. You can find your API keys in the Resource Management section of your Azure portal. On your Azure OpenAI Service Resource page, click Keys and Endpoint. You can copy either KEY1 or KEY2.
  2. Create an Azure OpenAI Service resource and deploy a model: Create and deploy an Azure OpenAI Service resource.

    Tip:

    • Make note of the resource name and deployment name as those parameters are used to provide network access permission and to create your Azure OpenAI Service profile using the DBMS_CLOUD_AI.CREATE_PROFILE procedure.
    • To know about rate limits for token per minute on a model, see Azure OpenAI Service quotas and limits.
  3. Allow access to Azure OpenAI Service:

Use OCI Generative AI

To enable OCI Generative AI to generate SQL and text responses to your natural language prompts, generate an API signing key.

Use the Console or command line to generate an API signing key for any Oracle Database instance. See How to Generate the API Signing Key.

Use Google

To enable Google AI Studio to generate SQL and text responses to your natural language prompts, obtain API keys from your Google AI Studio paid account.

  1. Go to Google AI Studio.
  2. Click Sign In to Google AI Studio.
  3. Click Get API key on the prompt screen.
  4. Select all the applicable options on the next page.
  5. Click Create API key.
  6. Click Create API key in new project.
    The screen displays the progress and generates an API key. Copy the key and save it.

Create and Set an AI Profile

Describes the steps to create and enable an AI profile.

Use DBMS_CLOUD_AI.CREATE_PROFILE to create an AI profile. Run DBMS_CLOUD_AI.SET_PROFILE to enable the AI profile so that you can use SELECT AI with a natural language prompt.

Note:

You must run DBMS_CLOUD_AI.SET_PROFILE in each new stateful database session (connection) before you use SELECT AI. If you are using a stateless connection, you must use the DBMS_CLOUD_AI.GENERATE function which enables you to specify the profile name in each invocation.

The following example with the OpenAI provider creates an AI profile called OPENAI and sets the OPENAI profile for the current user session.

-- Create AI profile
--
SQL> BEGIN
  DBMS_CLOUD_AI.create_profile(
      'OPENAI',
      '{"provider": "openai",
        "credential_name": "OPENAI_CRED",
        "object_list": [{"owner": "SH", "name": "customers"},
                        {"owner": "SH", "name": "sales"},
                        {"owner": "SH", "name": "products"},
                        {"owner": "SH", "name": "countries"}]
       }');
END;
/
 
PL/SQL procedure successfully completed.
 
--
-- Enable AI profile in current session
--
SQL> EXEC DBMS_CLOUD_AI.set_profile('OPENAI');
 
PL/SQL procedure successfully completed.