If they are free swimming (then they are not flatworm)...sooo they are probably a roundworm or larvae of some sort
I have four theories on what your worms may actually be:
Do you know what the general length of the worms are? (can help rule out some of the theories)
Hrm this may be a strange question but is it warm enough/ mosquito season where you live? Mosquito larvae are little red worms and I've red of incidences where people have found these larvae in their tanks. But I think this one is probably not as likely as midge larvae...
Midge larvae could be a another possibility, and another one I've read to be commonly found in aquariums. Kinda shorter stumpier "worms" lol
I also think there is a type of roundworm parasite that can inflict fish, but I think they wold be seen in the feces and coming from the anus...if I am correct. I am not sure what they are called. (this one is the least likely unless these worms are seen coming from your fish's bum
Lastly, could be tubifex worms, sometimes unhatched cysts can be found in the food bettas eat, this could potentially allow for hatching in the tank. These are commonly found forming large balls when their population gets established and are very thin. They swim very oddly contorting their bodies. I think they like to hang out in gravel and sand too? (but not sure about that one)
here are some wild ones
here are some cultured ones
Worms are usually common when in a tank where there is excess organic build up, so you may actually find more in the filter.
I hope this helps you figure out what could be the worms. In any case I would remove them, I would clean the tank and gravel thoroughly with hot hot water. You could add some salt in the cleaning process as a further precaution. But rinse all the salt from the tank and gravel with hot water again before refilling your tank with freshwater again.
If after you clean the tank and you notice worms clinging on your fish, in the gills or protruding from the anus you should seek treatment ASAP