使用 Select AI 從自然語言提示產生 SQL
Select AI 功能允許 Autonomous AI Database 使用具有大型語言模型 (LLM) 的生成式 AI,將使用者的輸入文字轉換為 Oracle SQL。Select AI 會處理自然語言提示,以中繼資料補充提示,然後產生和執行 SQL 查詢。
支援的平台
Autonomous AI Database Serverless 和 Autonomous AI Database (客戶專用 Exadata 基礎架構和雲端) 支援 Select AI。
- Autonomous AI Database 無伺服器
- 專用 Exadata 基礎架構上的 Autonomous AI Database
- 專用 Exadata 基礎架構區域上的 Autonomous AI Database
- Autonomous AI Database Cloud@Customer
關於產生 SQL
現在,使用自然語言與資料庫資料互動,即可使用 LLM。這表示您可以使用自然語言 (例如英文) 來查詢資料庫。
使用 Select AI 時, Autonomous AI Database 會管理將自然語言轉換為 SQL 的程序。這表示您可以提供自然語言提示,而非 SQL 程式碼來與資料互動。Select AI 可作為 SQL 使用者和開發人員的生產力工具,讓非專業 SQL 使用者無須瞭解資料結構或技術語言,即可從資料中取得有用的洞察力。
DBMS_CLOUD_AI 套裝程式可與使用者指定的 LLM 整合,以使用自然語言提示產生 SQL 程式碼。套裝程式可協助 LLM 瞭解資料庫綱要,並指示其撰寫與該綱要一致的 SQL 查詢。DBMS_CLOUD_AI 套件可與 OpenAI、Cohere、Azure OpenAI Service 和 Oracle Cloud Infrastructure Generative AI 等 AI 供應商搭配使用。
附註:
使用者必須擁有 AI 提供者的帳戶,並透過 Autonomous AI Database 使用的DBMS_CLOUD_AI 物件提供其認證。
術語
請務必先瞭解 Select AI 所使用的各種術語,再加以使用。
以下是與 Select AI 功能相關的術語:
| 詞彙 | 定義 |
|---|---|
|
資料庫證明資料 |
「資料庫證明資料」是用來存取資料庫並與資料庫互動的認證證明資料。它們通常由使用者名稱和密碼組成,有時也會由其他認證因素 (例如安全記號) 補充。這些證明資料是用來建立應用程式或使用者與資料庫之間的安全連線,確保只有經過授權的個人或系統才能存取和操控資料庫中儲存的資料。 |
|
LLM 幻覺 |
「大型語言模型」的脈絡是指模型產生與輸入提示不正確、非語意或無關之文字的現象。儘管模型嘗試產生一致的文字,但這些實例可以包含結構化、誤導或純粹想像的資訊。由於訓練資料的偏差、缺乏適當的情境理解,或模型訓練過程中的限制,因此會發生虛構。 |
| IAM | Oracle Cloud Infrastructure Identity and Access Management (IAM) 可讓您控管可存取雲端資源的人員。您可以控制某個群組的使用者可具備的存取類型,以及可存取哪些特定資源。若要深入瞭解,請參閱身分識別與存取管理概要。 |
|
一般語言提示 |
自然語言提示是人類可閱讀的指示或要求,用來引導生成式 AI 模型 (例如大型語言模型)。使用者無須使用特定的程式設計語言或指令,而是可以透過在更具對話性或自然語言表單中輸入提示,與這些模型互動。接著,模型會根據提供的提示產生輸出。 |
|
網路存取控制清單 (ACL) |
「網路存取控制清單」是一組規則或權限,定義允許哪些網路流量通過網路裝置,例如路由器、防火牆或閘道。ACL 會根據各種條件 (例如 IP 位址、連接埠號碼以及協定) 來控制和篩選內送和外送流量。他們在網路安全中扮演重要角色,讓管理員能夠管理和限制網路流量,以防止未經授權的存取、潛在攻擊及資料外洩。 |
|
相似性搜尋 |
相似性搜尋會透過比較向量儲存區中的特徵向量來識別和擷取與指定查詢相符的資料點。 |
|
向量的距離 |
向量距離透過計算多維空間中特徵向量之間的距離來測量特徵向量之間的相似性或不相似性。 |
|
向量索引 |
向量索引可組織和儲存特徵向量,以有效率地搜尋和擷取相關資料。 |
|
向量儲存 |
向量儲存包括儲存、管理和啟用涉及向量內嵌語意相似性搜尋的系統。這包括獨立向量資料庫和 Oracle Database 23ai AI Vector Search。 |
用法指導方針
提供使用準則,以確保有效且正確地使用 SQL 產生所需的自然語言提示,以確保增強的使用者體驗。
用途
此功能用於產生與執行由使用者提供的自然語言提示所產生的 SQL 查詢。它會結合使用者選擇的大型語言模型 (LLM),自動根據使用者綱要描述資料執行手動作業。
雖然可以提供任何提示,包括與產生 SQL 查詢結果無關的提示,但 Select AI 著重於產生 SQL 查詢。選取 AI 可透過 chat 動作提交一般要求。
提示擴增資料
資料庫會以資料庫中繼資料來增強使用者指定的提示,以減輕 LLM 的幻燈片。然後,增強提示會傳送至使用者指定的 LLM 以產生查詢。
資料庫只會以綱要描述資料來增強提示。此描述資料可能包括綱要定義、表格和資料欄註解,以及資料說明和目錄中可用的內容。為了產生 SQL,在擴增提示時,資料庫不會提供表格或檢視內容 (實際列或欄值)。
不過,narrate 動作會將查詢的結果 (可能包含資料庫資料) 提供給使用者指定的 LLM,以產生描述查詢結果的自然語言文字。
警告:
大型語言模型 (LLM) 已接受廣泛的文字文件和內容 (通常來自網際網路) 訓練。因此,LLM 可能整合了無效或惡意內容的模式,包括 SQL 資料隱碼。因此,LLM 在產生實用且相關的內容時,也可能產生不正確和偽的資訊,包括產生不正確結果的 SQL 查詢和 (或) 危害資料的安全性。
由使用者指定的 LLM 供應商代替您產生的查詢將在您的資料庫中執行。貴方對此功能的使用須自行承擔風險,即使與 Oracle 提供的服務有關的任何其他條款及條件,亦構成貴方對此風險的接受,並明確排除 Oracle 對此使用所造成之損害賠償責任或責任。
選取您的 AI 提供者與 LLM
選擇符合您安全標準並符合特定需求 (例如文字或程式碼產生) 的 AI 提供者和 LLM。
不同的 LLM 會根據其訓練資料和目標,在各種任務中脫穎而出。有些模型非常適合產生文字,但在產生程式碼時可能表現不佳,其他模型則專門針對編碼工作進行最佳化。選擇最符合您需求的 LLM。
| AI 提供者 | LLM | RAG 的內嵌模型 | 目的 |
|---|---|---|---|
|
OCI 生成式 AI |
|
請參閱關於在生成式 AI 中嵌入模型。 |
所有 只有 |
|
Azure OpenAI 服務 |
|
文字嵌入 -ada-002 |
最適合從自然語言提示、 |
|
OpenAI |
|
文字嵌入 -ada-002 |
最適合從自然語言提示、 |
|
OpenAI- 相容 |
與 OpenAI 相容之提供者的模型,例如:
|
從 OpenAI 相容的提供者內嵌模型。例如,請參閱 Fireworks AI 內嵌模型。 |
支援廣泛的使用案例。 |
|
Cohere |
|
中文 (繁體) v2.0 |
最適用於 |
|
|
|
text-embedding-004 (預設) |
最適合從自然語言提示、 |
|
人類 |
|
無 |
最適合從自然語言提示、 |
|
Hugging Face |
|
無 |
最適合從自然語言提示、 |
|
AWS |
|
支援廣泛的使用案例。 |
附註:
-
對於接受影像的模型,請使用
meta.llama-3.2-90b-vision-instruct。此模型專門針對視覺和影像進行訓練。雖然模型可用於文字和 SQL 產生,但最適合用於影像。若要深入瞭解,請參閱在 OCI Generative AI 中交談。meta.llama-3.2-11b-vision-instruct模型提供強大的多模型功能。 -
嵌入模型也稱為變壓器模型。
關於 SQL 產生
現在可以使用自然語言與資料庫資料互動,與 LLM 達成。這表示您可以使用自然語言 (例如純英文) 來查詢資料庫。
使用 Select AI 時, Autonomous AI Database 會管理將自然語言轉換為 SQL 的程序。這表示您可以提供自然語言提示,而非 SQL 程式碼來與資料互動。Select AI 可作為 SQL 使用者和開發人員的生產力工具,讓非專業 SQL 使用者無須瞭解資料結構或技術語言,即可從資料中取得有用的洞察力。
DBMS_CLOUD_AI 套裝程式可與使用者指定的 LLM 整合,以使用自然語言提示產生 SQL 程式碼。套裝程式可協助 LLM 瞭解資料庫綱要,並指示其撰寫與該綱要一致的 SQL 查詢。DBMS_CLOUD_AI 套件可與 OpenAI、Cohere、Azure OpenAI Service 和 Oracle Cloud Infrastructure Generative AI 等 AI 供應商搭配使用。
附註:
使用者必須擁有 AI 提供者的帳戶,並透過 Autonomous AI Database 使用的DBMS_CLOUD_AI 物件提供其認證。
使用 DBMS_CLOUD_AI 設定 AI 設定檔
Autonomous AI Database 使用 AI 設定檔來協助和設定對 LLM 的存取,以及設定從自然語言提示產生 SQL 陳述式。
AI 設定檔包含作為自然語言查詢目標的資料庫物件。這些目標中使用的描述資料可以包括資料庫表格名稱、資料欄名稱、資料欄資料類型以及註解。您可以使用 DBMS_CLOUD_AI.CREATE_PROFILE 和 DBMS_CLOUD_AI.SET_PROFILE 程序建立並設定 AI 設定檔。
設定 DBMS_CLOUD_AI 套裝軟體的需求
執行 DBMS_CLOUD_AI 需要下列項目:
- 存取 Oracle Cloud Infrastructure 雲端帳戶和 Autonomous AI Database 執行處理。
- 支援 AI 提供者的付費 API 帳戶,其中之一:
-
OpenAI:若要讓 OpenAI 從自然語言提示產生 SQL,請從您的 OpenAI 付費帳戶取得 API 金鑰。
您可以在使用者設定當中找到您的私密 API 金鑰。
-
Cohere:若要讓 Cohere 能夠從自然語言提示中產生 SQL,請從您的 Cohere 付費帳戶取得 API 金鑰。
按一下儀表板,然後按一下左側導覽中的 API 金鑰。複製預設 API 金鑰或建立其他金鑰。請參閱 API-Keys 以瞭解詳細資訊。
-
Azure OpenAI Service:若要啟用 Azure OpenAI Service ,從自然語言提示產生 SQL,請設定並提供 AI 提供者的存取權。
若要使用 Azure OpenAI Service ,請執行下列步驟:
- 取得您的秘密 API 金鑰。您可以在 Azure 入口網站的 Resource Management 區段中找到您的 API 金鑰。在您的 Azure OpenAI 服務資源頁面上,按一下金鑰和端點。您可以複製 KEY1 或 KEY2。
- 建立 Azure OpenAI Service 資源並部署模型:建立及部署 Azure OpenAI Service 資源。
秘訣:
- 請注意資源名稱和部署名稱,這些參數會用來提供網路存取權限,並使用
DBMS_CLOUD_AI.CREATE_PROFILE程序建立 Azure OpenAI Service 設定檔。 - 若要深入瞭解模型上每分鐘記號的速率限制,請參閱 Azure OpenAI 服務配額和限制。
- 請注意資源名稱和部署名稱,這些參數會用來提供網路存取權限,並使用
- 允許存取 Azure OpenAI 服務:
- OCI Generative AI:請參閱 How to Generate the API Signing Key 。
- Google:若要讓 Google AI Studio 產生您自然語言提示的 SQL 和文字回應,請從您的 Google AI Studio 付費帳戶取得 API 金鑰。
- 前往 Google AI Studio 。
- 按一下「登入 Google AI Studio」。
- 按一下提示畫面上的「取得 API 金鑰」。
- 選取下一頁所有適用的選項。
- 按一下「建立 API 金鑰」。
-
按一下新專案中的「建立 API」金鑰。
此畫面會顯示進度並產生 API 金鑰。複製金鑰並儲存。
- Anthropic:若要啟用「Anthropic 開發人員主控台」以產生自然語言提示的 SQL 和文字回應,請從您的「Antropic 開發人員主控台」付費帳戶取得 API 金鑰。
- 前往 Anthropic Developer Console 。
- 若您還沒有註冊帳號,請註冊該帳號。
- 登入後,導覽至 API 區段或儀表板。
- 尋找產生或檢視 API 金鑰的選項。
- 按一下即可建立新的 API 金鑰。
-
複製產生的 API 金鑰並加以儲存。
Claude API 是付費服務。您必須先將點數新增至帳戶,才能使用 API 金鑰。
- 擁抱臉部:為了讓您的 AI 提供者能夠產生自然語言提示的 SQL 和文字回應,請從 Hugging Face 付費帳戶取得 API 金鑰。
- 前往 Hugging Face 。
- 若您還沒有註冊帳號,請註冊該帳號。
- 瀏覽至您的帳號設定。
- 在導覽功能表中,尋找「存取權杖」。
- 按一下即可建立新的 API 金鑰。
- 複製產生的 API 金鑰並加以儲存。
-
AWS:若要啟用 AWS,請取得您的 API 金鑰和模型 ID。
取得您的 API 金鑰,並使用該金鑰透過
DBMS_CLOUD.CREATE_CREDENTIAL建立證明資料。請依照此程序取得您的 API 金鑰和模型名稱:
- 如果您還沒有 AWS 帳戶,請註冊。
- 從 AWS Bedrock Console 建立您的存取金鑰和私密金鑰。
- 複製產生的關鍵碼並加以儲存。
- 要求存取其基礎模型。請參閱存取 Amazon Bedrock 基礎模型。
- 取得模型 ID。您需要
DBMS_CLOUD_AI.CREATE_PROFILE程序中的模型 ID。模型 ID 取決於您使用的資源。如果您使用的是:- 基本目錄模型,指定模型 ID 或其 ARN (Amazon 資源名稱)。如需基本目錄模型的模型 ID 清單,請參閱 Amazon Bedrock 基本目錄模型 ID
- 推論設定檔,指定推論設定檔 ID 或其 ARN。如需推論設定檔 ID 的清單,請參閱跨區域推論的支援區域與模型。
- 佈建的模型,指定「佈建的傳輸量」的 ARN。如需詳細資訊,請參閱使用佈建的傳輸量執行推論。
- 自訂模型,為其購買「佈建的傳輸量」。然後,指定產生之佈建模型的 ARN。如需詳細資訊,請參閱在 Amazon Bedrock 中使用自訂模型。
- Amazon Bedrock Marketplace 模型,請指定您所建立市集端點的 ID 或 ARN,請參閱 Amazon Bedrock Marketplace 。
附註:
Bedrock Converse API 不支援匯入的模型。
若要使用 AWS 作為提供者,請參閱範例:使用 AWS 選取 AI 。
-
- 存取您外部 AI 提供者的網路 ACL 權限。
附註:
網路 ACL 不適用於 OCI Generative AI。 - 可存取 AI 提供者的證明資料。
設定 DBMS_CLOUD_AI 套裝程式
使用 Select AI 之前,以下是啟用 DBMS_CLOUD_AI 的步驟。
DBMS_CLOUD_AI :
-
將
DBMS_CLOUD_AI套裝程式的EXECUTE權限授予想要使用 Select AI 的使用者。預設只會授予 ADMIN 使用者
EXECUTE權限。ADMIN 使用者可以將EXECUTE權限授予其他使用者。 -
將網路 ACL 存取權授予想要使用 Select AI 和 AI Provider 端點的使用者。
ADMIN 使用者可授予網路 ACL 存取權。請參閱 Oracle Database 19c PL/SQL Packages and Types Reference 中的 APPEND_HOST_ACE Procedure 或 Oracle Database 26ai PL/SQL Packages and Types Reference ,瞭解詳細資訊。
- 建立證明資料以啟用 AI 提供者的存取權。
如需詳細資訊,請參閱CREATE_CREDENTIAL 程序。
EXECUTE 權限授予 ADB_USER:grant execute on DBMS_CLOUD_AI to ADB_USER;下列範例授予 ADB_USER 使用 api.openai.com 端點的權限。
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'api.openai.com',
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => 'ADB_USER',
principal_type => xs_acl.ptype_db)
);
END;
/
APPEND_HOST_ACE 函數參數
| Parameter - 參數 | 描述 |
|---|---|
|
|
主機,可以是主機的名稱或 IP 位址。您可以使用萬用字元指定網域或 IP 子網路。主機或網域名稱不區分大小寫。 若為 OpenAI,請使用 api.openai.com。 對於 Cohere,請使用 api.cohere.ai。 對於 Azure OpenAI Service ,請使用 <azure_resource_name>.openai.azure.com。請參閱設定檔屬性以瞭解 若為 Google,請使用 generativelanguage.googleapis.com。 對於人類,請使用 api.anthropic.com。 對於 Hugging Face,請使用 api-inference.huggingface.co。 |
|
|
存取控制項目 (ACE)。系統會提供 |
以下範例說明如何建立證明資料以啟用 OpenAI 的存取權。
EXEC DBMS_CLOUD.CREATE_CREDENTIAL('OPENAI_CRED', 'OPENAI', 'your_api_token');DBMS_CLOUD.CREATE_CREDENTIAL 參數
| Parameter - 參數 | 描述 |
|---|---|
|
|
要儲存的證明資料名稱。 |
|
|
|
|
|
|
建立和設定 AI 設定檔
描述建立和啟用 AI 設定檔的步驟。
請使用 DBMS_CLOUD_AI.CREATE_PROFILE 建立 AI 設定檔。接下來啟動 DBMS_CLOUD_AI.SET_PROFILE 以啟用 AI 設定檔,以便搭配使用 SELECT AI 搭配自然語言提示。
附註:
您必須先在每個新的資料庫階段作業 (連線) 中執行 DBMS_CLOUD_AI.SET_PROFILE ,才能使用 SELECT AI。
下列使用 OpenAI 提供者的範例會建立名為 OPENAI 的 AI 設定檔,並設定目前使用者階段作業的 OPENAI 設定檔。
-- Create AI profile
--
SQL> BEGIN
DBMS_CLOUD_AI.create_profile(
'OPENAI',
'{"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;
/
PL/SQL procedure successfully completed.
--
-- Enable AI profile in current session
--
SQL> EXEC DBMS_CLOUD_AI.set_profile('OPENAI');
PL/SQL procedure successfully completed.
使用 AI 關鍵字輸入提示
使用 AI 作為 SELECT 敘述句中的關鍵字,以使用自然語言提示與資料庫互動。
SELECT 陳述式中的 AI 關鍵字會指示 SQL 執行引擎使用作用中 AI 設定檔中識別的 LLM 來處理自然語言並產生 SQL。
您可以在查詢中使用 AI 關鍵字與 Oracle 從屬端 (例如 SQL Developer、OML Notebooks 和第三方工具) 進行互動,以自然語言與資料庫進行互動。
附註:
您無法使用AI 關鍵字執行 PL/SQL 敘述句、DDL 敘述句或 DML 敘述句。
語法
SELECT AI action natural_language_prompt參數
| Parameter - 參數 | 描述 |
|---|---|
|
|
使用自然語言提示執行提供的 SQL 命令。此為預設動作,可選擇是否指定此參數。 |
|
|
顯示自然語言提示的 SQL 陳述式。 |
|
|
提示的輸出會以自然語言來說明。此選項會將 SQL 結果傳送給 AI 提供者,以產生自然語言摘要。 |
|
|
根據提示直接從 LLM 產生回應。如果 |
|
|
提示產生的 SQL 是以自然語言來說明。此選項會將產生的 SQL 傳送給 AI 提供者,以產生自然語言說明。 |
使用注意事項
-
「資料庫動作」或 APEX 服務不支援選取
AI。您只能使用DBMS_CLOUD_AI.GENERATE函數。 -
AI關鍵字僅在SELECT陳述式中支援。 -
您無法使用
AI關鍵字執行 PL/SQL 敘述句、DDL 敘述句或 DML 敘述句。 -
序列為
SELECT,後面接著AI。這些關鍵字沒有大小寫之別。設定DBMS_CLOUD_AI.SET_PROFILE之後,SELECT AI之後的文字即為自然語言提示。如果未設定 AI 設定檔,SELECTAI會報告下列錯誤:ORA-00923: FROM keyword not found where expected 00923. 00000 - "FROM keyword not found where expected" -
依據 Oracle 準則套用特殊字元使用規則。例如,如果您在句子中使用單引號,請使用兩次單引號。
select ai how many customers in SF don''t own their own home -
LLM 需遵守 hallucinations ,結果並非總是正確的:
-
SELECT AI可能無法針對特定自然語言提示執行產生的 SQL。 -
SELECT AI可能無法產生特定自然語言提示的 SQL。
在此情況下,
SELECT AI會回應資訊以協助您產生有效的 SQL。 -
-
使用
chat動作搭配SELECT AI chat以進一步瞭解 SQL 建構。若要取得chat動作的較佳結果,請使用含有相關內容資料欄名稱的資料庫檢視或表格,或考慮新增說明資料欄中儲存值的資料欄註解。 -
若要存取 DBA 或 USER 視觀表,請參閱 DBMS_CLOUD_AI Views 。
範例:選取 AI 動作
這些範例說明常見的 Select AI 動作。
下列範例說明可以使用 SELECT AI 執行的動作,例如 runsql (預設值)、showsql、narrate、chat、explainsql、feedback 和 summarize。這些範例使用 sh 綱要搭配 AI 提供者,以及 DBMS_CLOUD_AI.CREATE_PROFILE 函數中指定的設定檔屬性。在目前階段作業中使用 DBMS_CLOUD_AI.SET_PROFILE 程序設定 AI 設定檔之後,請使用「選取 AI 動作」。
若要產生文字摘要,請使用 SELECT AI SUMMARIZE <TEXT>。
SQL> select ai how many customers exist;
CUSTOMER_COUNT
--------------
55500
SQL> select ai showsql how many customers exist;
RESPONSE
----------------------------------------------------
SELECT COUNT(*) AS total_customers
FROM SH.CUSTOMERS
SQL> select ai narrate how many customers exist;
RESPONSE
------------------------------------------------------
There are a total of 55,500 customers in the database.
SQL> select ai chat how many customers exist;
RESPONSE
--------------------------------------------------------------------------------
It is impossible to determine the exact number of customers that exist as it con
stantly changes due to various factors such as population growth, new businesses
, and customer turnover. Additionally, the term "customer" can refer to individu
als, businesses, or organizations, making it difficult to provide a specific num
ber.
SQL> select ai explainsql how many customers in San Francisco are married;
RESPONSE
--------------------------------------------------------------------------------
SELECT COUNT(*) AS customer_count
FROM SH.CUSTOMERS AS c
WHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married';
Explanation:
- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.
- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.
- The 'WHERE' clause is used to filter the results:
- 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province.
- 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.
The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result.
Remember to adjust the table and column names based on your actual schema if they differ from the example.
Feel free to ask if you have more questions related to SQL or database in general.
-- Feedback on SQL Text
-- Negative feedback example:
SQL > select ai feedback for query "select ai showsql how many watch histories in total", please use sum instead of count;
-- Positive feedback example:
SQL > select ai feedback for query "select ai showsql how many watch histories in total", the sql query generated is correct;
-- Feedback on SQL ID
-- Negative feedback example:
SQL > select ai feedback please use sum instead of count for sql_id 1v1z68ra6r9zf;
-- Positive feedback example:
SQL > select ai feedback sql query result is correct for sql_id 1v1z68ra6r9zf;
-- If not specified, use default LASTAI SQL
-- To use default LASTAI sql, make sure that set server output off;
-- Negative feedback example:
SQL > select ai feedback please use ascending sorting for ranking;
-- Positive feedback example:
SQL > select ai feedback the result is correct;
SQL> SELECT AI SUMMARIZE
Like countless other people around the globe, I stream music, and like more
than six hundred million of them I mainly use Spotify. Streaming currently
accounts for about eighty per cent of the American recording industry’s
revenue, and in recent years Spotify’s health is often consulted as a measure
for the health of the music business over all. Last spring, the International
Federation of the Phonographic Industry reported global revenues of $28.6
billion, making for the ninth straight year of growth. All of this was
unimaginable in the two-thousands, when the major record labels appeared
poorly equipped to deal with piracy and the so-called death of physical media.
On the consumer side, the story looks even rosier. Adjusted for inflation, a
... (skipped 1000 rows in the middle)
Pelly writes of some artists, in search of viral fame, who surreptitiously use
social media to effectively beta test melodies and motifs, basically putting
together songs via crowdsourcing. Artists have always fretted about the
pressure to conform, but the data-driven, music-as-content era feels
different. “You are a Spotify employee at that point,” Daniel Lopatin, who
makes abstract electronic music as Oneohtrix Point Never, told Pelly. “If your
art practice is so ingrained in the brutal reality that Spotify has outlined
for all of us, then what is the music that you’re not making? What does the
music you’re not making sound like?” Listeners might wonder something similar.
What does the music we’re not hearing sound like?;
RESPONSE
------------------------------------------------------------------------------
The music streaming industry, led by Spotify, has revolutionized the way
people consume music, with streaming accounting for 80% of the American
recording industry's revenue. However, this shift has also complicated the
lives of artists, who struggle to survive in a hyper-abundant present where
music is often valued for its convenience rather than its artistic merit.
Spotify's algorithms prioritize popularity and profitability over artistic
diversity, leading to a homogenization of music and a devaluation of the
labor that goes into creating it. Meanwhile, the company's executives reap
enormous profits, with CEO Daniel Ek's net worth rivaling that of the
wealthiest musicians. As music critic Liz Pelly argues, the streaming economy
raises important questions about autonomy, creativity, and the value of art
in a world where everything is readily available and easily accessible.
範例:使用 AWS 選取 AI
以下範例顯示如何使用 AWS 作為 Amazon Bedrock 的 AI 供應商及其基礎模型。此範例顯示建立 AWS 證明資料、提供網路存取、建立 AI 設定檔,以及使用 Select AI 動作從自然語言提示產生 SQL 查詢,以及使用 AWS 基礎模型進行交談。
若要使用 AWS,請取得存取金鑰、秘密金鑰以及模型 ID。請參閱。使用模型 ID 作為 DBMS_CLOUD_AI.CREATE_PROFILE 程序中的 model 屬性。您必須明確指定 model 屬性,因為未提供預設模型。
--Grant EXECUTE privilege to ADB_USER
GRANT EXECUTE on DBMS_CLOUD_AI to ADB_USER;
--
-- Create Credential for AI provider
--
BEGIN
DBMS_CLOUD.CREATE_CREDENTIAL(
credential_name => 'AWS_CRED',
username => '<your_AWS_access_key>',
password => '<your_AWS_secret_key>'
);
END;
/
PL/SQL procedure successfully completed.
--
-- Grant Network ACL for AWS
--
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'bedrock-runtime.us-east-1.amazonaws.com',
ace => xs$ace_type(privilege_list => xs$name_list('http'),
principal_name => 'ADB_USER',
principal_type => xs_acl.ptype_db)
);
END;
/
PL/SQL procedure successfully completed.
--
-- Create AI profile
--
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name =>'AWS',
attributes =>'{"provider": "aws",
"credential_name": "AWS_CRED",
"object_list": [{"owner": "SH", "name": "customers"},
{"owner": "SH", "name": "countries"},
{"owner": "SH", "name": "supplementary_demographics"},
{"owner": "SH", "name": "profits"},
{"owner": "SH", "name": "promotions"},
{"owner": "SH", "name": "products"}],
"model" : "anthropic.claude-v2",
"conversation" : "true"
}');
END;
/
PL/SQL procedure successfully completed.
--
-- Enable AI profile in current session
--
EXEC DBMS_CLOUD_AI.SET_PROFILE('AWS');
PL/SQL procedure successfully completed.
--
-- Use AI
--
SELECT AI how many customers exist;
"RESPONSE"
"COUNT(*)"
55500
SELECT AI how many customers in San Francisco are married;
"RESPONSE"
"COUNT(*)"
46
SELECT AI showsql how many customers in San Francisco are married;
"RESPONSE"
"SELECT COUNT(*) AS "Number of Married Customers in San Francisco"
FROM "SH"."CUSTOMERS" C
WHERE UPPER(C."CUST_CITY") = UPPER('San Francisco')
AND UPPER(C."CUST_MARITAL_STATUS") = UPPER('Married')"
SELECT AI explainsql how many customers in San Francisco are married;
"RESPONSE""SELECT
COUNT(*) AS "Number of Married Customers in San Francisco"
FROM "SH"."CUSTOMERS" C
WHERE C."CUST_CITY" = 'San Francisco'
AND C."CUST_MARITAL_STATUS" = 'Married'
Explanation:
- Used table alias C for CUSTOMERS table
- Used easy to read column names like CUST_CITY, CUST_MARITAL_STATUS
- Enclosed table name, schema name and column names in double quotes
- Compared string values in WHERE clause without UPPER() since the values are not in double quotes
- Counted number of rows satisfying the condition and aliased the count as "Number of Married Customers in San Francisco""
SELECT AI narrate what are the top 3 customers in San Francisco;
"RESPONSE"
The top 3 customers in San Francisco ordered by credit limit in descending order are:
1. Bert Katz
2. Madallyn Ladd
3. Henrietta Snodgrass
SELECT AI chat what is Autonomous AI Database;
"RESPONSE"
"An Autonomous AI Database is a cloud database service provided by Oracle Corporation. Some key features of Oracle Autonomous AI Database include:
- Fully automated and self-driving - The database automatically upgrades, patches, tunes, and backs itself up without any human intervention required.
- Self-securing - The database uses machine learning to detect threats and automatically apply security updates.
- Self-repairing - The database monitors itself and automatically recovers from failures and errors without downtime.
- Self-scaling - The database automatically scales compute and storage resources up and down as needed to meet workload demands.
- Serverless - The database is accessed as a cloud service without having to manually provision any servers or infrastructure.
- High performance - The database uses Oracle's advanced automation and machine learning to continuously tune itself for high performance.
- Multiple workload support - Supports transaction processing, analytics, graph processing, etc in a single converged database.
- Fully managed - Oracle handles all the management and administration of the database. Users just load and access their data.
- Compatible - Supports common SQL and Oracle PL/SQL for easy migration from on-prem Oracle databases.
So in summary, an Oracle Autonomous AI Database is a fully automated, self-driving, self-securing, and self-repairing database provided as a simple cloud service. The automation provides high performance, elasticity, and availability with minimal human labor required."
--
--Clear the profile
--
BEGIN
DBMS_CLOUD_AI.CLEAR_PROFILE;
END;
/
PL/SQL procedure successfully completed.
--
--Drop the profile
--
EXEC DBMS_CLOUD_AI.DROP_PROFILE('AWS');
PL/SQL procedure successfully completed.