How Do White Blood Cells Learn? Or Do They?
So while some kind of a biological database might have been an evolutionary option, the way we evolved is different from this. Rather than 'planning' what diseases could be recognized in the environment and recording this, our bone marrow constantly pumps out naive B and T cells that have a randomized receptor on them. The effect of this is that every new B and T cell that your bone marrow makes will recognize a unique, random protein sequence, and you will have billions of these cells floating around in your blood circulation at any given time. These cells however will only float around in circulation for a short period of time before dying and being replaced by other cells with new random sequence receptors.

When you get a vaccination, you are injecting in specific protein sequences from a specific pathogen. As these injected protein sequences circulate through your blood they will eventually bump into a B or T cell that has a receptor that recognizes them. When this happens, the B or T cell will now start to divide and give rise to long lasting memory cells that express the exact same receptor and will therefore recognize the exact same protein sequence again in the future. These cells will float around in your blood for most of your life and make you 'immune' to the recognized pathogen. When you get reinfected with the same pathogen or the pathogen to which you were vaccinated these memory cells will rapidly divide upon recognition of the pathogen and give rise to a large number of effector cells that eliminate the pathogen before it can 'make you sick'.

What is really cool about this is that because each T or B cell carries on it a receptor that recognizes a random protein sequence, you currently have in you B and T cells that would recognize a protein that does not even exist on Earth, but might exist on Mars or somewhere else in the Universe. This makes our immune system quite valuable because any protein that nature creates for all of time anywhere in the universe will still be recognizable by our immune systems.