Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.16k stars 4.53k forks source link

Azure Search: No content fields found. Please confirm if you have String fields which are searchable! #41538

Open MikeAlhayek opened 5 months ago

MikeAlhayek commented 5 months ago

Library name and version

Azure.AI.OpenAI 1.0.0-beta.12

Describe the bug

When trying to search an index that only has searchable field of type StringCollection I get a bad request response. as you can see here image

Expected behavior

In Azure AI Search, both field types String and StringCollection are searchable. So I should be able to search the index using any searchable field regardless of it's type.

Actual behavior

When running the code I get HTTP code 400 response from the API.

{"error": {"requestid": "6003d42d-13b4-454f-90d9-287b3af6213b", "code": 400, "message": "Invalid AzureCognitiveSearch configuration detected: Call to get ACS index failed. Check you are using correct index, instance and api_key.\nAzure Search: No content fields found. Please confirm if you have String fields which are searchable!"}}

Reproduction Steps

Create an Azure Search AI index with no String fields. Add at least one StringCollection field.

Then try to use Azure.AI.OpenAI model to search that index. This throw the exception listed above

Here is the code I use to search my Azure Search AI index

try
{
    var completion = await _openAIClient.GetChatCompletionsAsync(new ChatCompletionsOptions("my-chat-deployment-name", [new ChatRequestUserMessage("Something to search for")])
    {
        AzureExtensionsOptions = new AzureChatExtensionsOptions()
        {
            Extensions =
            {
                new AzureCognitiveSearchChatExtensionConfiguration()
                {
                    SearchEndpoint = new Uri("https://my-endpoint"),
                    Key = "My key",
                    IndexName = "the-azure-search-ai-index-name",
                },
            }
        }
    });

    // ...
}
catch (Exception ex)
{
    _logger.LogError(ex, "Unable to complete chat using Azure AI Completion model.");
}

The above code works when searching an index that has String field.

Environment

No response

MikeAlhayek commented 5 months ago

@bleroy can you please confirm that StringCollection should be searchable just like String type would in Azure Search AI? I am just trying to determine if this is a limitation in the Azure Search AI or an issue or limitation in chat completion on your own data?

When I search for a string using "Search explorer" UI on Azure, I am able to see results. So I am guessing this isn't a limitation on Azure Search AI.

image

bleroy commented 5 months ago

@MikeAlhayek not sure why you're tagging me. I think so, but that's not my area of expertise.

MikeAlhayek commented 5 months ago

Sorry! I thought you had an answer to the Azure Search AI portion.

bleroy commented 5 months ago

I work on the indexer. You'll want to ask someone on the search engine side of the team. As far as I can tell from the documentation, collections of strings are supported: https://learn.microsoft.com/en-us/rest/api/searchservice/supported-data-types

jsquire commented 5 months ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

ShivangiReja commented 5 months ago

@MikeAlhayek - Azure AI Search supports both string and collection of strings, both of which are searchable. Check out an example here, where HotelName is a string field and Tags is a collection of strings, both marked as searchable.

Refer to the docs here for more details:

"searchable": true (default where applicable) | false (only Edm.String and Collection(Edm.String) fields can be searchable).

Are you possibly missing FieldMappingOptions in the provided code snippet? Consider the following:

AzureExtensionsOptions = new AzureChatExtensionsOptions()
{
    Extensions =
    {
        new AzureCognitiveSearchChatExtensionConfiguration()
        {
            SearchEndpoint = new Uri("https://my-endpoint"),
            Key = "My key",
            IndexName = "the-azure-search-ai-index-name",
            FieldMappingOptions = new AzureCognitiveSearchIndexFieldMappingOptions()
            {
                ContentFieldNames = { "MyContentField" }
            }
        },
    }
}

For more details on using extensions in OpenAI, @trrwilson or @joseharriaga can provide additional assistance.

MikeAlhayek commented 5 months ago

@ShivangiReja FieldMappingOptions is optional and not required. I am not sure if providing them will enhance the result. Any how, I tried adding them and ended up with the same result.

Please note that my code works on a different index. For example, if you look at this other index, searching works as expected. The key difference between the two indexes is that this one has at least one searchable String type field whereas the other one has searchable SearchCollection fields.

image

ShivangiReja commented 5 months ago

@MikeAlhayek Even if you have no searchable string field and only have searchable SearchCollection fields, it should still be a valid index, and the functionality should work as intended. I've added a sample based on your scenario using the search library. You can review the example here, showcasing only a searchable SearchCollection field and no searchable string field (lines 74-75). The sample works correctly and returns the expected results.

Could you please try utilizing only the search library to determine if it provides the expected response? If an error persists, it might be related to the Azure AI Search. If there's no issue, then it could indicate a problem with Azure Open AI.

MikeAlhayek commented 5 months ago

@ShivangiReja your code does not use the Chat Completion code. It utilizes the Search AI index by creating an index, pushing content and then performing a search. This all works for me as expected as well. This is all working as part of OrchardCore CMS

The part that isn't working as expected in the GetChatCompletionsAsync using AzureCognitiveSearchChatExtensionConfiguration. Again the same code work fine when my index contains searchable String field. But it does not seems to search when there are no searchable String field.

ShivangiReja commented 5 months ago

@joseharriaga could you please help @MikeAlhayek with utilizing the extensions in OpenAI?

github-actions[bot] commented 4 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @arv100kri @bleroy @jpalvarezl @tjacobhi @trrwilson.

MikeAlhayek commented 1 month ago

@ShivangiReja @joseharriaga There has been no activity on this issue. I am wondering if there is a plan to fix this issue soon? In a short summary, it appears that the Azure OpenAI (C# SDK) on your own data does not search within a string-collection field types. I can't imagine this being a limitation, so I am assuming it is a bug in the SDK.