These systems are a form of hybrid gas/electric, and is similar to regenerative braking on EVs.
Modern hybrids/EVs use a planetary gearing scheme, where the gas motor is attached to one of the three transmission 'inputs,' the electric motor/generator to a second 'input' and the wheels to the third 'input.'
With planetary gears, you can stop any one of the three 'inputs' and the other two shafts are 'connected' to each other. Or, you can apply power to two of the three shafts, and route the sum of the two shafts to the third. Or the reverse.
So, for a KERS system, do the same thing. MG to one input of a planetary gear, gas motor to a second input, and sprocket on the third 'input' shaft.
When accelerating, assume that you're not adding electricity to the MG, and it's sitting still. Power goes out through the sprocket.
Then, you add battery current to the MG, and it starts spinning. Since it is spinning to support the engine, the two rotations are added, and the summed output goes out the sprocket.
Now, at speed, the you let off the gas. The bike starts slowing down, as the moving mass is spinning the generator, and the current gets pushed back into the battery.
There are losses. The planetary gearing is apx. 90% The MG/controller is 70-80% or so efficient at converting battery potential energy into mechanical energy. The MG/Charger/Battery is about 70% efficient at converting mechanical energy into chemical potential energy in the battery. So, for each charge/discharge cycle (Kinetic energy through gearbox through MG through Controller to Battery; Battery through Controller Through MG through Gearbox to Kinetic energy, you end up with about 50% of the kinetic energy you initially started with.