a
I am a highly motivated and organised professional with more than ten years of experience as a Database Specialist and Architect or designer.
Bring Me a Coffee - NZ$ 5
 

Select AI – Natural Language to SQL Generation on Autonomous Database

Select AI – Natural Language to SQL Generation on Autonomous Database

Autonomous Database Select AI, which enables you to easily retrieve data using natural language. Combining generative AI with Oracle SQL allows you to express your desired outcome and let the database generate the appropriate SQL query for your schema. While some language models may excel at generating SQL, executing it on your database can be a challenge. Select AI streamlines the process by generating SQL tailored to your specific database.

Large language models (LLMs) powered by AI are trained on vast amounts of text data and can understand the nuances and intended meaning of most natural language inquiries. By using natural language to create SQL, the time taken to generate queries is reduced, query construction is simplified, and the need for specialized SQL expertise is minimized or eliminated. Obtaining information from your database that involves creating queries with multiple joins, nested subqueries, and other SQL structures becomes easier and faster when using plain language.

By learning effective SQL query patterns from curated training data, LLMs can produce more efficient queries – enabling them to perform better. As part of Oracle Autonomous Database, Select AI inherits all security and authentication features of the database.

By virtue of being integrated with Oracle SQL, this capability is available through any SQL IDE, SQL Developer Web, Oracle Application Express (APEX), and Oracle Machine Learning Notebooks. Any application that invokes SQL and has an AI provider account also has access to Select AI.

Large Language are Insufficient

Certain LLMs excel at generating SQL code and are capable of accurately interpreting the user’s intentions. These LLMs can even generate table and field names that fit within the syntax of a valid SQL query. However, it’s important to note that this query will only work if your database has pre-existing tables with columns. Essentially, the LLM is able to imagine the necessary tables and fields in order to generate the SQL code.

To generate a runnable query, we must first tie it to a certain schema, which is where Select AI comes in. By creating a profile, you can use your local schema by default, but you can also indicate which schema(s) and table(s) you wish to be considered when producing queries.

The initial natural language query is enhanced with metadata from schema(s) found in the user’s profile, as shown below. Feeding information to the LLM allows it to generate a SQL query that can be executed against your database and, hopefully, offer the results you’re searching for.

DBMS_CLOUD_AI Package

Enabling this feature is a new package, DBMS_CLOUD_AI, in Autonomous Database that enables the use of LLMs for generating SQL from natural language prompts. The package provides access to user specified LLMs along with knowledge of the user’s accessible database metadata. This enables producing runnable SQL queries applicable to that schema. The DBMS_CLOUD_AI package currently integrates with AI providers such as OpenAI and Cohere, with others planned to follow. To use this feature, you need an account with the AI provider and must supply your API credentials to Autonomous Database.

Getting started

To get started with Select AI, sign into your Autonomous Database instance with administrator privileges and add your user (here MY_USER) to the ACL list and grant access to the DBMS_CLOUD_AI package:

Copy Code
BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => ‘api.openai.com’, ace => xs$ace_type(privilege_list => xs$name_list(‘http’), principal_name => ‘MY_USER’, principal_type => xs_acl.ptype_db) ); END; grant execute on DBMS_CLOUD_AI to MY_USER;

Create a database credential to your AI provider account. In the case of OpenAI, the password is the uniquely generated token for API usage.

Copy Code
BEGIN DBMS_CLOUD.DROP_CREDENTIAL ( credential_name => ‘OPENAI_CRED’); DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => ‘OPENAI_CRED’, username => ‘OPENAI’, password => ‘xyz’ ); END;

Create your DBMS_CLOUD_AI profile. Here, we list the schema(s) we want to be considered (e.g., SH) and, optionally, any tables (e.g., customers, sales, etc.).

Copy Code
BEGIN DBMS_CLOUD_AI.drop_profile(profile_name => ‘OPENAI’); DBMS_CLOUD_AI.create_profile( profile_name => ‘OPENAI’, attributes => ‘{“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;

Set your DBMS_CLOUD_AI profile, which must be done in each database session.

Copy Code
BEGIN DBMS_CLOUD_AI.SET_PROFILE( profile_name => ‘OPENAI’ ); END;

Very Soon I will put more information to complement this new feature.

No Comments

Reply