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.chatpletions.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.chatpletions.create
?
PS: The only way I can get my code to work is if I delete the scoring profile or do not make it the scoring profile by default by I do want to use it.
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.chatpletions.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.chatpletions.create
?
PS: The only way I can get my code to work is if I delete the scoring profile or do not make it the scoring profile by default by I do want to use it.
Share Improve this question edited Mar 16 at 8:08 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Mar 16 at 0:36 R_StudentR_Student 7691 gold badge9 silver badges22 bronze badges 1- but I do have to send that on the extra_body as I will be using the integration – R_Student Commented Mar 17 at 14:20
1 Answer
Reset to default 2Your problem made me research as well. And I just realized that there’s some discrepancy.
If you check out the Azure AI Search integration here, you’ll see that they don’t mention scoringProfiles
or scoring_parameters
.
It seems like Azure OpenAI’s implementation of Azure Search doesn’t expose scoringProfiles
or scoring_parameters
through extra_body.
But if you look at the Azure Cognitive Search API here, you’ll see that, you can list scoring profiles and parameters.
It looks like the official Azure OpenAI integration just doesn’t support them as valid fields.
Only workaround I can think of is to query Azure Search before sending the documents to Azure OpenAI.
Something like this:
import requests
import os
search_endpoint, search_index, api_key = ..
headers = {
"Content-Type": "application/json",
"api-key": api_key
}
query_body = {
"search": "your_query",
"queryType": "semantic",
"scoringProfile": "my-scoring-profile",
"scoringParameters": ["tags-zinc"],
"top": 3
}
response = requests.post(
f"{search_endpoint}/indexes/{search_index}/docs/search?api-version=2023-07-01-preview",
headers=headers,
json=query_body
)
search_results = response.json()["value"]
client.chatpletions.create(
model=os.getenv('DEPLOYMENT'),
messages=messages,
temperature=0.5,
extra_body={
"data_sources": [{
"type": "azure_search",
"parameters": {
"index_name": os.getenv('INDEX'),
# add here
"documents": search_results
}
}]
}
)