警告
Azure AI 検索 Vector Store の機能はプレビュー段階であり、破壊的変更を必要とする機能強化は、リリース前の限られた状況で引き続き発生する可能性があります。
警告
セマンティック カーネル ベクター ストア機能はプレビュー段階であり、破壊的変更を必要とする機能強化は、リリース前の限られた状況で引き続き発生する可能性があります。
警告
セマンティック カーネル ベクター ストア機能はプレビュー段階であり、破壊的変更を必要とする機能強化は、リリース前の限られた状況で引き続き発生する可能性があります。
概要
Azure AI 検索 Vector Store コネクタを使用して、Azure AI 検索 のデータにアクセスして管理できます。 コネクタには次の特性があります。
| 機能分野 | サポート |
|---|---|
| コレクション マップ先 | Azure AI 検索 インデックス |
| サポートされているキー プロパティの種類 | 文字列 |
| サポートされているデータ プロパティ型 |
|
| サポートされているベクター プロパティ型 |
|
| サポートされているインデックスの種類 |
|
| サポートされている距離関数 |
|
| サポートされているフィルター句 |
|
| レコード内の複数のベクターをサポートします | はい |
| IsIndexed はサポートされていますか? | はい |
| IsFullTextIndexed がサポートされていますか? | はい |
| StorageName がサポートされていますか? | いいえ。代わりに JsonSerializerOptions と JsonPropertyNameAttribute を使用してください。
詳細については、こちらを参照してください。 |
| HybridSearch はサポートされていますか? | はい |
| 機能分野 | サポート |
|---|---|
| コレクション マップ先 | Azure AI 検索 インデックス |
| サポートされているキー プロパティの種類 | 文字列 |
| サポートされているデータ プロパティ型 |
|
| サポートされているベクター プロパティ型 |
|
| サポートされているインデックスの種類 |
|
| サポートされている距離関数 |
|
| サポートされているフィルター句 |
|
| レコード内の複数のベクターをサポートします | はい |
| IsFilterable がサポートされていますか? | はい |
| IsFullTextSearchable がサポートされていますか? | はい |
| 機能分野 | サポート |
|---|---|
| コレクション マップ先 | Azure AI 検索 インデックス |
| サポートされているキー プロパティの種類 | 文字列 |
| サポートされているデータ プロパティ型 |
|
| サポートされているベクター プロパティ型 | ReadOnlyMemory<float> |
| サポートされているインデックスの種類 |
|
| サポートされている距離関数 |
|
| サポートされているフィルター句 |
|
| レコード内の複数のベクターをサポートします | はい |
| IsFilterable がサポートされていますか? | はい |
| IsFullTextSearchable がサポートされていますか? | はい |
| StorageName がサポートされていますか? | いいえ。代わりに JsonSerializerOptions と JsonPropertyNameAttribute を使用してください。
詳細については、こちらを参照してください。 |
制限事項
Azure AI 検索 コネクタの機能に関する重要な制限事項。
| 機能分野 | 回避策 |
|---|---|
| コレクションの作成時にフルテキスト検索アナライザーを構成することはサポートされていません。 | コレクションの作成に Azure AI 検索 クライアント SDK を直接使用する |
作業の開始
Azure AI 検索 Vector Store コネクタ NuGet パッケージをプロジェクトに追加します。
dotnet add package CommunityToolkit.VectorData.AzureAISearch
コネクタ パッケージによって提供される拡張メソッドを使用して、 KernelBuilder で使用できる依存関係挿入コンテナーまたは IServiceCollection 依存関係挿入コンテナーにベクター ストアを追加できます。
using Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
// Using Kernel Builder.
var kernelBuilder = Kernel
.CreateBuilder();
kernelBuilder.Services
.AddAzureAISearchVectorStore(new Uri(azureAISearchUri), new AzureKeyCredential(secret));
using Azure;
using Microsoft.Extensions.DependencyInjection;
// Using IServiceCollection with ASP.NET Core.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAzureAISearchVectorStore(new Uri(azureAISearchUri), new AzureKeyCredential(secret));
パラメーターを受け取たない拡張メソッドも提供されます。 これには、Azure AI 検索 SearchIndexClient のインスタンスを依存関係挿入コンテナーに個別に登録する必要があります。
using Azure;
using Azure.Search.Documents.Indexes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
// Using Kernel Builder.
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.Services.AddSingleton<SearchIndexClient>(
sp => new SearchIndexClient(
new Uri(azureAISearchUri),
new AzureKeyCredential(secret)));
kernelBuilder.Services.AddAzureAISearchVectorStore();
using Azure;
using Azure.Search.Documents.Indexes;
using Microsoft.Extensions.DependencyInjection;
// Using IServiceCollection with ASP.NET Core.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<SearchIndexClient>(
sp => new SearchIndexClient(
new Uri(azureAISearchUri),
new AzureKeyCredential(secret)));
builder.Services.AddAzureAISearchVectorStore();
Azure AI 検索 Vector Store インスタンスを直接構築できます。
using Azure;
using Azure.Search.Documents.Indexes;
using CommunityToolkit.VectorData.AzureAISearch;
var vectorStore = new AzureAISearchVectorStore(
new SearchIndexClient(
new Uri(azureAISearchUri),
new AzureKeyCredential(secret)));
名前付きコレクションへの直接参照を構築できます。
using Azure;
using Azure.Search.Documents.Indexes;
using CommunityToolkit.VectorData.AzureAISearch;
var collection = new AzureAISearchCollection<string, Hotel>(
new SearchIndexClient(new Uri(azureAISearchUri), new AzureKeyCredential(secret)),
"skhotels");
作業の開始
Azure AI 検索 SDK を含む Azure extras を使用してセマンティック カーネルをインストールします。
pip install semantic-kernel[azure]
その後、AzureAISearchStore クラスを使用してベクター ストア インスタンスを作成できます。これにより、AZURE_AI_SEARCH_ENDPOINT と AZURE_AI_SEARCH_API_KEY の環境変数が使用されて Azure AI 検索 インスタンスに接続します。これらの値を直接指定することもできます。 API キーの代わりに Azure 資格情報またはトークン資格情報を指定することもできます。
from semantic_kernel.connectors.azure_ai_search import AzureAISearchStore
vector_store = AzureAISearchStore()
また、Azure Search クライアントの独自のインスタンスを使用してベクター ストアを作成することもできます。
from azure.search.documents.indexes import SearchIndexClient
from semantic_kernel.connectors.azure_ai_search import AzureAISearchStore
search_client = SearchIndexClient(endpoint="https://<your-search-service-name>.search.windows.net", credential="<your-search-service-key>")
vector_store = AzureAISearchStore(search_index_client=search_client)
コレクションを直接作成することもできます。
from semantic_kernel.connectors.azure_ai_search import AzureAISearchCollection
collection = AzureAISearchCollection(
record_type=hotel,
collection_name="skhotels"
)
シリアル化
Azure AI 検索 コネクタには、入力としてインデックスに対応するフィールドを含む単純なディクテーションが必要であるため、シリアル化は非常に簡単で、インデックス フィールドに対応するキーを持つ値を含むディクテーションを返すだけです。dict からストア モデルへの組み込みの手順は、作成されたディクテーションの直線パススルーです。
この概念の詳細については、シリアル化ドキュメントを参照してください。
作業の開始
次の依存関係を pom.xmlに追加して、Maven プロジェクトにセマンティック カーネル Azure AI 検索 データ コネクタの最新バージョンを含めます。
<dependency>
<groupId>com.microsoft.semantic-kernel</groupId>
<artifactId>semantickernel-data-azureaisearch</artifactId>
<version>[LATEST]</version>
</dependency>
その後、 AzureAISearchVectorStore クラスを使用して、AzureAISearch クライアントをパラメーターとして持つベクター ストア インスタンスを作成できます。
import com.azure.core.credential.AzureKeyCredential;
import com.azure.search.documents.indexes.SearchIndexClientBuilder;
import com.microsoft.semantickernel.data.azureaisearch.AzureAISearchVectorStore;
import com.microsoft.semantickernel.data.azureaisearch.AzureAISearchVectorStoreOptions;
import com.microsoft.semantickernel.data.azureaisearch.AzureAISearchVectorStoreRecordCollection;
import com.microsoft.semantickernel.data.azureaisearch.AzureAISearchVectorStoreRecordCollectionOptions;
public class Main {
public static void main(String[] args) {
// Build the Azure AI Search client
var searchClient = new SearchIndexClientBuilder()
.endpoint("https://<your-search-service-name>.search.windows.net")
.credential(new AzureKeyCredential("<your-search-service-key>"))
.buildAsyncClient();
// Build an Azure AI Search Vector Store
var vectorStore = AzureAISearchVectorStore.builder()
.withSearchIndexAsyncClient(searchClient)
.withOptions(new AzureAISearchVectorStoreOptions())
.build();
}
}
コレクションを直接作成することもできます。
var collection = new AzureAISearchVectorStoreRecordCollection<>(searchClient, "skhotels",
AzureAISearchVectorStoreRecordCollectionOptions.<Hotel>builder()
.withRecordClass(Hotel.class)
.build());
データ マッピング
データ モデルからストレージへのデータのマッピング時に Azure AI 検索 コネクタによって使用される既定のマッパーは、Azure AI 検索 SDK によって提供されるマッパーです。
このマッパーは、データ モデルのプロパティの一覧を Azure AI 検索 のフィールドに直接変換し、 System.Text.Json.JsonSerializer を使用してストレージ スキーマに変換します。 つまり、データ モデルのプロパティ名に別のストレージ名が必要な場合は、 JsonPropertyNameAttribute の使用がサポートされます。
カスタマイズされたプロパティの名前付けポリシーでカスタム JsonSerializerOptions インスタンスを使用することもできます。 これを有効にするには、 JsonSerializerOptions を SearchIndexClient と構築時の AzureAISearchCollection の両方に渡す必要があります。
var jsonSerializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseUpper };
var collection = new AzureAISearchCollection<string, Hotel>(
new SearchIndexClient(
new Uri(azureAISearchUri),
new AzureKeyCredential(secret),
new() { Serializer = new JsonObjectSerializer(jsonSerializerOptions) }),
"skhotels",
new() { JsonSerializerOptions = jsonSerializerOptions });