Filter Cognitive Search when using Azure OpenAI on your data

Samuel Mercier 20 Reputation points
2023-11-16T14:57:08.1133333+00:00

I'm using Azure OpenAI on your data. My OpenAI ressource is linked to a Cognitive Search index, which has a filterable field named "projectName".

My question is the following: Is there any way I can use this filter when using Azure OpenAI on your data?

To give you an illustration of my problem, if I query GPT model with a question such as "Can you list the technologies used during project ABC?", GPT might actually list me technologies which were used in projects others than ABC. My hypothesis is that the internal call to Cognitive Search returns documents related to project ABC, but also return documents related to other projects that contain, for instance, the word "technologies".

I believe that if I could specify Cognitive Search filters when calling Azure OpenAI (in this case projectName="ABC"), it would fix my issue.

Thanks for the support!

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,107 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
3,404 questions
{count} votes

Accepted answer
  1. SnehaAgrawal-MSFT 21,926 Reputation points
    2023-11-20T11:02:28.63+00:00

    @Samuel Mercier

    You can pass the filter expression as a parameter in the "parameters" object of the "AzureCognitiveSearch" data source in your OpenAI GPT API call. Specifically, you can add a "filter" parameter to the "parameters" object with the filter expression you want to use.

    Here's an example of how you can modify your API call to include the filter expression:

    {
        "messages": [
            {
                "role": "user",
                "content": "Can you list the technologies used during project ABC"
            }
        ],
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": "'$SearchEndpoint'",
                    "key": "'$SearchKey'",
                    "indexName": "'$SearchIndex'",
                    "filter": "projectName eq 'ABC'"
                }
            }
        ]
    }
    

    By adding the "filter" parameter with the expression "projectName eq 'ABC'", you are telling the Azure Cognitive Search data source to only return documents that have a "projectName" field equal to "ABC".

    You may refer to examples mentioned here- https://learn.microsoft.com/en-us/azure/search/search-query-odata-filter#examples

    I hope this helps!

    Let me know if you have any further questions.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.