|
| 1 | +# Select AI Configuration |
| 2 | + |
| 3 | +## Introduction |
| 4 | +**Select AI** is a functionality provided by **Oracle Autonomous Database (ADB)**. |
| 5 | + |
| 6 | +It enables to do easily **Text2SQL**, in other words to translate a request for data, expressed in Natural Language (NL), |
| 7 | +in a SQL statement working in your Database. |
| 8 | + |
| 9 | +Example: |
| 10 | + |
| 11 | +* (NL): List the names of all F1 drivers. |
| 12 | +* (SQL): SELECT DRIVER_NAME from F1USER.F1_DRIVERS |
| 13 | + |
| 14 | +## Configuration |
| 15 | +To use **Select AI** you need an ADB, with the schema where you want to run your SQL statements, and a Large Language Model (LLM). |
| 16 | +You can use a model provided by **OCI Generative AI** service, or a model from another supported provider (see Oracle docs for the list). |
| 17 | + |
| 18 | +In this short note, we will provide information to configure Select AI using OCI Generative AI. |
| 19 | + |
| 20 | +### Store credentials and create a Select AI **Profile** |
| 21 | +Create in your OCI account (enabled to use Generative AI) an API key. Save the keys. |
| 22 | + |
| 23 | +Create and store a **credential**, with a name, inside your DB schema (the schema you're using to execute Select AI, not the data schema). |
| 24 | + |
| 25 | +Execute the following procedure, with your data |
| 26 | + |
| 27 | +``` |
| 28 | +BEGIN |
| 29 | + DBMS_CLOUD.create_credential( |
| 30 | + credential_name => 'MY_CREDENTIAL_NAME', |
| 31 | + user_ocid => 'ocid1.user.oc1..my_user_oci', |
| 32 | + tenancy_ocid => 'ocid1.tenancy.oc1..my_tenancy_ocid', |
| 33 | + fingerprint => 'fingerprint of my key', |
| 34 | + private_key => 'cut&paste your private key here' |
| 35 | + ); |
| 36 | +END; |
| 37 | +/ |
| 38 | +``` |
| 39 | + |
| 40 | +Create a **Select AI profile**. Execute the following procedure, again with your data. |
| 41 | +(put the list of the object in the schema you need to make visible to Select AI) |
| 42 | + |
| 43 | +``` |
| 44 | +BEGIN |
| 45 | + DBMS_CLOUD_AI.CREATE_PROFILE( |
| 46 | + profile_name => 'OCI_GENERATIVE_AI_PROFILE' , |
| 47 | + attributes => |
| 48 | + '{ |
| 49 | + "provider": "oci", |
| 50 | + "region": "us-chicago-1", |
| 51 | + "oci_compartment_id": "ocid1.compartment.oc1..my compartment ocid", |
| 52 | + "credential_name": "MY_CREDENTIAL_NAME", |
| 53 | + "object_list": [ |
| 54 | + {"owner": "SH", "name": "CHANNELS"}, |
| 55 | + {"owner": "SH", "name": "COSTS"}, |
| 56 | + {"owner": "SH", "name": "COUNTRIES"}, |
| 57 | + {"owner": "SH", "name": "CUSTOMERS"}, |
| 58 | + {"owner": "SH", "name": "PRODUCTS"}, |
| 59 | + {"owner": "SH", "name": "PROMOTIONS"}, |
| 60 | + {"owner": "SH", "name": "SALES"}, |
| 61 | + {"owner": "SH", "name": "SUPPLEMENTARY_DEMOGRAPHICS"}, |
| 62 | + {"owner": "SH", "name": "TIMES"} |
| 63 | + ], |
| 64 | + "model": "xai.grok-4" |
| 65 | + }'); |
| 66 | +
|
| 67 | +END; |
| 68 | +``` |
| 69 | + |
| 70 | +## Test Select AI |
| 71 | +You can test that the configuration is correctly working using code like the one in [test select AI](./test_selectai01.py) |
| 72 | + |
| 73 | +The code is using the new library from Oracle: **select-ai** |
| 74 | +To use it, you need also to have installed in your Python environment the library: **oracledb** |
| 75 | + |
| 76 | +``` |
| 77 | +pip install select_ai |
| 78 | +pip install oracledb |
| 79 | +``` |
| 80 | + |
| 81 | +## References |
| 82 | +For more information, see |
| 83 | +* [Getting Started with Select AI](https://docs.oracle.com/en-us/iaas/autonomous-database-serverless/doc/select-ai-get-started.html) |
| 84 | +* [How to use Select AI: A step-by-step guide](https://blogs.oracle.com/datawarehousing/post/how-to-use-oracle-select-ai-a-stepbystep-guide-generative-ai) |
0 commit comments