Forum Discussion

Robert Ireland's avatar
Robert Ireland
Copper Contributor
Dec 22, 2023

Using Azure.AI.OpenAI v1.0.0 beta 12 and semantic + vector (hybrid) search

I have used the Azure Open AI Studio and Chat to import some files and create an index, embeddings, semantic search and configured cognitive search. Using the Azure OpenAI Studio I get the results that I'm expecting.

I have created a simple console application in VS Code using Azure.AI.OpenAI v1.0.0 beta 12. It's a very basic bit of code now that I'm just trying to get working.

 

 

using Azure.AI.OpenAI;
using Azure;
using System.Text.Json;

// Azure OpenAI setup
var apiBase = "https://[Azure OpenAI service name].openai.azure.com/"; // Add your endpoint here
var apiKey = "[Azure OpenAI API Key]";
// Azure Cognitive Search setup
var client = new OpenAIClient(new Uri(apiBase), new AzureKeyCredential(apiKey!));

// Initialize the AzureCognitiveSearchChatExtensionConfiguration
var search = new AzureCognitiveSearchChatExtensionConfiguration()
{
    SearchEndpoint = new Uri("https://[Cognitive Search Service Name].search.windows.net"),
    IndexName = "[The index created by Azure OpenAI Studio]",
    Key = "Search API Key",
    EmbeddingEndpoint = new Uri("https://[Azure OpenAI service name].openai.azure.com"),
    EmbeddingKey = "Azure OpenAI API Key",
    SemanticConfiguration = "default",
    QueryType = AzureCognitiveSearchQueryType.VectorSemanticHybrid,

};

// Set the FieldMappingOptions
search.FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions()
{
    UrlFieldName = "url",
    TitleFieldName = "title",
};

// Add ContentFieldNames
search.FieldMappingOptions.ContentFieldNames.Add("content");

var chatCompletionsOptions = new ChatCompletionsOptions()
{
    DeploymentName = "gpt35turbo",
    AzureExtensionsOptions = new AzureChatExtensionsOptions()
    {
        Extensions = { search }
    },
    Messages = {
                new ChatRequestUserMessage("Where can i store something")
    },
    Temperature = (float)0.1,
    MaxTokens = 800,
};

Response<ChatCompletions> response = await client.GetChatCompletionsAsync(chatCompletionsOptions);

var message = response.Value.Choices[0].Message;

 

When I run the code I get the following error

An error occurred when calling Azure Cognitive Search: Azure Search Error: 400, message='Invalid embedding endpoint https://[Azure OpenAI Service Name].openai.azure.com/: Server responded with status 404.

If I change the embedding URL to something like 

https://[Azure OpenAI service name].openai.azure.com/openai/deployments/gpt35turbo/extensions/chat/completions?api-version=2023-07-01-preview

Server responded with status 400. Error message: {\"error\":{\"code\":\"OperationNotSupported\", \"message\":\"The extensions chat completions operation must have at least one extension.\"}}', url=URL('https://[Azure OpenAI service name]/openai/deployments/gpt35turbo/extensions/chat/completions?api-version=2023-07-01-preview')\nCall to Azure Search instance failed.

 

Any pointers greatly appreciated. If it's the embedding endpoint I'm not sure where to get the correct version from in the Azure Portal.

 

Thanks

Rob Ireland

No RepliesBe the first to reply

Resources