Filter Cognitive Search when using Azure OpenAI on your data

Samuel Mercier 20 Reputation points

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 Cognitive Search
Azure Cognitive Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
497 questions
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
1,395 questions
{count} votes

Accepted answer
  1. SnehaAgrawal-MSFT 15,946 Reputation points Microsoft Employee

    @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-

    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