A dual-frequency laser interferometer is an important instrument that can provide a meter-level measurement range with nanometer-level measurement accuracy at several meters per second measurement speed. The measurement accuracy of the dual-frequency laser interferometer plays a vital role based on laser wavelength, which is easily affected by environmental factors, so the air refractive index needs to be corrected. In this paper, an improved Edlen empirical formula air refractive index compensation method is introduced, in which a particle swarm optimization algorithm is used to optimize the Edlen formula by adjusting the compensation model online according to the compensation effect to adapt to different environmental conditions. The experimental results show that the root mean square error of the interferometer compensated for by the unoptimized Edlen formula can be reduced by 79.3% and 72.1% under different optical path lengths, and by 90.7% and 91.9% after compensation by the optimized Edlen formula, which means that the average compensation effect is improved by about 20%.