It is generally recommended to avoid sexual intercourse for about 24-48 hours after an HSG test to reduce the risk of infection and allow the body to recover.