I made a separate post since this one wasn't getting anywhere, and was eventually able to figure out the issue myself. For whatever reason the fieldsMapping property was required for my requests to the API. I imagine this might have something to do with the fact that I have more than one vector field, or maybe because my vector fields aren't named "vector"? Not sure exactly, honestly, and Microsoft's documentation is no help on explaining why this might be the case, but I would give it a try considering how similar this post is to my own. You can view my original post below
AzureCognitiveSearchChatExtensionConfiguration help
Hi guys
I'm trying to setup AzureCognitiveSearchChatExtensionConfiguration for hybrid search (vector + semantic) but I can't make it work
Here is my code
var search=new AzureCognitiveSearchChatExtensionConfiguration()
{
SearchEndpoint = new Uri(_configuration.GetSection("AppSettings")["SearchEndPoint"]),
IndexName = "ai"
};
search.SetSearchKey(_configuration.GetSection("AppSettings")["SearchKey"]);
search.SemanticConfiguration="ai-semantic-config";
search.QueryType= AzureCognitiveSearchQueryType.VectorSemanticHybrid;
search.EmbeddingEndpoint =new Uri(_configuration.GetSection("AppSettings")["AiEndPoint"]);///openai/deployments/{deployment-id}/embeddings?api-version={api-version}
search.SetEmbeddingKey(_configuration.GetSection("AppSettings")["AiKey"]);
search.FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions()
{
UrlFieldName="Url",
TitleFieldName="Title",
}
;
search.FieldMappingOptions.ContentFieldNames.Add("Content");
search.FieldMappingOptions.ContentFieldNames.Add("Subtitle");
search.FieldMappingOptions.ContentFieldNames.Add("Authors");
//search.FieldMappingOptions.VectorFieldNames.Add("TitleVector");
search.FieldMappingOptions.VectorFieldNames.Add("ContentVector");
ChatCompletionsOptions chatCompletionsOptions = new()
{
DeploymentName = modelName,
Messages =
{
new ChatMessage(
ChatRole.System,
"You are a helpful assistant "),
new ChatMessage(ChatRole.User, question)
},
AzureExtensionsOptions = new AzureChatExtensionsOptions()
{
Extensions =
{
search
}
}
};
try
{
Response<ChatCompletions> response = await _client.GetChatCompletionsAsync(chatCompletionsOptions);
ChatMessage message = response.Value.Choices[0].Message;
return message.Content;
}
The message I'm getting is
Service request failed. Status: 400 (Bad Request) Content: {"error": {"requestid": "90ef3895-27ce-458f-a6d2-ba0fe165345f", "code": 400, "message": "An error occurred when calling Azure Cognitive Search: Azure Search: Please assign a proper column/field for vector search. It should be of type Collection(Edm.Single)"}} Headers: x-envoy-upstream-service-time: REDACTED apim-request-id: REDACTED x-ms-client-request-id: e87d8134-efc6-4e6f-8195-dc51be1a712f Strict-Transport-Security: REDACTED X-Content-Type-Options: REDACTED x-ms-region: REDACTED Date: Thu, 16 Nov 2023 15:15:24 GMT Content-Length: 259 Content-Type: application/json; charset=UTF-8 ss
Although I have passed the correct vector filed
Thanks
2 answers
Sort by: Most helpful
-
-
Saurabh Sharma 23,821 Reputation points Microsoft Employee
2023-12-12T17:48:02.4233333+00:00 Good to hear that you have successfully resolved your issue and shared your solution.
Thank you for your contribution! This will help others who face the same problem find the answer quickly.
Please note that the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others (Opens in new window or tab)", I'll repost your solution in case you'd like to "Accept (Opens in new window or tab)" the answer.
Solution: "I just figured it out. It seems that the "fieldMapping" property is required for vector embeddings, at least with how my vectors are configured. If I had to guess it might have to do with the fact that I'm using two vector fields, but the property is supposed to only be required for the Azure Cosmos DB/MongoDB... at least according to the documentation. Below is the property format I used to get the request working."
"fieldsMapping": { "vectorFields": [ "titleVector", "contentVector" ] },
Please 'Accept as answer' and Upvote if it helped so that it can help others in the community looking for help on similar topics.