Vaccines contain strains of an attenuated Pathogen. This means there is a dead or inactive form of the virus you are protecting against in the vaccine. This could be a like DNA segments or some lipid membrane. This is then injected into the patient.The pathogen entering the blood stream triggers an initial adaptive immune response as recognised as a dangerous foreign molecule by its non-self antigens. The body in its response releases B lymphocytes which release antibodies. When the complimentary antibody is located and binds to the pathogen's antigens and there is cell proliferation. This causes more of these B cells (now B plasma cells) to be released to create the antibodies and kill the 'pathogen'. There are also B memory cells formed. These are dormant cells with the complimentary antibodies. They remain in the blood stream for many years and create the long term immunity the vaccines produce.If you ever then come across the pathogen again rather than feeling ill/potentially getting very sick, the B memory cells will recognise the antigens of the pathogen. They then bind and differentiate into the corresponding B plasma cell. So your body can release the corresponding antibodies faster and in larger volumes - so a more effective immune response.