They hang out with fish that look the same as those they grew up with.
eg: a baby neon tetra grows up with a bunch of other neon tetras. It thinks it is a neon tetra and will associate with them.
It does not think it's a guppy because it did not grow up with them.
It's the same right across the animal kingdom with baby animals, birds and fish associating with the species they grew up with. It's called imprinting and can happen when baby birds see their parents for the first time after they hatch from the egg. Swap the adult bird for a human, and the baby bird sees a human as its mother and will instinctively bond with and follow the human around.
It's also an instinct all animals have when they reach puberty (sexual maturity). They are naturally attracted to their own kind.