A swarm was a gathering of animals (usually insects) in one location. They could occur for many reasons, such as for defense if they felt threatened. The term could also be applied to any gathering of starships, other artificial objects or an astronomical event similar to animal swarming.
In 2268, Nilz Baris described the twelve Klingons who came aboard Deep Space K-7 as a swarm, although Captain Kirk did not believe "that twelve Klingons constitutes a swarm". (TOS: "The Trouble with Tribbles"; DS9: "Trials and Tribble-ations")