Bti is another option. You can use it pre-emptively, too.
gnat larva often come in the medium. At some point it is stored or transported while exposed to the outdoors. Using bti from the start will avoid that possibility. if you dont see any gnats a month down the line, probably fine to stop.
larva is what damages your plants. the adults are annoying and embarassing, but the larva is element to worry about most. Bti is a bacteria that kills the larva one way or another - details really don't matter, eh? LOL. nematodes eat the larva and also a good option.
mid-problem, might takes 2 weeks to clear up with bti.. use both.. bti and nematodes... stick traps for adults.
in north armerica, at least, the brand and product name is summit mosquito bits or dunks. YMMV elsewhere in the world, but a product probably exists with .. and i will spell this wrong but it'll still work in a google search -- Bacillus thurgenesis (israelis) ... a different subspecies has been used on food crops for maybe a century so it's safe.
better to avoid this problem pre-emptively. By the time you notice you have them, the roots are already under attack and damaged needlessly. I top dress a few 'bits' for first irriation of seedling pots. Then, use for at least 3 weeks beyond last transplant. I occasionally do see a single gnat, but it never escalates. It's also effective against other larva in soil, too. not all, of course.