Skip to content

Commit 31ce3a4

Browse files
authored
Merge pull request #4 from martygubar/main
centralized credential creation and added RAG example
2 parents fd89c79 + cc60f73 commit 31ce3a4

11 files changed

+173
-297
lines changed

azure-cli/config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ADB_NAME="quickstart"
1010
# database
1111
VNET_NAME="dev-vnet"
1212
VNET_PREFIX="19x.xxx.0.0/16"
13+
1314
# subnet for the database
1415
SUBNET_NAME="dev-sn-db"
1516
SUBNET_PREFIX="19x.xxx.1.0/24"
@@ -34,5 +35,5 @@ STORAGE_CONTAINER_NAME="adb-sample"
3435
## IDENTITIES
3536
# This identity will be used for your VM. The password will also be used for the database ADMIN user
3637
USER_NAME="adb"
37-
# The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character.
38+
--The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character
3839
USER_PASSWORD=""

azure-cli/config.default

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ ADB_NAME="quickstart"
99
## NETWORKING
1010
# database
1111
VNET_NAME="dev-vnet"
12-
#VNET_PREFIX="192.168.0.0/16"
1312
VNET_PREFIX="19x.xxx.0.0/16"
13+
1414
# subnet for the database
1515
SUBNET_NAME="dev-sn-db"
16-
#SUBNET_PREFIX="192.168.1.0/24"
1716
SUBNET_PREFIX="19x.xxx.1.0/24"
1817

1918
# client subnet
2019
SUBNET2_NAME="dev-sn-client"
21-
#SUBNET2_PREFIX="192.168.2.0/24"
2220
SUBNET2_PREFIX="19x.xxx.2.0/24"
2321

2422
#network security group
@@ -37,4 +35,5 @@ STORAGE_CONTAINER_NAME="adb-sample"
3735
## IDENTITIES
3836
# This identity will be used for your VM. The password will also be used for the database ADMIN user
3937
USER_NAME="adb"
40-
USER_PASSWORD="your-complex-password"
38+
--The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character
39+
USER_PASSWORD=""

sql/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Try out these scripts to learn how to get started using Autonomous Database. Sim
1616

1717
|Script|Description|
1818
|----|---|
19+
|[credential-create.sql](credential-create.sql)|Autonomous Database credentials contain the secret keys used to connect to services - like Azure OpenAI. This script creates those credentials. It's called by multiple scripts listed below |
1920
|[data-create-sample-schema.sql](data-create-sample-schema.sql)|Create a sample user and install sample data|
2021
|[data-create-synthetic-data.sql](data-create-synthetic-data.sql)|Use AI to generate sample data sets|
2122
|[data-import-from-datalake.sql](data-create-synthetic-data.sql)|Import sample data from Azure Data Lake. Sample data was uploaded using the [`create-all-resources.sh`](../azure-cli/create-all-resources.sh)and [`create-data-lake-storage.sh`](../azure-cli/create-data-lake-storage.sh) scripts. You can run [`show-data-lake-storage-info.sh`](../azure-cli/show-data-lake-storage-info.sh) to get connection information to the storage container.|
@@ -43,14 +44,16 @@ chmod 600 config.sql
4344
|**Select AI and GenAI**|
4445
|AZURE_OPENAI_RESOURCE_NAME|Name of the Azure OpenAI endpoint|'dev-adb-azure-openai'|
4546
|AZURE_OPENAI_ENDPOINT|Your Azure OpenAI endpoint (server name only)|'my-openai.openai.azure.com'|
46-
|AZURE_OPENAI_DEPLOYMENT_NAME|Your Azure OpenAI deployment name|'gpt-4o'|
47+
|AZURE_OPENAI_DEPLOYMENT_NAME|Your Azure OpenAI deployment name. This is used for NL2SQL and AI SQLfunctions|'gpt-4o'|
48+
|AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME|The Azure OpenAI deployment that uses an embedding model. This is used for creating vector embeddings.|'text-embedding-ada-002'|
4749
|AZURE_OPENAI_KEY|Azure OpenAI secret key|'3Cu9AB...H53'|
4850
|AZURE_OPENAI_PROFILE_NAME|The Select AI profile that will reference your Azure OpenAI deployment|'gpt4o'|
4951
|AZURE_OPENAI_CREDENTIAL_NAME|The database credential that will be used to connect to Azure OpenAI|'azure_cred4o'|
5052
|**Azure Data Lake Storage**|
5153
|STORAGE_ACCOUNT_NAME|Name of your Azure Data Lake Storage Gen 2 account. You can run [`show-data-lake-storage-info.sh`](../azure-cli/show-data-lake-storage-info.sh) to get storage details|'mysamplestorage'|
5254
|STORAGE_URL|Azure data lake storage URL|'https://mysamplestorage.blob.core.windows.net/adb-sample'
5355
|STORAGE_KEY|The secret key used to connecto Azure Data Lake Storage|'dJVNxq1YTT...jp/g=='
56+
|STORAGE_CREDENTIAL_NAME|The name of the Autonomous Database credential that's used to connect to Azure Data Lake Storage Gen 2|'adls_cred'|
5457

5558
You can find the Azure OpenAI settings in the Azure OpenAI Studio:
5659
![Azure OpenAI settings](images/azure-openai.png)

sql/config-default.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
define CONN='your-database-connection-string'
1010
-- the database user that will own the sample schema
1111
define USER_NAME='moviestream'
12-
define USER_PASSWORD='your-strong-password'
12+
--The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character
13+
define USER_PASSWORD=''
1314
--
1415
-- GENAI
1516
--
@@ -19,6 +20,8 @@ define AZURE_OPENAI_ENDPOINT='your-azure-openai-endpoint'
1920
define AZURE_OPENAI_RESOURCE_NAME='your-azure-openai-resourcename'
2021
-- Azure OpenAI deployment Name
2122
define AZURE_OPENAI_DEPLOYMENT_NAME='your-azure-openai-deployment-name'
23+
-- Azure OpenAI Embedding deployment name. This is used for creating embeddings for RAG
24+
define AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME='your-azure-openai-embedding-deployment-name'
2225
-- Azure OpenAI key
2326
define AZURE_OPENAI_KEY='your-azure-openai-key'
2427

@@ -32,4 +35,6 @@ define AZURE_OPENAI_CREDENTIAL_NAME='azure_cred4o'
3235
-- Get this information by running ../azure-cli/show-data-lake-storage-info.sh
3336
define STORAGE_KEY='your-azure-data-lake-storage-key'
3437
define STORAGE_ACCOUNT_NAME='your-azure-data-lake-storage-account-name'
35-
define STORAGE_URL='https://your-storage-url/adb-sample'
38+
define STORAGE_URL='https://your-storage-url'
39+
-- You can leave this default
40+
define STORAGE_CREDENTIAL_NAME='adls_cred'

sql/config.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
define CONN='your-database-connection-string'
1010
-- the database user that will own the sample schema
1111
define USER_NAME='moviestream'
12-
-- Password for the database user
13-
-- The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character.
12+
--The password must be between 12 and 30 characters long and must include at least one uppercase letter, one lowercase letter, and one numeric character
1413
define USER_PASSWORD=''
1514
--
1615
-- GENAI
@@ -21,6 +20,8 @@ define AZURE_OPENAI_ENDPOINT='your-azure-openai-endpoint'
2120
define AZURE_OPENAI_RESOURCE_NAME='your-azure-openai-resourcename'
2221
-- Azure OpenAI deployment Name
2322
define AZURE_OPENAI_DEPLOYMENT_NAME='your-azure-openai-deployment-name'
23+
-- Azure OpenAI Embedding deployment name. This is used for creating embeddings for RAG
24+
define AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME='your-azure-openai-embedding-deployment-name'
2425
-- Azure OpenAI key
2526
define AZURE_OPENAI_KEY='your-azure-openai-key'
2627

@@ -34,4 +35,6 @@ define AZURE_OPENAI_CREDENTIAL_NAME='azure_cred4o'
3435
-- Get this information by running ../azure-cli/show-data-lake-storage-info.sh
3536
define STORAGE_KEY='your-azure-data-lake-storage-key'
3637
define STORAGE_ACCOUNT_NAME='your-azure-data-lake-storage-account-name'
37-
define STORAGE_URL='https://your-storage-url/adb-sample'
38+
define STORAGE_URL='https://your-storage-url'
39+
-- You can leave this default
40+
define STORAGE_CREDENTIAL_NAME='adls_cred'

sql/credential-create.sql

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
ARGUMENT 1 DEFAULT 'ALL'
2+
3+
define user_param=&1
4+
undefine 1
5+
6+
prompt "Creating credential: &user_param"
7+
8+
-- Get the config information
9+
@config.sql
10+
11+
-- This procedure will recreate credentials. You can specify a credential type (storage, OpenAI)
12+
13+
DECLARE
14+
l_exists number := 0;
15+
l_type varchar2(20) := nvl(upper('&user_param'),'ALL');
16+
BEGIN
17+
-- Azure OpenAI
18+
if l_type in ('OPENAI','ALL') then
19+
-- Create your credential. Replace it if already exists
20+
select COUNT(*)
21+
into l_exists
22+
from user_credentials
23+
where upper(credential_name)=upper('&AZURE_OPENAI_CREDENTIAL_NAME');
24+
25+
IF l_exists = 1 THEN
26+
dbms_cloud.drop_credential (
27+
credential_name => '&AZURE_OPENAI_CREDENTIAL_NAME'
28+
);
29+
END IF;
30+
31+
dbms_cloud.create_credential (
32+
credential_name => '&AZURE_OPENAI_CREDENTIAL_NAME',
33+
username => 'AZURE_OPENAI',
34+
password => '&AZURE_OPENAI_KEY'
35+
);
36+
37+
END IF; -- Azure OpenAI
38+
39+
if l_type in ('STORAGE','ALL') then
40+
-- Create your credential. Replace it if already exists
41+
select COUNT(*)
42+
into l_exists
43+
from user_credentials
44+
where upper(credential_name)=upper('&STORAGE_CREDENTIAL_NAME');
45+
46+
IF l_exists = 1 THEN
47+
dbms_cloud.drop_credential (
48+
credential_name => '&STORAGE_CREDENTIAL_NAME'
49+
);
50+
END IF;
51+
52+
dbms_cloud.create_credential(
53+
credential_name => '&STORAGE_CREDENTIAL_NAME',
54+
username => '&STORAGE_ACCOUNT_NAME',
55+
password => '&STORAGE_KEY'
56+
);
57+
58+
END IF; -- Storage
59+
END;
60+
/
61+
62+
-- Review the credentials
63+
COLUMN credential_name FORMAT A40
64+
COLUMN username FORMAT A40
65+
66+
select
67+
credential_name,
68+
username
69+
from user_credentials;

sql/data-export-to-datalake.sql

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,13 @@
1111
@config.sql
1212

1313
-- Create a credential in order to connect to data lake storage
14-
BEGIN
15-
DBMS_CLOUD.CREATE_CREDENTIAL(
16-
credential_name => 'ADLS_CRED',
17-
username => '&STORAGE_ACCOUNT_NAME',
18-
password => '&STORAGE_KEY'
19-
);
20-
END;
21-
/
14+
@credential-create.sql storage
2215

2316
-- List the files in that storage container
2417
SELECT object_name, bytes
2518
FROM dbms_cloud.list_objects(
26-
credential_name => 'ADLS_CRED',
27-
location_uri => '&STORAGE_URL'
19+
credential_name => '&STORAGE_CREDENTIAL_NAME',
20+
location_uri => '&STORAGE_URL/adb-sample'
2821
);
2922

3023
--
@@ -37,8 +30,8 @@ FROM genre;
3730
-- Export in CSV format
3831
BEGIN
3932
DBMS_CLOUD.EXPORT_DATA(
40-
credential_name => 'ADLS_CRED',
41-
file_uri_list => '&STORAGE_URL/data/genre/genre',
33+
credential_name => '&STORAGE_CREDENTIAL_NAME',
34+
file_uri_list => '&STORAGE_URL/adb-sample/data/genre/genre',
4235
query => 'SELECT * FROM genre',
4336
format => JSON_OBJECT('type' VALUE 'csv', 'delimiter' VALUE ',')
4437
);
@@ -48,6 +41,6 @@ END;
4841
-- List the files in that storage container. Notice the new genre data.
4942
SELECT object_name, bytes
5043
FROM dbms_cloud.list_objects(
51-
credential_name => 'ADLS_CRED',
52-
location_uri => '&STORAGE_URL'
44+
credential_name => '&STORAGE_CREDENTIAL_NAME',
45+
location_uri => '&STORAGE_URL/adb-sample'
5346
);

sql/data-import-from-datalake.sql

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
@config.sql
77

88
-- Create a credential in order to connect to data lake storage
9-
BEGIN
10-
DBMS_CLOUD.CREATE_CREDENTIAL(
11-
credential_name => 'ADLS_CRED',
12-
username => '&STORAGE_ACCOUNT_NAME',
13-
password => '&STORAGE_KEY'
14-
);
15-
END;
16-
/
9+
@credential-create.sql storage
1710

1811
-- List the files
1912
SELECT object_name, bytes
2013
FROM dbms_cloud.list_objects(
21-
credential_name => 'ADLS_CRED',
22-
location_uri => '&STORAGE_URL'
14+
credential_name => '&STORAGE_CREDENTIAL_NAME',
15+
location_uri => '&STORAGE_URL/adb-sample'
2316
);
2417

2518
-- Create a table for movies that were created from books
@@ -37,7 +30,7 @@ CREATE TABLE movie_from_book
3730
BEGIN
3831
DBMS_CLOUD.COPY_DATA
3932
( table_name => 'MOVIE_FROM_BOOK',
40-
credential_name => 'ADLS_CRED',
33+
credential_name => '&STORAGE_CREDENTIAL_NAME',
4134
file_uri_list => 'https://storagemartygubaradb.blob.core.windows.net/adb-sample/data/movie_from_book/*.csv',
4235
field_list => 'MOVIE_NAME CHAR(4000),
4336
MOVIE_RELEASE_DATE CHAR date_format DATE MASK "YYYY-MM-DD",

sql/select-ai-create-profile.sql

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,9 @@
77

88
-- config.sql contains the endpoints, resource groups and other settings required to connect to your Azure OpenAI deployment
99
@config.sql
10-
1110

1211
-- Create a credential that allows the user to access the Azure OpenAI endpoint
13-
DECLARE
14-
l_exists number := 0;
15-
BEGIN
16-
-- Create your credential. Replace it if already exists
17-
select COUNT(*)
18-
into l_exists
19-
from user_credentials
20-
where upper(credential_name)=upper('&AZURE_OPENAI_CREDENTIAL_NAME');
21-
22-
IF l_exists = 1 THEN
23-
dbms_cloud.drop_credential (
24-
credential_name => '&AZURE_OPENAI_CREDENTIAL_NAME'
25-
);
26-
END IF;
27-
28-
29-
dbms_cloud.create_credential (
30-
credential_name => '&AZURE_OPENAI_CREDENTIAL_NAME',
31-
username => 'AZURE_OPENAI',
32-
password => '&AZURE_OPENAI_KEY'
33-
);
34-
35-
END;
36-
/
12+
@credential-create.sql openai
3713

3814
/*
3915
A Select AI profile describes the LLM you will use plus information that will be used for natural language queries. You can create as many

0 commit comments

Comments
 (0)