So I've been looking into the function of the immune system recently, and have been a bit confused with the process of developing new antibodies for foreign antigens. Based on what I've read and learnt so far, it seems that much of the process of generating antibodies is quite random, based on the recombination of D, V, and J segments in the heavy chain, and similar recombination in the gene segments of the light chain.
So then, when researchers are developing and injecting vaccines into our body, or our body encounters a new pathogen, does the body have a system to manually recognize a new antigen and create an antibody specific for that antigen, or does it instead depend on having a randomly-generated antibody that recognizes that antigen already, generating immunity that way. In other words, does the body produce antibodies based on the antigen it comes across, or does it hope to have a randomly generated antibody that binds to the new antigen?