Unveil the Duality of Retrieval-Augmented Generation: Theoretical Analysis and Practical Solution