I am on a keto diet
I am familiar with that diet.  It is used primarily to treat children with epilepsy.  Did you have epilepsy as a child?
No I do not. But it was recommended by the doctor
It is a high fat, low carb diet.  the fat is broken down in the liver into Ketone, which replaces the glucose in the blood stream, improving brain function.
How does Ketone improve the brain function
Well, normally carbs are converted into sugar, which the brain uses.  But a low carb, high fat diet replaces the glucose with ketone, forcing the brain to use it instead.
When I take sugar my brain is happy. I think that is good
Yes, but ketone can replace glucose as an energy source.  As long as you are not at risk for clogged arteries, go for the high fat and ketone.