Neuro-Symbolic Query Compiler

Yuyao Zhang, Zhicheng Dou, Xiaoxi Li, Jiajie Jin, Yongkang Wu, Zhonghua Li, Ye Qi, Ji-Rong Wen · DOI

Abstract

Retrieval-Augmented Generation (RAG) systems frequently struggle with complex, multi-hop queries that involve nested logic or implicit dependencies. This paper introduces QCompiler, a neuro-symbolic framework that addresses these challenges by "compiling" natural language queries into structured Abstract Syntax Trees (ASTs) based on a formal Backus-Naur Form (BNF) grammar. By decomposing messy questions into precise, atomic sub-queries, QCompiler enhances retrieval precision and logical consistency. Evaluated on four multi-hop reasoning benchmarks, QCompiler demonstrates superior accuracy and token efficiency compared to state-of-the-art iterative and agentic RAG methods.

Introduction: The Challenge of Complex RAG

Retrieval-Augmented Generation (RAG) has become the standard for grounding Large Language Models (LLMs) in external knowledge. However, traditional RAG systems often fail when faced with "complex queries"—questions requiring nested logic, multi-step dependencies, or implicit intents. For example, a query like "Who is the director of the movie where the lead actor was born in 1950?" often leads to imprecise retrieval because the system attempts to find documents for the entire sentence at once, missing the specific intermediate entities.

While iterative or "agentic" RAG methods attempt to solve this through multi-step reasoning, they are often computationally expensive, prone to "hallucinated" planning, and lack a formal structure to ensure logical decomposition. QCompiler addresses these issues by treating natural language as high-level code that can be compiled into a rigorous execution plan.

Comparison between traditional RAG and the QCompiler framework, highlighting how decomposition leads to precise retrieval.

The QCompiler Framework

QCompiler bridges the gap between neural computation (LLMs) and symbolic reasoning (formal grammars) through a four-stage process:

  1. Mathematical Formalization: Queries are categorized into four types: Atomic (indivisible), Dependent (sequential), List (parallel), and Complex (nested).
  2. BNF Grammar ($G[q]$): A minimal Backus-Naur Form grammar serves as the "instruction set" for query structure, constraining the LLM's reasoning into a mathematically sound framework.
  3. Query Expression Translator: A fine-tuned Llama-3.2-3B model translates natural language into grammar-based expressions, using operators like * for dependencies and + for parallel lists.
  4. Recursive Descent Processor: This component parses expressions into an Abstract Syntax Tree (AST) and executes it recursively. It resolves placeholders (e.g., {director1}) as it moves from leaf nodes to the root to synthesize the final answer.

By using a formal grammar, the system prevents the rambling or circular logic often observed in free-form chain-of-thought prompting.

Experimental Evaluation

The researchers evaluated QCompiler against several state-of-the-art baselines, including Naive RAG, Self-RAG, IR-CoT, and Iter-RetGen. Testing was conducted across four challenging multi-hop reasoning benchmarks:

  • 2WikiMultihopQA: Reasoning over multiple Wikipedia documents.
  • HotpotQA: Classic multi-hop question answering.
  • Musique: Deep reasoning chains (up to 4 hops).
  • Bamboogle: "Google-proof" questions designed to be difficult for standard search engines.

Key Results and Insights

QCompiler consistently outperformed all baselines across every benchmark. On the 2Wiki benchmark, it achieved an Exact Match (EM) score of 44.5, nearly doubling the performance of Naive RAG (28.2) and significantly exceeding the best iterative baseline, Iter-Retgen (29.8).

Performance comparison (ACC %) across four benchmarks (2WikiMultihopQA, HotpotQA, Musique, Bamboogle) showing QCompiler consistently outperforming baselines as TopK increases.

Key Insights:

  • Atomicity and Precision: The "leaf nodes" of the AST must be atomic. Forcing the system to retrieve information for the smallest possible indivisible question causes retrieval precision to skyrocket.
  • Grammar as a Constraint: Unlike agentic RAG where models decide their own next steps, QCompiler uses BNF grammar to restrict the search space, making decomposition reliable even for smaller 1B or 3B parameter models.
  • Efficiency: QCompiler used approximately 50% fewer tokens than iterative RAG methods. By "compiling" the plan upfront, it avoids redundant re-planning steps and allows for parallel execution of independent sub-queries.

Conclusion and Future Work

QCompiler demonstrates that complex reasoning does not always require massive 70B+ parameter models if the logical structure is provided via a neuro-symbolic interface. While the current system relies on supervised fine-tuning, future iterations could utilize Reinforcement Learning (RL) with step-level rewards to optimize query expressions further. Additionally, the authors aim to extend this framework to more ambiguous open-domain summarization tasks where the decomposition plan is less structured.

Summary updated

BibTeX
@inproceedings{zhang2025neuro,
  author = {Yuyao Zhang and Zhicheng Dou and Xiaoxi Li and Jiajie Jin and Yongkang Wu and Zhonghua Li and Ye Qi and Ji-Rong Wen},
  title = {{Neuro-Symbolic Query Compiler}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure