I am using QnA Maker v4.0 and I am trying to update my knowledge base programmatically using C# and following the documentation provided in:
I am able to add new questions and answers pairs to my knowledge base, but when I try to delete some of them, I am not able to do it. I get no message error, it's just that if I enter in QnAMaker portal, I can still see the question I am trying to delete is there.
I have tried to delete a complete source and that's working well so I am a bit lost on how can I delete just a given pair of questions and answer instead of the whole source.
What I have tried so far is following the documentation as follows:
Add new question an answer pair
string json = "{\"add\":{\"qnaList\":[{\"id\":123456789,\"answer\":\"fooanswer\",\"source\":\"Editorial\",\"questions\":[\"fooquestion\"],\"metadata\":null},{\"id\":987654321,\"answer\":\"fooanswer2\",\"source\":\"Editorial\",\"questions\":[\"fooquestion2\"],\"metadata\":null}],\"urls\":null,\"files\":null},\"delete\":null,\"update\":null}"
public async void UpdateKnowledgeBase(string json)
{
var knowledgebaseid = "<my kb id>";
var client = new HttpClient();
var querystring = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "QnA Subscription Key>");
var uri = "https://westus.api.cognitive.microsoft.com/qnamaker/v4.0/knowledgebases/"+ this.KnowledgeBaseId + "?" + querystring;
// Request body
byte[] byteData = Encoding.UTF8.GetBytes(json);
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var method = new HttpMethod("PATCH");
var request = new HttpRequestMessage(method, uri)
{
Content = content
};
HttpResponseMessage response;
response = await client.SendAsync(request);
}
}
This will create the question and answer pair in my knowledge base:
Deleting question and answer pair
However, if I try now to follow the documentation and delete the question and answer pair with id 123456789
, nothing will happen. To do so I am doing:
json = "{\"add\":null,\"delete\":{\"ids\":[123456789],\"sources\":null},\"update\":null}"
And, after calling the UpdateKnowledgeBase method with this json, I will get no error but my question and answer pair still appears in the QnA Maker portal. If I add the source, it will delete all the Editorial source. That's ok, but I also want to delete just one pair and not all of them. Is that possible?
Updating an existing question and answer pair
When updating an existing question and answer pair, I have the same problem, I am not getting any kind of mistake but I can't see the changes in the QnA Maker portal, what makes me think that no changes are being done.
My question therefore is, how can I do to update and/or delete questions and answer pairs without removing all the source?
Thank you in advance!