TL;DR
CoeusBI is an industrial-scale, LLM-powered interactive Business Intelligence (BI) system deployed at Baidu that automates natural language-to-SQL translation. By replacing manual semantic layers with an autonomous offline view generation agent and employing a deterministic, dialect-agnostic compiler, it overcomes production hurdles like complex JOIN operations, ultra-wide schemas, and multi-round dialogue hallucinations.
What Problem Does This Paper Address?
While large language models (LLMs) excel at translating natural language queries into SQL (NL2SQL), deploying them in real-world enterprise BI environments reveals a massive gap between academic benchmarks and production realities.
Typical enterprise BI pipelines face three severe challenges:
- Frequent and Complex JOINs: In production, the vast majority of queries (over 90%) require joining multiple base tables, which drastically degrades LLM generation accuracy.
- Ultra-Wide Schemas: Enterprise databases contain thousands of columns (e.g., averaging over 219 columns per view in some of Baidu's business lines). Standard prompt-based schema-linking methods quickly exhaust LLM token windows.
- Multi-Round Dialogue and Dialect Chaos: Users expect to ask follow-up questions iteratively. Managing this history while generating queries for diverse database dialects (e.g., ClickHouse, MySQL) incurs high computational costs and risks LLM "hallucinations" if the model synthesizes raw SQL directly.
Traditional commercial solutions bridge this gap using a manual semantic layer (configured via YAML or LookML), but this requires prohibitive human labor and fails to scale when schemas evolve. CoeusBI aims to fully automate this pipeline.
Methods
CoeusBI splits its architecture into two main environments: Offline Preparation and Online Query Processing.
1. Offline View Generation Agent
Instead of relying on humans to model data, an autonomous agent ingests raw database schemas, query logs, and documentation to automatically construct Relation-Aware Views. This agent pre-computes complex JOIN paths, effectively transforming difficult multi-table queries into simple, single-view queries before the user even asks a question.
2. Hierarchical Schema Linking
To handle ultra-wide schemas without blowing past token limits, CoeusBI uses a two-stage retrieval process:
- Stage 1 (Word2View): Formulates schema linking as a view routing problem. It uses vector databases across three mapping modes (Direct Column, Column Value, and Domain Knowledge) or a fine-tuned compact model (Ernie-Tiny v2) to pinpoint the single correct view ID.
- Stage 2 (View2Column): Prunes irrelevant columns within that specific view to isolate the top-K candidate columns.
3. Routing Agent & Deterministic SQL Compiler
When a query arrives, a Routing Agent determines if it is a new intent (Single-Round Dialogue) or a follow-up (Multi-Round Dialogue).
- For new queries, an LLM maps the natural language to a structured, dialect-agnostic Intermediate Representation (IR).
- For follow-ups, an IR Editor uses the LLM to generate a precise JSON Patch that modifies the previous query's IR, avoiding the need to re-send massive chat histories.
Crucially, the LLM never generates raw SQL. Instead, a deterministic compiler translates the abstract IR into perfectly predictable, dialect-specific SQL (e.g., ClickHouse or SQLite), eliminating hallucination risks entirely.
Datasets
The authors evaluated CoeusBI across both public benchmarks and massive, real-world production datasets:
- Public Datasets: WikiSQL, Spider, and BIRD (specifically the challenging BIRD-dev dataset for evaluating complex queries).
- Baidu Production Datasets: Real-world data from four major business lines (Video, Search, Advertising, and Finance), encompassing up to 2,281 tables and 65,000 columns, with views averaging up to 219 columns wide.
Key Insights and Ideas
- Demand-Driven vs. Structure-Driven Modeling: Instead of trying to map all structural table combinations (which causes a combinatorial explosion), the View Generation Agent focuses on empirical query patterns and business themes, keeping the number of generated views strictly bounded.
- Decoupling Comprehension from Compilation: Forcing the LLM to target a strictly bounded, abstract IR rather than raw SQL reduces the effective search space. It separates semantic understanding from database dialect syntax, allowing the system to support multiple SQL dialects natively without retraining the LLM.
- State-Saving via IR Edits: Treating multi-round conversations as localized JSON patches on a fixed-size IR state ensures constant token consumption and stable inference latency, even during extended exploratory sessions.
Key Results
- JOIN Elimination: The View Generation Agent successfully converted the majority of complex queries into single-view selections. On Baidu's production dataset, the proportion of queries requiring explicit JOIN clauses plummeted from 90.8% down to 25.72%.
- State-of-the-Art Accuracy: On the public BIRD-dev benchmark, CoeusBI achieved an Execution Accuracy (EX) of 71.4%, outperforming standard DIN-SQL (59.7%) and the industrial baseline SiriusBI (68.97%). On production datasets, it achieved up to 86.5% Useful Execution Accuracy (UEX).
- Massive Token Savings: Due to its hierarchical schema linking and localized IR editing, CoeusBI reduced prompt token overhead by 80% to 85% compared to traditional frameworks like MAC-SQL.
- Production Impact: Deployed live at Baidu, a three-week gray-release study involving 50 business analysts demonstrated a 55.7% reduction in average query completion time compared to legacy tools.
Limitations and Future Work
The primary limitation of CoeusBI stems from its deliberate design choice to bound the expressiveness of its Intermediate Representation (IR). Currently, the abstract IR cannot natively express highly specialized enterprise requirements, such as complex cross-view logic, advanced window functions (e.g., recursive ranking), or non-standard groupings.
While the system mitigates this by pushing these complexities down into "Virtual Columns" within the view layer, roughly 4.7% of production queries still fail to process autonomously and require expert fallback. Future work will focus on expanding the IR's semantics to natively encompass these advanced features without compromising the predictability of its deterministic compiler.
Summary updated