  Ultracold ground-state molecules can be formed from ultracold atoms via
photoassociation followed by a spontaneous emission process. Typically, the
molecular products are distributed over a range of final states. Here, we
propose to use an optical cavity with high cooperativity to selectively enhance
the population of a pre-determined final state by controlling the spontaneous
emission. During this process, a photon will be emitted into the cavity mode.
Detection of this photon heralds a single reaction. We discuss the efficiency
and the dynamics of cavity-assisted molecule formation in the frame of
realistic parameters that can be achieved in current ultracold-atom setups. In
particular, we consider the production of Rb$_2$ molecules in the $a^3\Sigma_u$
triplet ground state. Moreover, when working with more than two atoms in the
cavity, collective enhancement effects in chemistry should be observable.
