The method of small-angle neutron scattering has been used for the investigation of hydrogels synthesized on the basis of a cross-linked copolymer of 2-hydroxyethyl methacrylate and functional monomers (acrylic acid or dimethylaminoethyl methacrylate) which possess the memory effect with respect to the target pharmaceutical substance — cefazolin. The difference in the structure of anionic, cationic and amphiphilic hydrogels has been shown as well as the relation between the structure and the ability of a hydrogel for water sorption in the presence and in the absence of cefazolin. Certain structural features of the hydrogels confirmed the conditions for the appearance of the memory effect for the sorption and liberation of cefazolin.