データ ソース - Azure Machine Learning インデックス (プレビュー)

Azure OpenAI On Your Data を使用するときの Azure Machine Learning インデックスの構成可能オプション。 このデータ ソースは API バージョン 2024-02-15-preview でサポートされています。

名前 タイプ Required 説明
parameters パラメーター True Azure Machine Learning インデックスを構成するときに使用するパラメーター。
type string True azure_ml_indexである必要があります。

パラメーター

件名 タイプ Required Description
project_resource_id string True Azure Machine Learning プロジェクトのリソース ID。
name string True Azure Machine Learning インデックス名。
version string True Azure Machine Learning インデックスのバージョン。
authentication AccessTokenAuthenticationOptionsSystemAssignedManagedIdentityAuthenticationOptionsUserAssignedManagedIdentityAuthenticationOptions のいずれか True 定義されたデータ ソースにアクセスするときに使用する認証方法。
in_scope boolean False クエリをインデックス付きデータの使用に制限するかどうか。 既定値は True です。
role_information string False ふるまいに関する指示と、応答の生成時に参照する必要があるコンテキストをモデルに与えます。 アシスタントのパーソナリティを説明し、応答の書式設定方法を伝えることができます。
strictness integer False 検索の関連性フィルター処理の構成された厳密度。 厳密度が高いほど、精度は高くなりますが、回答の再現率は低くなります。 既定値は 3 です。
top_n_documents integer False 構成されたクエリの特徴量に対して構成されている上位のドキュメントの数。 既定値は 5 です。
filter string False 検索フィルター。 Azure Machine Learning インデックスの種類が Azure Search の場合にのみサポートされます。

アクセス トークン認証オプション

アクセス トークンを使用する場合の Azure OpenAI On Your Data の認証オプション。

名前 タイプ Required Description
access_token string True 認証に使用するアクセス トークン。
type string True access_tokenである必要があります。

システム割り当てマネージド ID 認証オプション

システム割り当てマネージド ID を使用する場合の Azure OpenAI On Your Data の認証オプション。

名前 タイプ Required Description
type string True system_assigned_managed_identityである必要があります。

ユーザー割り当てマネージド ID 認証オプション

ユーザー割り当てマネージド ID を使用する場合の Azure OpenAI On Your Data の認証オプション。

名前 タイプ Required Description
managed_identity_resource_id string True 認証に使用するユーザー割り当てマネージド ID のリソース ID。
type string True user_assigned_managed_identityである必要があります。

前提条件:

  • Azure OpenAI システム割り当てマネージド ID から Azure Machine Learning ワークスペース リソースへのロールの割り当てを構成します。 必要なロール: AzureML Data Scientist
  • ユーザーから Azure OpenAI リソースへのロールの割り当てを構成します。 必要なロール: Cognitive Services OpenAI User
  • Az CLI をインストールし、az login を実行します。
  • 環境変数 AzureOpenAIEndpointChatCompletionsDeploymentNameProjectResourceIdIndexNameIndexVersion を定義します。
  • MINGW を使用している場合、export MSYS_NO_PATHCONV=1 を実行します。
export AzureOpenAIEndpoint=https://example.openai.azure.com/
export ChatCompletionsDeploymentName=turbo
export ProjectResourceId='/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.MachineLearningServices/workspaces/{workspace-id}'
export IndexName=testamlindex
export IndexVersion=2

最新の pip パッケージ openaiazure-identity をインストールします。

import os
from openai import AzureOpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider

endpoint = os.environ.get("AzureOpenAIEndpoint")
deployment = os.environ.get("ChatCompletionsDeploymentName")
project_resource_id = os.environ.get("ProjectResourceId")
index_name = os.environ.get("IndexName")
index_version = os.environ.get("IndexVersion")

token_provider = get_bearer_token_provider(
    DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default")

client = AzureOpenAI(
    azure_endpoint=endpoint,
    azure_ad_token_provider=token_provider,
    api_version="2024-02-15-preview",
)

completion = client.chat.completions.create(
    model=deployment,
    messages=[
        {
            "role": "user",
            "content": "Who is DRI?",
        },
    ],
    extra_body={
        "data_sources": [
            {
                "type": "azure_ml_index",
                "parameters": {
                    "project_resource_id": project_resource_id,
                    "name": index_name,
                    "version": index_version,
                    "authentication": {
                        "type": "system_assigned_managed_identity"
                    },
                }
            }
        ]
    }
)

print(completion.model_dump_json(indent=2))