[Python] Azure AI Search - Tag Scoring profile on azureopenai extra_body

Discussão em 'Python' iniciado por Stack, Março 15, 2025.

  1. Stack

    Stack Membro Participativo

    I created an index on Azure AI Search and connected it to Azure OpenAI using the extra_body. It works perfectly. However, I created a default scoring profile for my index, which boosts documents containing the string "zinc" in the VITAMINS field by a factor of 10.

    Since doing this, I can no longer run the query that worked previously without issues. Now, the query is asking for a scoringParameter, and when I attempt to pass it, I receive an error. Here is the code that works fine when I remove the scoring function.

    client.chat.completions.create(
    model=os.getenv('DEPLOYMENT'),
    messages=messages,
    temperature=0.5,
    extra_body={
    "data_sources": [{
    "type": "azure_search",
    "parameters": {
    "endpoint": os.getenv('ENDPOINT'),
    "index_name": os.getenv('INDEX'),
    "semantic_configuration": os.getenv('RANK'),
    "query_type": "hybrid",
    "in_scope": True,
    "role_information": None,
    "strictness": 1,
    "top_n_documents": 3,
    "authentication": {
    "type": "api_key",
    "key": os.getenv('KEY')
    },
    "embedding_dependency": {
    "type": "deployment_name",
    "deployment_name": os.getenv('ADA_VIT')
    }
    }
    }]
    }
    )


    However, if I activate the default scoring profile, I get the following error:

    An error occurred: Error code: 400 - {'error': 'message': 'An error occurred when calling Azure Cognitive Search: Azure Search Error: 400, message=\'Server responded with status 400. Error message: {"error":{"code":"MissingRequiredParameter","message":"Expected 1 parameter(s) but 0 were supplied.\\\\r\\\\nParameter name: scoringParameter","details":[{"code":"MissingScoringParameter","message":"Expected 1 parameter(s) but 0 were supplied."}]}}\', api-version=2024-03-01-preview\'\nCall to Azure Search instance failed.\nAPI Users: Please ensure you are using the right instance, index_name, and provide admin_key as the api_key.\n'}


    If I try to pass the scoringParameter anywhere in the extra_body, I receive this error:

    An error occurred: Error code: 400 - {'error': {'requestid': '', 'code': 400, 'message': 'Validation error at #/data_sources/0/azure_search/parameters/scoringParameter: Extra inputs are not permitted'}}


    This error is even more confusing. I’ve been looking through various resources, but none of them seem to provide a clear example of how to properly pass the scoring profile or scoring parameters in the extra_body.

    Here’s how I define my scoring profile using tags:

    scoring_profiles = [
    ScoringProfile(
    name="my-scoring-profile",
    functions=[
    TagScoringFunction(
    field_name="VITAMINS",
    boost=10.0,
    parameters=TagScoringParameters(
    tags_parameter="tags",
    ),
    )
    ]
    )
    ]


    How to pass the scoring parameters correctly in the extra_body on the client.chat.completions.create?

    PS: The only way I can get my code to work is if I delete the socirng profile or do not make it the socirng profile by default by I do want to use it.

    Continue reading...

Compartilhe esta Página