The ability of the immune system to quickly and specifically recognize an antigen that the body has previously encountered and initiate a corresponding immune response.