Forum Discussion
QnA Maker API - How to programatically delete structured QnA files?
Hello all,
I am working on a programmatic solution to feed QnAs into QnA Maker. In order to do so, I use the API to provide structured data, as outlined here
The reason is, I cannot use files nor urls and thus leave these fields blank when submitting my data. The input I being used looks like
{"id":<Integer>,
"answer":"<Textual Content>",
"questions":["<Textual Content>"],
"metadata":[]}
As it turns out, I cannot provide any URLs, as the repositories are on premise and cannot be accessed by QnA Maker.
Now, my observation is that I cannot programatically delete my documents using the "id" which I provided in the initial submission. Actually, it appears that QnA Maker replaces my "id" by some internal counting which starts from 0 for fresh KBs. Thus, it turns out that I can delete my Q&As if I just guess these ids.
My questions therefore are:
- Is the above observation correct? A hint pointing at the documentation on how these ids which are needed for deleting would be helpful.
- If yes, are there any thoughts of extending the behavior toward a fallback approach, i.e., only if no "id" is given, this counting starting from 0 is used?
- In the meantime, is there a way to programtically retrieve this internal "id" from QnA Maker, ideally as part of the success response?
Thank you!
- dhinagajaCopper Contributor
Hi Christian,
As far as my understanding goes, you could use the any resource/URLs and the QnAMaker would extract and create KB.
Also, I just did a quick testing with your scenario and I am able to delete a particular document from the QnAMaker KB with the ID provided during the initial submission.
You can refer to Update Knowledge API : https://westus.dev.cognitive.microsoft.com/docs/services/5a93fcf85b4ccd136866eb37/operations/5ac266295b4ccd1554da7600/console
Firstly, I used the below body to create 2 documents in the KB.
{
"add": {
"qnaList": [
{
"id": 3001,
"answer": "You can change the default message if you use the QnAMakerDialog. See this for details: https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle",
"source": "Custom Editorial",
"questions": [
"How can I change the default message from QnA Maker?"
],
"metadata": []
},
{
"id": 3002,
"answer": "You can use our REST apis to manage your KB. See here for details: https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a073d9e041ad42d9baa",
"source": "Custom Editorial",
"questions": [
"How do I programmatically update my KB?"
]
}
]
}
}
I verified that it created using the "TEST" button in the QnAMaker website.
Next, I used the below body to delete just 1 document.
{
"delete": {
"ids": [
3001
],
"sources": [
"Custom Editorial"
]
}
}
I verified that it got deleted by using the "TEST" button again and the document is not found.
Hope it helps!
Dhina
- ChristianGrossCopper Contributor
Hi Dhina,
I tried to reproduce your suggestion. I submitted your JSON but the Ids got ignored again.
What I did is I used the patch snippet from
https://docs.microsoft.com/en-us/azure/cognitive-services/qnamaker/quickstarts/java#Update
to submit your JSON. If I download the knowledge base, I receive the following
{
"qnaDocuments": [
{ "id": 188, "answer": "You can change the default message if you use the QnAMakerDialog. See this for details: https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle",
"source": "Custom Editorial",
"questions": [ "How can I change the default message from QnA Maker?" ],
"metadata": [],
"alternateQuestionClusters": [],
"changeStatus": "Update",
"kbId": "..."
},
{
"id": 189,
"answer": "You can use our REST apis to manage your KB. See here for details: https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a0...",
"source": "Custom Editorial",
"questions": [ "How do I programmatically update my KB?" ],
"metadata": [],
"alternateQuestionClusters": [],
"changeStatus": "Update",
"kbId": "..." }
]
}
As you see, the ids 188 and 189 rather than 3001 and 3002.
Is there anything obvious what I can do wrong at client side to have the Ids not be used within the QnA Maker?
Best regards
Christian
- dhinagajaCopper Contributor
Interesting. But, after you had submitted the JSON with 3001 and 3002, did you try deleting by passing either 3001 or 3002 as parameters? I am asking because, in my case, when I used these ids in my delete payload, the article got deleted (which I confirmed using the TEST button). That indicates to me that the IDs are intact.