Yeah probably an oversimplification but it just creates different combinations and the ones that attach to the pathogen (and don't attach to non-pathogenic things in the body) are reproduced. But the immune system is wild I would say comes close to the neurological system from a how does this exist perspective.
https://en.wikipedia.org/wiki/Antibody#Immunoglobulin_divers...