Update Custom Question Answering File of Knowledge Base via API

Nishanth Thekke Melepat 5 Reputation points
2024-03-02T14:19:55.7533333+00:00

Hi there,

I am using the Azure SDK for python to update the Custom Question Answering pair sources from an Azure Blob.

For Example: If the source is already existed in Language, I would paas the 'replace' operation so that it will not duplicate the question answer pair. If the source is new , I would paas the 'add' operation.

Unfortunately with the 'replace' operation, it does not refresh the source, even if have the parameter set as refresh:True. Due to this Question answer pair remains same in the Language studio. Replace operation is not really helping!

Looks like refresh boolean is only supported today with SourceKind "url". But I want to use File instead.

https://learn.microsoft.com/en-us/rest/api/cognitiveservices/questionanswering/question-answering-projects/update-sources?view=rest-cognitiveservices-questionanswering-2021-10-01&tabs=HTTP#updateqnasourcerecord

Is there a best way to update the question answerpair when the source is replaced with the same name? I know i can delete and recreate the source but this will loose all the metdata and additional custom questions that may have added outside of the source!


op = "replace" if blob.name in existing_source_names else "add"
update_sources_poller = client.begin_update_sources(
                    project_name=project_name,
                    sources=[
                        {
                            "op": op,
                            "value": {
                                "displayName":  blob.name,
                                "source": blob.name,
                                "sourceUri": source_uri,
                                "sourceKind": "file",
                                "refresh": True
                            }
                        }
                    ]
                )

Azure AI Language
Azure AI Language
An Azure service that provides natural language capabilities including sentiment analysis, entity extraction, and automated question answering.
355 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 13,160 Reputation points
    2024-03-02T14:50:37.59+00:00

    To update a Custom Question Answering source in Azure without duplicating, use 'replace' for existing sources and 'add' for new ones. However, 'replace' might not refresh file sources like it does for URLs. As a workaround, manually delete and re-add the file source, but back up any external metadata or custom questions first. Microsoft may enhance this feature, so consider providing feedback. For handling project updates, refer to Azure's documentation on managing question answering projects​

    https://learn.microsoft.com/en-us/python/api/overview/azure/ai-language-questionanswering-readme?view=azure-python

    https://learn.microsoft.com/en-us/azure/ai-services/language-service/question-answering/how-to/create-test-deploy