{"action":"created","issue":{"url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/44","repository_url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot","labels_url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/44/comments","events_url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/44/events","html_url":"https://github.com/aws-samples/aws-ai-qna-bot/issues/44","id":281148125,"node_id":"MDU6SXNzdWUyODExNDgxMjU=","number":44,"title":"Adding a new question to a QnA item can change response to an existing question","user":{"login":"rstrahan","id":10953374,"node_id":"MDQ6VXNlcjEwOTUzMzc0","avatar_url":"https://avatars0.githubusercontent.com/u/10953374?v=4","gravatar_id":"","url":"https://api.github.com/users/rstrahan","html_url":"https://github.com/rstrahan","followers_url":"https://api.github.com/users/rstrahan/followers","following_url":"https://api.github.com/users/rstrahan/following{/other_user}","gists_url":"https://api.github.com/users/rstrahan/gists{/gist_id}","starred_url":"https://api.github.com/users/rstrahan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rstrahan/subscriptions","organizations_url":"https://api.github.com/users/rstrahan/orgs","repos_url":"https://api.github.com/users/rstrahan/repos","events_url":"https://api.github.com/users/rstrahan/events{/privacy}","received_events_url":"https://api.github.com/users/rstrahan/received_events","type":"User","site_admin":false},"labels":[{"id":666249918,"node_id":"MDU6TGFiZWw2NjYyNDk5MTg=","url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":{"login":"JohnCalhoun","id":13800333,"node_id":"MDQ6VXNlcjEzODAwMzMz","avatar_url":"https://avatars1.githubusercontent.com/u/13800333?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnCalhoun","html_url":"https://github.com/JohnCalhoun","followers_url":"https://api.github.com/users/JohnCalhoun/followers","following_url":"https://api.github.com/users/JohnCalhoun/following{/other_user}","gists_url":"https://api.github.com/users/JohnCalhoun/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnCalhoun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnCalhoun/subscriptions","organizations_url":"https://api.github.com/users/JohnCalhoun/orgs","repos_url":"https://api.github.com/users/JohnCalhoun/repos","events_url":"https://api.github.com/users/JohnCalhoun/events{/privacy}","received_events_url":"https://api.github.com/users/JohnCalhoun/received_events","type":"User","site_admin":false},"assignees":[{"login":"JohnCalhoun","id":13800333,"node_id":"MDQ6VXNlcjEzODAwMzMz","avatar_url":"https://avatars1.githubusercontent.com/u/13800333?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnCalhoun","html_url":"https://github.com/JohnCalhoun","followers_url":"https://api.github.com/users/JohnCalhoun/followers","following_url":"https://api.github.com/users/JohnCalhoun/following{/other_user}","gists_url":"https://api.github.com/users/JohnCalhoun/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnCalhoun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnCalhoun/subscriptions","organizations_url":"https://api.github.com/users/JohnCalhoun/orgs","repos_url":"https://api.github.com/users/JohnCalhoun/repos","events_url":"https://api.github.com/users/JohnCalhoun/events{/privacy}","received_events_url":"https://api.github.com/users/JohnCalhoun/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2017-12-11T19:59:27Z","updated_at":"2018-06-12T20:54:54Z","closed_at":"2018-06-12T20:54:54Z","author_association":"NONE","body":"## Expected Behavior\r\n\r\nAdding new questions to an item should not adversely affect any answers that were previously correctly matched. \r\n  \r\n## Actual Behavior  \r\n  \r\nAdding a new question can actually weaken the score of an existing good match, sometimes causing another item to have a stronger score. See example below.   \r\n  \r\n## Steps to Reproduce the Problem\r\n  \r\nImport two items in attached file: \r\n[test.txt](https://github.com/awslabs/aws-ai-qna-bot/files/1549152/test.txt)  \r\n  \r\nSwitch to 'test' tab, and test question \"tell me about snorkeling\" - observe that the expected item is 'test.001' has the higher score (though by a slim margin)  \r\n  \r\n![image](https://user-images.githubusercontent.com/10953374/33850381-b4e20bc8-de81-11e7-8d8a-6929185c8d92.png)\r\n  \r\nNow edit 'test.001' and add a second question: \"what should I know about snorkeling\"  \r\nRerun the test with the same question.. Now the other answer has the higher score.   \r\n  \r\n![image](https://user-images.githubusercontent.com/10953374/33850471-01033bc6-de82-11e7-982d-58e382833f47.png)\r\n\r\nIt is counter intuitive, and undesirable, that adding the second question would change the answer.\r\n\r\n## Analysis\r\nThe QnABot uses elastic search ‘full text search’ capability to create ‘relevance scores’ for each QnA item. Relevance scores are computed by weighting a number of different factors in an effort to get the best match – see [What is relevance](https://www.elastic.co/guide/en/elasticsearch/guide/master/relevance-intro.html)  \r\n\r\nThere are three factors to the scoring a) term frequency, b) inverse document frequency, and 3) field length norm.. I believe it is this third factor that is biting us here.  \r\n\r\nThis is because the effect of adding the second question to the first item was to make the whole ‘question’ field longer, which reduced the relevance score of the match of item 1 (die to the ‘field length norm’ behavior aforementioned). The score was reduced to the point where it was slightly lower than the first item.\r\n\r\nNOTE: This situation really only arises when the question results in very similar scores on multiple items.. Ie when similarilties between the questions prevent a strong unique match.   \r\n  \r\n## Options\r\n\r\nA shortterm workaround can be to duplicate the question in order to increase the 'terms frequency' part of the scoring equation. ie adding a 3rd question to 'test.001' duplicating the initial question \"tell me about snorkelling\" once again results in this item having the highest score. Despite the fact that the 3rd question also lengthened the field further, the fact that it was a strong match to the question had the net effect of strengthening the overall score.\r\nHowever, while this technique might be useful for avoiding this specific problem, I do worry that it could introduce new problems by weakening the score of other question variants. Could become a game of 'whack-a-mole'!\r\n\r\nBetter if we can fix a fix in the code\r\n1) (preferred) find a way to construct the doctype mapping or the query to negate the problematic 'field length norm' factor when matching on the question lists. The total number of or length of the questions should ideally not affect the scoring of a match. See [disable field-length norm in mapping](https://www.elastic.co/guide/en/elasticsearch/guide/master/scoring-theory.html#field-norm)  \r\n  - UPDATE: disabling 'field-length norm' did resolve this issue but created a new issue.. namely with it disabled, the question \"tell me about snorkeling\" returned identical relevance scores for the two test items \"tell me about snorkeling' and 'tell me about snorkel prices' since after stemming (snorkeling=snorkel) the matches were identical. So back to the drawing board. Next up - see if mapping the question array as a [nested datatype](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html) will help.  \r\n2) alternatively, enhance the elastic search document structure to model each question independently, either by duplicating answers where there are multiple questions, or using a parent/child nested mapping to next questions as separate documents under the parent answer.  \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/comments/396730549","html_url":"https://github.com/aws-samples/aws-ai-qna-bot/issues/44#issuecomment-396730549","issue_url":"https://api.github.com/repos/aws-samples/aws-ai-qna-bot/issues/44","id":396730549,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NjczMDU0OQ==","user":{"login":"JohnCalhoun","id":13800333,"node_id":"MDQ6VXNlcjEzODAwMzMz","avatar_url":"https://avatars1.githubusercontent.com/u/13800333?v=4","gravatar_id":"","url":"https://api.github.com/users/JohnCalhoun","html_url":"https://github.com/JohnCalhoun","followers_url":"https://api.github.com/users/JohnCalhoun/followers","following_url":"https://api.github.com/users/JohnCalhoun/following{/other_user}","gists_url":"https://api.github.com/users/JohnCalhoun/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnCalhoun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnCalhoun/subscriptions","organizations_url":"https://api.github.com/users/JohnCalhoun/orgs","repos_url":"https://api.github.com/users/JohnCalhoun/repos","events_url":"https://api.github.com/users/JohnCalhoun/events{/privacy}","received_events_url":"https://api.github.com/users/JohnCalhoun/received_events","type":"User","site_admin":false},"created_at":"2018-06-12T20:54:54Z","updated_at":"2018-06-12T20:54:54Z","author_association":"MEMBER","body":"fixed in v2.0.0"}}
{"actor":{"display_login":"JohnCalhoun"}}