Back in my Q clearance days in the 80’s it was done by the Office of Personnel Management. They would go around and talk to all of your friends, family, and neighbors.
The initial screening was done by contractors
Back in the 60s it was done by the FBI.