How to set synonymMaps up on Azure Cognitive Service

George Lai 0 Reputation points
2023-10-03T14:25:31.8666667+00:00

Hi,

I want to set synonymMaps up on JSON,
I found the website, but I can not understand how to set it up
https://learn.microsoft.com/en-us/rest/api/searchservice/preview-api/create-or-update-index

I don't understand how to handle this line, can anyone give me guidance?

"synonymMaps": [ "name_of_synonym_map" ], (optional, only one synonym map per field is currently supported),

Thank you so much

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,354 questions
{count} votes

2 answers

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 22,706 Reputation points Moderator
    2023-10-04T13:29:42.6333333+00:00

    @George Lai Thanks for asking question,

    To set up synonymMaps on Azure Cognitive Service using JSON, you can use the REST API to create or update an index. The "synonymMaps" property is an optional field that allows you to specify the name of the synonym map that you want to use for a particular field.

    Here's an example of how you can set up a synonym map for a field called "description" in your index:

    {
        "name": "my_index",
        "fields": [
            {
                "name": "description",
                "type": "Edm.String",
                "synonymMaps": [ "my_synonyms" ]
            }
        ],
        "synonymMaps": [
            {
                "name": "my_synonyms",
                "format": "solr",
                "synonyms":"
                 USA, United States, United States of America\n
                 Washington, Wash., WA => WA\n"
            }
        ]
    }
    
    

    In this example, we're creating an index called "my_index" with a field called "description".

    We're also specifying a synonym map called "my_synonyms" that we want to use for the "description" field. The synonym map is defined in the "synonymMaps" property as a JSON object with a "name", "format", and "synonyms" property.

    The "format" property specifies the format of the synonym map, which in this case is "solr". The "synonyms" property contains the actual synonym mappings, which are defined using the Solr syntax.

    Note that- A synonym map consists of name, format, and rules that function as synonym map entries. The only format that is supported is solr, and the solr format determines rule construction.

    For more details see- https://learn.microsoft.com/en-us/azure/search/search-synonyms

    Hope this helps.

    let us know.

    0 comments No comments

  2. George Lai 0 Reputation points
    2023-10-04T16:17:40.5966667+00:00

    I figured out the problem, I can't create synonymMaps on the portal.

    When I use Python create synonymMaps, I have a problem :

    AttributeError: 'dict' object has no attribute '_to_generated'

    There is my code

    client = SearchIndexClient(service_name, AzureKeyCredential(admin_key))
    
    synonym_map = {
        "name": "m01",
        "format": "solr",
        "synonyms": "Purchase,sell,sold,purchased"
    }
    
    client.create_synonym_map(synonym_map)
    
    0 comments No comments

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.