Yes, the gnats are probably coming from your soil, if they're fungus gnats.
They're quite common seen with inside grows and are a result of not letting the soil dry out enough between waterings. It seems I've always a few flitting about and they've never (in 30+ yrs) ruined a grow of mine.
If they thrive and get out of hand, they do burrow down and feed on roots, which can (I've read) destroy the plant(s).
I've never dealt with them myself. They just seem to come and go here, and it could be due to my lower grow temps in this old house. I've never seen a few turn into a bunch, but have read of a couple RIUppers who have.
If you feel the need to try and eradicate them, here's a fix to try. Stop watering.
Place raw potato slices on the soil surface and leave. After a while, lift the slice(s) and IF it's fungus gnats, the larva should be in the potato flesh. Discard and replace. (Flush the old down the turd-lette?)
When you don't find larva twice in a row (on fresh slices, after some hours) then the larva is gone and your outbreak squashed.
Be sure to allow the top few inches of your soil to dry out, as in this moist soil the gnats lay eggs.
I've also read that a layer of sand on top of the soil helps?