At a minimum, it's recommended that you vacuum your carpets at least twice a week (via Bob Vila), although if you don't use a room very often, you can get away from that recommendation — that is, if you have a seldom-used guest room, you can vacuum every two weeks or so.
The frequency should go up, though, depending on the above factors. For example, if you have indoor pets, you'll need to do it every day. Pets not only lose their hair on the regular, but also drop dander everywhere and bring in all sorts of yuck from the outdoors.
While carpets do a good job of keeping contaminants out of the air, that means it can make them harder to clean when you do vacuum. Basically, the dirt and dust winds up ground in and attached to the fibers, which is pretty gross when you think about it. Busting out the vacuum more frequently, then, means your carpets are easier to clean than if you didn't do it very often, because the dirt comes up easier when you do vacuum.
So yes, you need to vacuum fairly frequently — possibly as frequently as once a day — but keep in mind that means your home will be cleaner, easier to clean, and overall a better environment.