skip to Main Content

I’m trying to use semantic search enabled azure cognitive search in my flask app (in python virtual env).
When I do pip install azure.search.documents, 11.3.0 version gets installed
and I get following error:

TypeError: Session.request() got an unexpected keyword argument 'query_language'

same for query_speller, semantic_configuration_name etc.

here is the code I’m using:

results = list(
             self.search_client.search(search_text="xxx", 
                                            query_type ="semantic", 
                                            query_language  ="en-us",
                                            query_speller  ="lexicon", 
                                            semantic_configuration_name  ="xxx", 
                                            top=3, 
                                            captions= None)

below code works fine

results = list(self.search_client.search(search_text="xxx"))

2

Answers


  1. Semantic search is still in preview and only available in beta versions.

    Please try install latest beta version of azure-search-documents library.

    (I work in the SDK team in MS)

    Login or Signup to reply.
  2. I tried in my environment and got the below results:

    Initially, I got the same error that occurs when I try with azure-search-documents=11.3.0 package in my environment.

    TypeError: Session.request() got an unexpected keyword argument ‘query_language’

    enter image description here

    You can use the below code and package to get the semantic search enabled Azure cognitive search.

    Package:

    pip install azure-search-documents==11.4.0b3
    

    Code:

    
    from azure.core.credentials import AzureKeyCredential
    from azure.search.documents import SearchClient
    
      endpoint = "AZURE_SEARCH_SERVICE_ENDPOINT"
      index_name = "AZURE_SEARCH_INDEX_NAME"
      api_key = "AZURE_SEARCH_API_KEY"
    
    credential = AzureKeyCredential(api_key)
    client = SearchClient(endpoint=endpoint,
                              index_name=index_name,
                              credential=credential)
    results = list(client.search(search_text="Budget Room", 
                                                query_type ="semantic", 
                                                query_language  ="en-us",
                                                query_speller  ="lexicon", 
                                                semantic_configuration_name  ="semantic", 
                                                top=3))
    print(results)
    

    Output:

    The above code was executed and successfully get the required results.

    [{'LastRenovationDate': '2014-10-31T00:00:00Z', 'Category': 'Budget', 'Description': 'The Best Gaming Resort in the area.  With elegant rooms & suites, pool, cabanas, spa, brewery & world-class gaming.  This is the best place to play, stay & dine.', 'ParkingIncluded': False, 'Tags': ['continental breakfast', 'bar', 'pool'], 'Location': {'type': 'Point', 'coordinates': [-106.605949, 35.1087], 'crs': {'type': 'name', 'properties': {'name': 'EPSG:4326'}}}, 'Description_fr': "La meilleure station de jeux dans la région.
    

    enter image description here

    Also, make sure your Semantic search is enabled for your service.

    Reference:
    Azure.search.documents.SearchClient class | Microsoft Learn

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search