How to determine semantic search request limit/quota via an API call or using the azure-search-documents python SDK?

Das Gupta, Abhijeet 100 Reputation points
2024-06-26T14:40:00.4366667+00:00

The following document does not list any monitor usage APIs.

https://learn.microsoft.com/en-us/rest/api/searchservice/search-documents

Also, how to determine the api-version of my search resource? TIA

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.
821 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Grmacjon-MSFT 17,286 Reputation points
    2024-06-26T17:13:43.2133333+00:00

    Hello @Das Gupta, Abhijeet currently there isn't a way to determine the semantic search request limit/quota directly through an API call or the azure-search-documents Python SDK. The provided documentation (https://learn.microsoft.com/en-us/rest/api/searchservice/) is accurate in this regard.

    However, there are two ways to determine the API version of your Azure Cognitive Search resource:

    1. Azure Portal:

    • Access your search resource in the Azure portal.
    • Go to the "Overview" section.
    • The API version will be displayed under the resource details or properties.

    2. Azure CLI or PowerShell:

    • You can use Azure CLI or PowerShell commands to retrieve the API version of your search resource. For example, with Azure CLI :
        az search service show --resource-group <your-resource-group-name> --name <your-search-service-name> --query properties.apiVersion
        
      

    Hope that helps.

    -Grace


  2. Sina Salam 6,341 Reputation points
    2024-06-26T18:28:39.4466667+00:00

    Hello Das Gupta, Abhijeet,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    Problem

    I understand that you are having challenges on how to determine semantic search request limit/quota via an API call or using the azure-search-documents python SDK and also, how to determine the api-version of my search resource.

    Before answering your question:

    In support of the CLI command shared by @Grmacjon-MSFT this is the corrected version: az search service show --resource-group <your-resource-group-name> --name <your-search-service-name> --query properties.apiVersion

    Solution

    Let me say that it is correct that the provided documentation accurately outlines the service limits for Azure AI Search. However, there is a way to determine the semantic search request limit or quota directly through an API call or the Azure Search Python SDK.

    Kindly note that you typically do not have a specific API to directly query for current usage or limits. If you're using the semantic ranker feature in Azure AI Search, you can switch between the free plan and the standard plan, the free plan is capped at 1,000 queries per month and after the first 1,000 queries in the free plan, you'll receive an error message indicating that you've exhausted your quota the next time you issue a semantic query.

    Now, you can monitor your search service's usage and limits through Azure Monitor or Azure Portal metrics:

    By using Azure Portal Metrics.

    You will need to navigate to your Azure Cognitive Search resource in the Azure Portal.

    Go to Metrics and select the appropriate metrics like "Search Requests" or "Semantic Search Requests" under the Azure Cognitive Search category.

    Set the time range to see the usage and ensure it aligns with your expectations.

    By using REST API for Metrics.

    You can programmatically retrieve metrics using Azure Monitor Metrics REST API. Azure Monitor Metrics REST API documentation. You'll need to specify your resource ID, metric names (e.g., "SearchRequests", "SemanticSearchRequests"), and optionally filter by time ranges.

    By using Python SDK (azure-search-documents).

    The Python SDK for Azure Cognitive Search (azure-search-documents) does not have direct methods for fetching usage metrics. You would typically use the Azure Monitor API as mentioned above or azure-mgmt-resource SDK as described below:

    Regarding determining the API version of your search resource.

    I have corrected the Azure CLI code mentioned earlier by a colleague. However, not only to get the API version by making a request to the Azure Resource Manager (ARM) endpoint for your search service. You can use Python code by using the azure-mgmt-resource SDK to get the API version as I give an example below:

    from azure.identity import DefaultAzureCredential
    from azure.mgmt.resource import ResourceManagementClient
    # Replace with your subscription ID, resource group name, and search service name
    subscription_id = '<your-subscription-id>'
    resource_group_name = '<your-resource-group-name>'
    search_service_name = '<your-search-service-name>'
    credential = DefaultAzureCredential()
    resource_client = ResourceManagementClient(credential, subscription_id)
    resource = resource_client.resources.get(
        resource_group_name,
        'Microsoft.Search/searchServices',
        search_service_name
    )
    api_version = resource.properties['apiVersion']
    print(f"API Version of {search_service_name}: {api_version}")
    

    Replace the placeholders with your actual values and ensure you authenticate your Python code using the appropriate credentials and permission (such as a service principal or managed identity) before making the API call.

    References

    The below are the major source of the solution provided, kindly utilize them to read more and likewise, the additional resources by the right side of this page.

    Source: Azure AI Search client library for Python. Accessed, 6/26/2024.

    Source: azure-search-documents · PyPI. Accessed, 6/26/2024.

    Source: API versions of Search REST APIs - Azure AI Search. Accessed, 6/26/2024.

    Source: Understanding API Versioning: Best Practices and Strategies. Accessed, 6/26/2024.

    Source: Upgrade REST API versions. Accessed, 6/26/2024.

    Source: Azure AI Search client library for Python. Accessed, 6/26/2024.

    Source: Using the right api_version of the azure SDK . Accessed, 6/26/2024.

    Accept Answer

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    0 comments No comments