Learning to Route: A Rule-Driven Agent Framework for Hybrid-Source Retrieval-Augmented Generation

Haoyue Bai, Haoyu Wang, Shengyu Chen, Zhengzhang Chen, Lu-An Tang, Wei Cheng, Haifeng Chen, Yanjie Fu · OpenReview

Abstract

Large Language Models (LLMs) have shown remarkable performance on general Question Answering (QA), yet they often struggle in domain-specific scenarios where accurate and up-to-date information is required. Retrieval-Augmented Generation (RAG) addresses this limitation by enriching LLMs with external knowledge, but existing systems primarily rely on unstructured documents, while largely overlooking relational databases, which provide precise, timely, and efficiently queryable factual information, serving as indispensable infrastructure in domains such as finance, healthcare, and scientific research. Motivated by this gap, we conduct a systematic analysis that reveals three central observations: (i) databases and documents offer complementary strengths across queries, (ii) naively combining both sources introduces noise and cost without consistent accuracy gains, and (iii) selecting the most suitable source for each query is crucial to balance effectiveness and efficiency. We further observe that query types show consistent regularities in their alignment with retrieval paths, suggesting that routing decisions can be effectively guided by systematic rules that capture these patterns. Building on these insights, we propose a rule-driven routing framework. A routing agent scores candidate augmentation paths based on explicit rules and selects the most suitable one; a rule-making expert agent refines the rules over time using QA feedback to maintain adaptability; and a path-level meta-cache reuses past routing decisions for semantically similar queries to reduce latency and cost. Experiments on three QA benchmarks demonstrate that our framework consistently outperforms static strategies and learned routing baselines, achieving higher accuracy while maintaining moderate computational cost.

Introduction

While Large Language Models (LLMs) are powerful, they struggle with domain-specific, up-to-date information. Retrieval-Augmented Generation (RAG) solves this by fetching external data, but most systems are "document-centric," relying on unstructured text like PDFs or Wiki pages. In industries like finance or healthcare, the most accurate data often lives in structured relational databases. This paper addresses the critical gap of integrating these structured sources effectively.

The Routing Challenge

A systematic analysis reveals that databases and documents possess complementary strengths. Databases excel at providing precise numerical facts, whereas documents are better suited for descriptive, open-ended queries. However, simply concatenating both sources—a strategy known as naive hybridization—often introduces noise that distracts the LLM, leading to lower accuracy and higher token costs.

Comparison of Database-Oriented and Document-Oriented queries

The challenge lies in intelligently routing queries to the most appropriate source. Existing "learned" routers are often black boxes that require massive labeled datasets and can be unpredictable in production. This framework proposes a more transparent, rule-based approach to navigate this complexity.

Methodology

The proposed framework is built on three pillars designed to maximize accuracy while minimizing latency and cost:

  • Rule-Driven Routing Agent: Instead of a black-box classifier, an LLM-based agent evaluates a query against a set of explicit, human-readable rules (e.g., "If the query asks for numbers, add +3 points to the Database path"). It selects the highest-scoring path: Database, Document, Hybrid, or Direct Answer.
  • Rule-Making Expert Agent: To avoid relying solely on static, hand-crafted rules, an "Expert Agent" works offline. It analyzes batches of past performance data (a "textual gradient") to refine, strengthen, or weaken rules, allowing the system to adapt to specific datasets without traditional retraining.
  • Path-Level Meta-Cache: Routing takes time and money. This component stores past routing decisions. When a new, semantically similar query arrives, the system reuses the previous routing decision based on embedding similarity, bypassing the routing agent entirely to save latency.

Experimental Results

The framework was evaluated on three diverse QA benchmarks: TATQA (financial reports), FinQA (numerical reasoning), and WikiQA (general knowledge). Across all backbones, including LLaMA-3, Qwen2.5, and GPT-4o, the framework demonstrated superior performance.

F1 Score distribution comparing the proposed framework against baselines

Key results include:

  • Superior Accuracy: On TATQA, the framework improved accuracy from 0.188 (best baseline) to 0.212 using LLaMA-3. On WikiQA with Qwen2.5, it achieved a new state-of-the-art accuracy of 0.302.
  • Efficiency Gains: The system maintained higher accuracy while using roughly 25-30% fewer tokens than the naive hybrid strategy by avoiding the retrieval of unnecessary context.
  • Noise Reduction: One of the most striking insights is that the Hybrid path (DB + Doc) is often less accurate than a single-source path. Irrelevant context from documents can "dilute" the precision of database facts; the routing agent successfully avoids this pitfall.

Conclusion

By treating natural language rules as optimization parameters, this framework provides a transparent and efficient solution for hybrid-source RAG. It bridges the gap between structured and unstructured data, ensuring LLMs can access the most relevant information with minimal overhead. Future work will explore extending this to multi-hop queries where an agent might need to route sequentially between different source types.

Summary updated

BibTeX
@misc{bai2025learning,
  author = {Haoyue Bai and Haoyu Wang and Shengyu Chen and Zhengzhang Chen and Lu-An Tang and Wei Cheng and Haifeng Chen and Yanjie Fu},
  title = {{Learning to Route: A Rule-Driven Agent Framework for Hybrid-Source Retrieval-Augmented Generation}},
  year = {2025},
  eprint = {2510.02388},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.02388},
}
Figure