in experiments/create-search-index/src/Services/IndexManager.cs [23:49]
public async Task Create(bool dropIfIndexExists)
{
// Check if the index exists and drop if configured
var indexExists = _searchIndexClient.GetIndexNames().Any(name => name == _searchClient.IndexName);
if (dropIfIndexExists && indexExists)
await _searchIndexClient.DeleteIndexAsync(_searchClient.IndexName);
// Create the index
var searchFields = new FieldBuilder().Build(typeof(IndexDocument));
var indexDefinition = new SearchIndex(_searchClient.IndexName)
{
VectorSearch = new()
{
Profiles =
{
new VectorSearchProfile(Constants.IMAGE_VECTOR_SEARCH_PROFILE_NAME, Constants.VECTOR_SEARCH_HNSW_CONFIG)
},
Algorithms =
{
new HnswAlgorithmConfiguration(Constants.VECTOR_SEARCH_HNSW_CONFIG)
}
},
Fields = searchFields
};
await _searchIndexClient.CreateIndexAsync(indexDefinition);
}