Select AI - new feature Oracle 23ai

 


Oracle's "Select AI" feature is a groundbreaking addition to the Oracle Database 23c AI. It simplifies the process of retrieving data for users who may not be proficient in SQL, making it accessible to a broader audience. Select AI acts as an intelligent assistant, swiftly navigating through vast datasets to extract valuable insights that aid in better decision-making for businesses.

Initially, Select AI was exclusive to Autonomous Database Serverless (ADB-S). However, Oracle has now extended its availability to Autonomous Database Dedicated (ADB-D) customers. Even existing Exadata Cloud Service (ExaCS) customers with the MultiVM cluster option can now experiment with this feature on their ADB-D instances. Select AI is part of the DBMS_CLOULD_AI package and supports various large language models (LLMs), including

  1. OCI GenAI 
  2. Cohere
  3. OpenAI
  4. Azure OpenAI
  5. Google

You can explore the Select AI feature using the always-free Autonomous Database, coupled with an API key from a Cohere trial account. However, accessing the other LLM options requires a paid account.

Steps to Implement Select AI

Implementing Select AI in your Oracle Database involves a straightforward four-step process:

Step 1: Provide permission to access the DBMS_CLOUD_AI package 

As the ADMIN user, you must configure certain settings for other database users before they can utilize Select AI. First, add the schema that will be using Select AI to the Access Control List (ACL). This grants the schema the necessary permissions to interact with external services. Here’s an example of how to add the Luqman_ai schema to the ACL and allow HTTP calls to the Cohere API:


BEGIN
    DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
         host => 'api.cohere.ai',
         ace => xs$ace_type(privilege_list => xs$name_list('http'),
         principal_name => 'Luqmanai',
         principal_type => xs_acl.ptype_db)
    );
END;

Next, grant the required privileges to the necessary PL/SQL packages:


GRANT EXECUTE ON DBMS_CLOUD_AI TO Luqmanai;
GRANT EXECUTE ON DBMS_CLOUD TO Luqmanai;

Step 2: Create credentials for Cohere API

In this step, connect to your schema (in this case, the Luqman_ai schema) and create a credential for the Cohere API:

first Access your OpenAI settings page to copy your API key, for creating the DBMS_CLOUD credentials. In your case, it could be Cohere or OpenAI. I used Cohere API.

Check this post to get yours: Cohere API KEY

write your password key then run the below


BEGIN
   -- DBMS_CLOUD.DROP_CREDENTIAL (credential_name => 'COHERE_CRED');

   DBMS_CLOUD.CREATE_CREDENTIAL(
       credential_name => 'COHERE_CRED',
       username => 'COHERE',
       password => '...yl5b' );
END;

Replace the ... with your Cohere API key, which can be easily obtained by following the steps provided by Cohere.

Step 3: Create a CLOUD_AI Profile

Now, create a CLOUD_AI profile that defines the objects and tables you want to expose to the LLMs (Cohere, OpenAI, etc.):


BEGIN
   --DBMS_CLOUD_AI.DROP_PROFILE(profile_name => 'COHERE_AI');
  
   DBMS_CLOUD_AI.CREATE_PROFILE(
      profile_name => 'COHERE_AI',
      attributes => '{"provider": "cohere",
                      "credential_name": "COHERE_CRED",
                      "object_list": [{"owner": "SH", "name": "customers"},  
                                      {"owner": "SH", "name": "sales"},
                                      {"owner": "SH", "name": "products"},
                                      {"owner": "SH", "name": "countries"},
                                      {"owner": "SH", "name": "channels"},
                                      {"owner": "SH", "name": "promotions"},
                                      {"owner": "SH", "name": "times"}]
       }');
END;

This profile specifies the tables and objects that will be made accessible to the LLMs. According to Oracle’s documentation, the models use metadata such as primary keys, foreign keys, and other schema details to interpret and respond accurately. There are additional nuances and challenges to this process, which I’ll explore in a future post.

Step 4: Activate Select AI

To start using Select AI, you need to enable the profile for your session:


EXEC DBMS_CLOUD_AI.SET_PROFILE('COHERE_AI');

Remember, if you start a new session or your session is reset, you’ll need to re-run this command.



Let's try some queries 


select ai chat which team win world football cup 2018;
select ai chat give me the recipie of egptain koshari;
select ai chat what is the latest updates on edb postgres;

-- data-specific queries

select ai how many customers exist;
select AI what customer is the largest by sales;
select AI How many customers exist by country;


 

    

Comments

Looking for Database Consulting?

Get expert help with Oracle, PostgreSQL, and MongoDB services.

Contact US