將適用於 PostgreSQL 的 Azure Database 彈性伺服器與 Azure Machine Learning 服務整合

Azure AI 延伸模組可讓您從 SQL 內叫用部署在 Azure Machine Learning 線上端點 上部署的任何機器學習模型。 這些模型可以來自 Azure Machine Learning 目錄或已定型和部署的自訂模型。

先決條件

備註

您可以探索 Azure Machine Learning 範例

設定 Azure Machine Learning 端點

在 Azure Machine Learning Studio 的 [端點]>[挑選您的端點]>[取用] 下,您可以找到線上端點的端點 URI 和金鑰。 使用這些值來設定 azure_ai 延伸模組,以使用線上推斷端點。

select azure_ai.set_setting('azure_ml.scoring_endpoint','<URI>');
select azure_ai.set_setting('azure_ml.endpoint_key', '<Key>');

azure_ml.invoke

透過在 線上端點 上叫用 Azure Machine Learning 模型部署,對輸入資料進行評分。

azure_ml.invoke(input_data jsonb, timeout_ms integer DEFAULT NULL, throw_on_error boolean DEFAULT true, deployment_name text DEFAULT NULL)

Arguments

input_data

jsonb 包含模型請求酬載的 JSON。

deployment_name

text 對應至 Azure Machine Learning 線上推斷端點上所部署之模型的部署名稱

timeout_ms

作業停止之前的 integer DEFAULT NULL 逾時 (以毫秒為單位)。 模型本身的部署可以指定逾時,其值低於使用者定義函式中的逾時參數。 如果超過此逾時,評分作業將會失敗。

throw_on_error

boolean DEFAULT true 如果發生錯誤,函式會擲回例外狀況導致換行交易復原。

max_attempts

integer DEFAULT 1 擴充功能在因任何可重試錯誤而失敗時,重試呼叫 Azure Machine Learning 端點的次數。

retry_delay_ms

integer DEFAULT 1000 當它失敗並出現任何可重試的錯誤時,延伸模組在呼叫 Azure Machine Learning 端點之前等候的時間 (毫秒)。

傳回類型

jsonb JSONB 中叫用之模型的評分輸出。

範例

叫用機器學習模型

這會以 input_data 呼叫模型,並傳回 JSONB 酬載。

-- Invoke model, input data depends on the model.
  SELECT * FROM azure_ml.invoke('
  {
    "input_data": [
      [1,2,3,4,5,6,7,8],
      [-1,-2,-3,-4,-5,-6,-7,-8]
    ],
    "params": {}
  }', deployment_name=>'Housingprediction' )

-- Get JSON elements from model output
SELECT jsonb_array_elements(invoke.invoke) as MedianHousePrediction
FROM azure_ml.invoke('
{
  "input_data": [
    [1,2,3,4,5,6,7,8],
    [-1,-2,-3,-4,-5,-6,-7,-8]
  ],
 "params": {}
}', deployment_name=>'Housingprediction' )