The results show that maternal immune activity during the critical period of sex-dependent brain development in pregnancy influences long-term memory structure and function in offspring during childhood and middle age, with different manifestations in males and females.