I have written below function which Assign Community Groups to user. Thanks to vicky sir to adding this into core code of uKnowva too.
You can use this function like this -
$groups_to_assign = array(7,8,9); //7,8,9 are group ids which needs to assign
$user = uKnowvaFactory::getUser(); // assigning to current user, you can pass id of any of the user