We examine the gas and stellar metallicities in a sample of HII galaxies from the Sloan Digital Sky Survey , which possibly contains the largest homogeneous sample of HII galaxy spectra to date . We eliminated all spectra with an insufficient signal-to-noise ratio , without strong emission lines , and without the [ OII ] \lambda 3727 Å line , which is necessary for the determination of the gas metallicity . This excludes galaxies with redshift \stackrel { { } _ { < } } { { } _ { \sim } } 0.033 . Our final sample contains \sim 700 spectra of HII galaxies . Through emission line strength calibrations and a detailed stellar population analysis employing evolutionary stellar synthesis methods , which we already used in previous works , we determined the metallicities of both the gas and the stellar content of these galaxies . We find that in HII galaxies up to stellar masses of 5 \cdot 10 ^ { 9 } ~ { } M _ { \odot } , enrichment mechanisms do not vary with galactic mass , being the same for low- and high-mass galaxies on average . They do seem to present a greater variety at the high-mass end , though , indicating a more complex assembly history for high-mass galaxies . In around 23 per cent of our HII galaxies we find a metallicity decrease over the last few Gyr . Our results favour galaxy evolution models featuring constantly infalling low-metallicity clouds that retain part of the galactic winds . Above 5 \cdot 10 ^ { 9 } ~ { } M _ { \odot } stellar mass , the retention of high metallicity gas by the galaxies ’ gravitational potential dominates .