I am unable to create index in Azure AI search using C#
I have followed below git repo to create index in Azure AI Search (Line 231 - 307) https://github.com/Azure/azure-search-vector-samples/blob/main/demo-dotnet/DotNetVectorDemo/Program.cs
I am not using SemanticSearch so removed code from Line 266 - 283
Below is the code
public static async Task Main(string[] args)
{
SetUpIndex();
}
public static async Task SetUpIndex()
{
const string vectorSearchHnswProfile = "my-vector-profile";
const string vectorSearchHnswConfig = "myHnsw";
const string vectorSearchVectorizer = "myOpenAIVectorizer";
const string semanticSearchConfig = "my-semantic-config";
const string indexName = "my-demo-index-dummyindex";
const string AzureOpenAIEmbeddingDimensions = "1024";
try
{
Console.WriteLine("Initializing Azure Search Service");
SearchIndexClient indexclient = new SearchIndexClient(new Uri(searchServiceEndpoint), new AzureKeyCredential(searchApiKey));
//passing searchServiceEndpoint and key in searchApiKey
Console.WriteLine("Connected to Azure AI Search");
SearchIndex searchIndex = new(indexName)
{
VectorSearch = new()
{
Profiles =
{
new VectorSearchProfile(vectorSearchHnswProfile, vectorSearchHnswConfig)
{
VectorizerName = vectorSearchVectorizer
}
},
Algorithms =
{
new HnswAlgorithmConfiguration(vectorSearchHnswConfig)
},
Vectorizers =
{
new AzureOpenAIVectorizer(vectorSearchVectorizer)
{
Parameters = new AzureOpenAIVectorizerParameters
{
ResourceUri = new Uri(openaiApiBase), // Azure Open AI endpoint
ApiKey = openaiApiKey, //Azure open AI Key
ModelName = deploymentName, // using text-embedding-3-large model for embedding
DeploymentName = deploymentName
}
}
},
},
Fields =
{
new SimpleField("id", SearchFieldDataType.String) { IsKey = true, IsFilterable = true, IsSortable = true, IsFacetable = true },
new SearchableField("title") { IsFilterable = true, IsSortable = true },
new SearchableField("content") { IsFilterable = true, IsSortable = true },
new SearchField("contentVector", SearchFieldDataType.Collection(SearchFieldDataType.Single))
{
IsSearchable = true,
VectorSearchDimensions = int.Parse(AzureOpenAIEmbeddingDimensions),
VectorSearchProfileName = vectorSearchHnswProfile
},
new SearchableField("category") { IsFilterable = true, IsSortable = true, IsFacetable = true }
}
};
Console.WriteLine(searchIndex.Name.ToString());
Console.WriteLine("Creating Index");
//await indexclient.CreateIndexAsync(searchIndex); //first tried with this, its not working
await indexclient.CreateOrUpdateIndexAsync(searchIndex);
Console.WriteLine($"Index created successfully {indexName}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Error creating index: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Error creating index: {ex.Message}");
}
}
The code is not even throwing any errors or exceptions. It's printing Console.WriteLine("Creating Index"); on console but when entering await indexclient.CreateOrUpdateIndexAsync(searchIndex); program is simply terminating. No exception is being thrown or printed on the console. Any support on this issue is very helpful.