A shift from writing SQL queries to writing in natural language
my first interaction with the SQL language was during the University masters program, and then I went in depth. When I did the Oracle certification, From point onwards, SQL/PLSQL became part of my everyday job. Now, I am experiencing no other way of interacting with the database, which is not as tricky as learning the SQL and memorizing the syntax, which you keep forgetting over time.
As the LLMs are ruling the IT industry and impacting every aspect of our ecosystem, this impact also comes to the databases, and the question started coming to mind over a year ago:
How can we talk to the database rather than writing SQL queries to interact with it?
Oracle has released Database version 23ai, which was covered in the earlier newsletter episode. In it, you will find the basics of the new features introduced. I suggest heading to the earlier edition, “AI comes to the Database at the core of your data,” and reading this before moving forward.
In this release, you will gain practical knowledge of interacting with the Oracle database, similar to what you use today: Generative AI.
Select AI is the central feature enabling the Oracle database to allow you to chat with the data.
Select AI
LLMs now allow you to interact with your database using natural language, such as querying it in plain English.
With Select AI, the Oracle Autonomous Database handles the conversion of natural language into SQL, so you can provide a natural language prompt instead of writing SQL code to access your data.
Select AI has revolutionized productivity for users and developers. It allows those with limited SQL knowledge to extract valuable insights without needing to understand complex data structures or technical languages—no more memoizing the syntax.
Now, the question comes to mind: How do I get started? That’s what I did this weekend.
The DBMS_CLOUD_AI package in Oracle Autonomous Database facilitates the integration of a user-specified LLM for generating SQL queries based on natural language prompts. This package helps the LLM understand the database schema and guides it in creating SQL queries that align with that schema.
DBMS_CLOUD_AI is compatible with LLMs such as Oracle Cloud Infrastructure Generative AI, OpenAI, Cohere, and Azure OpenAI Service
To start first time Select AI in your database, you need to follow the steps mentioned in this Configuring Select AI for First Use (oracle.com)
Setup Autonomous Database to access OCI Generative AI
A credential is used to sign LLM API requests. We will use the Autonomous Database resource principal to access the OCI Generative AI/LLM.
Create AI profiles to access LLM.
AI profiles are created to facilitate and configure access to an LLM and to set up the generation of SQL statements from natural language prompts. Profiles capture the properties of your LLM provider and the tables and views you want to enable for natural language queries. You have the option to create multiple profiles (e.g., for different LLMs); however, only one is active for the current session.
Let’s get started: you’ll need to:
- Create a profile that describes your LLM provider and the metadata (schemas, tables, views, etc.) that can be used for natural language queries.
- Set the profile for your session. Because we’re accessing a single LLM, create a LOGON trigger that sets the profile for your session.
More information on DBMS_CLOUD_AI Package DBMS_CLOUD_AI Package (oracle.com)
Healthcare Dataset for exploration with Select AI
I have taken a dataset from the National Center for Health Statistics (2021): Vital Statistics Natality Birth Data. The NBER Data File name is nat2021us, and it is available from Natality Data from the National Vital Statistics System of the National Center for Health Statistics USA, which provides demographic and health data for births.
I quickly loaded the files in the Oracle Autonomous database through the Dataload utility.
Now, let’s start chatting with the data that I have uploaded.
When I asked the question to show the overall count over the mother’s age, the LLM understood, and it suggested how you can get it.
You can do so many questions and answers with the data. For another example, I have asked for the results of male and female infants’ data. There is a typo mistake in the syntax, but even then, it gives us the correct results. This was not possible at all with the SQL queries.
In this example, I asked about the maximum birth weight of the infant.
Now, the same query but with the chat function, and you can see the results; it also explained why ‘9999’ was ignored.
So, I have learned a new way to interact with the database and explore the data rather than writing SQL queries. I am leaving an action for you. If you want to do it yourself, just head over to this Lab, ‘Chat with your data in Autonomous Database using generative AI. ‘