Closed1
Azure OpenAI ServiceのOn Your DataのAPIで複数のAzure AI Searchの検索インデックスの指定ができるのか?

概要
Azure OpenAI ServiceではOn Your DataのAPIでデータソースを指定して検索拡張生成(RAG)に対応しています。
このデータソースのパラメータは配列形式であり、こちらを複数指定できるのでは?と考えたので試してみました。
なお先に結論を述べておくと、複数のパラメータを指定することはできませんでした。残念です。
data_sources
パラメータの説明
以下はドキュメントのdata_sources
パラメータの説明です。
名前 | タイプ | Required | 説明 |
---|---|---|---|
data_sources | DataSource[] | True | Azure OpenAI On Your Data の構成エントリ。 配列には 1 つの要素が必要です。 指定されていない場合、data_sources サービスはチャット入力候補モデルを直接使用し、Azure OpenAI On Your Data を使用しません。 data_sources パラメーターを指定すると、logprobsまたはtop_logprobsパラメーターを使用できなくなります。 |
**「配列には1つの要素が必要です」**とありますが、複数指定できるのかについては正確には読み取れませんでしたので、実際に2つ指定してリクエストを送ってみて検証してみます。
試したコード
以下が試したコードです。
from openai import AzureOpenAI
endpoint = "<aoaiのエンドポイント>"
api_key = "<aoaiのapiキー>"
deployment = "<aoaiのデプロイメント名>"
search_endpoint = "<ai searchのエンドポイント>"
search_index_1 = "ai-search-index-1"
search_index_2 = "ai-search-index-1"
search_api_key = "<ai searchのapiキー>"
client = AzureOpenAI(
azure_endpoint=endpoint,
api_key=api_key,
api_version="2024-02-01",
)
completion = client.chat.completions.create(
model=deployment,
messages=[
{
"role": "user",
"content": "AI活用の重要な点を教えてください。",
},
],
extra_body={
"data_sources": [
{
"type": "azure_search",
"parameters": {
"endpoint": search_endpoint,
"index_name": search_index_1,
"authentication": {
"type": "api_key",
"key": search_api_key
}
}
},
{
"type": "azure_search",
"parameters": {
"endpoint": search_endpoint,
"index_name": search_index_2,
"authentication": {
"type": "api_key",
"key": search_api_key
}
}
}
]
}
)
print(completion.model_dump_json(indent=2))
結果としては以下のようにバリデーションエラーとなります。
BadRequestError: Error code: 400 - {'error': {'requestid': '******', 'code': 400, 'message': 'Validation error at #/data_sources: List should have at most 1 item after validation, not 2'}}
バリデーションエラーのメッセージを読む限り、data_sources
パラメータには1つの要素しか指定できないようですね。
まとめ
Azure OpenAI ServiceではOn Your DataのAPIでのデータソースの指定では、パラメータ自体は配列であるもののデータソースは1つしか指定できません。
複数の検索インデックスのように複数のデータソースからの検索拡張回答(RAG)には、このAPIでは対応していないということがわかりました。
現状では、そのようなユースケースでは自前で検索(Retrieval )部分を実装し、コンテキストに加えるしか方法はなさそうです。
このスクラップは5ヶ月前にクローズされました