On the HR side:
For large tech firms, record of your interview performance is held for 6 months, along with notes from hiring manager and HR. After 6 months, that information is removed.
There were rare instances where the hiring managers remembering specific candidates who were absolutely terrible in their interviews that they know them by name.
===
Hiring POV:
There's no guarantee that either company will provide return offers - it's a mix of hiring manager, economic circumstance, and your own personal performance. At this stage, maximizing your opportunities is worthwhile to see which internship will be the most fulfilling for you. So do the interview anyway. In addition, you should utilize any internship as an opportunity to network internally to create the circumstance that can increase your return back offer.
Do not tell Company B that you accepted an internship offer. They'll immediately reject you given internships have large queues of candidates if candidate #1 is unavailable. However, if you leave to Company B from Company A, it'll definitely burn bridges for Company A given they had to say sorry to many of the candidates they interviewed. Depending on the recruiter and hiring manager, this may stay in company record for a while.