RQ-RAG: Learning to Refine Queries for Retrieval Augmented Generation