Unprotected sex with same person but still get weird symptoms..

So I’ve been having unprotected sex with my boyfriend for like 3 years now and every once in a while I begin to get heavy amounts of discharge that have a weird smell at times. When I go to the doctor to see whats wrong they would say I have bacterial vaginosis and once a yeast infection. Does anyone know why this is a recurring thing when I am having unprotected sex with the same person?