DocSage Beats GPT-4o RAG by 27 Points by Swapping Prose for SQL
DocSage builds query-specific relational tables from raw documents, then answers with SQL, beating GPT-4o with RAG by 27 percentage points on multi-entity QA.
ProTakeaways
- DocSage is an agentic framework that turns unstructured documents into query-specific relational tables answered via SQL.
- Beats GPT-4o + RAG by 27.2 points on MEBench and 27 points on Loong benchmarks.
- Three modules: ASK schema discovery, CLEAR logic-aware extraction, and schema-guided SQL reasoning.
- CLEAR uses LoRA-calibrated confidence plus cross-record constraints like functional dependencies and foreign keys.
- Robust to scale: only 4-point drop as entities grow past 100, versus 35-point RAG collapse.
- Code available at the anonymous repository; costly due to iterative agentic pipeline.
Answering questions that require piecing together facts about many entities scattered across many documents is where most retrieval systems quietly fall apart. Vector search grabs semantically similar chunks and misses the ones that actually contain the needed relationships, graph-based RAG bogs down as entity counts scale, and long-context LLMs suffer from attention diffusion, where the model loses track of specific facts in a sea of tokens. A new framework called DocSage attacks this problem by refusing to reason over prose at all. Instead, it dynamically builds a relational database on the fly, then answers the question with SQL.
The results are hard to ignore. On the MEBench and Loong benchmarks, DocSage outperforms GPT-4o with RAG by 27.2 and 27 percentage points respectively. More striking is how the gap widens as things get harder: on document sets with more than 100 entities, standard RAG collapses while DocSage barely flinches.
Why multi-document multi-entity QA breaks RAG
The task, abbreviated MDMEQA, shows up whenever answers depend on connecting entities across many sources. Think comparing corporate performance across dozens of SEC filings, synthesizing drug-disease relationships across trial reports, or cross-referencing clauses across contracts. The core requirement is not just locating relevant facts but establishing reliable cross-document entity alignments and constructing coherent evidence chains.
Existing tools each fail differently:
- Standard RAG retrieves by vector similarity, which prioritizes semantic overlap over entity relevance and drops critical facts.
- Graph-based RAG like GraphRAG models entities as triples, but graph construction becomes computationally prohibitive as document count grows.
- Long-context LLMs can ingest hundreds of pages but exhibit what the authors call contextual dilution, where key entities get lost due to attention saturation.
The unifying flaw is a lack of schema awareness. Without an explicit structured representation tailored to the query, none of these systems can systematically organize scattered entities into a coherent view.
Three agents, one relational table
DocSage is an end-to-end agentic pipeline built around a simple bet: if you can materialize the right relational schema for a given question, the rest is just database work. The system operates through three sequentially integrated modules: Interactive Schema Discovery, Logic-Aware Structured Extraction, and Schema-Guided Relational Reasoning.

The first module runs the ASK algorithm (Active Schema Discovery via Knowledge-seeking Queries). Rather than statically inferring a schema from a document sample, ASK treats schema discovery as an interactive dialogue with the corpus. After an initial pass, it looks for three types of uncertainty signals: entity alignment conflicts where the same entity has different attributes across documents, attribute value anomalies like an age of 180, and missing multi-hop relationships needed by the query. For each uncertainty, it generates a targeted natural language question, runs retrieval to answer it, and updates the schema. This continues until the schema stabilizes.
The second module is the CLEAR mechanism (Cross-record Logic Enforcement for Accuracy Reinforcement), which fills the schema with tuples extracted from documents. This is where most extract-then-reason pipelines silently accumulate errors. CLEAR operates at two levels:
- Single-point confidence calibration. A lightweight LoRA adapter is fine-tuned on the base extractor (Mistral-7B in the experiments) for each target schema, and confidence scores are calibrated using conformal prediction on a small labeled set.
- Cross-record logic checking. The system stages candidate tuples in a temporary database and validates them against schema-dependent constraints: functional dependencies (one Person_ID maps to one date of birth), temporal ordering (admission before discharge), numeric ranges, and foreign key referential integrity.
Low-confidence or constraint-violating tuples trigger a correction workflow. Simple errors get re-extracted by a stronger LLM committee. Complex logic conflicts go to a verification submodule that performs targeted backtracking retrieval to find decisive evidence in the source text.
The third module, Schema-Guided Relational Reasoning, is where the payoff arrives. The reasoning LLM compiles the natural language query into an optimized SQL query, executes it against the freshly built database, and traces each result row back to the originating document chunks for provenance. Multi-hop joins that would confuse an LLM in prose become deterministic database operations.
The numbers
DocSage was tested on two benchmarks: MEBench, a multi-entity QA benchmark with 4,780 questions across Comparison, Statistics, and Relationship types, and Loong, which stresses reasoning across increasing document lengths. Baselines included GPT-4o alone, GPT-4o with standard RAG, GraphRAG, and StructRAG.
On MEBench, DocSage hit 89.2% overall accuracy versus 62.0% for GPT-4o + RAG. The scaling behavior is the real story. While all methods degrade as entity count grows from Set1 (0-10 entities) to Set3 (over 100 entities), DocSage drops only from 91.8% to 87.9%, while GPT-4o + RAG collapses from 76.4% to 41.5%.
On Loong, DocSage's Perfect Rate, the fraction of fully correct answers, hit 0.53 overall versus 0.26 for GPT-4o. In the most challenging 200K-250K token setting, DocSage maintains an average score of 60.52 and a Perfect Rate of 0.47, while other models see their Perfect Rates drop to 0.10 or below.
What actually drives the win
The ablation study on MEBench pinpoints where the gains come from:
| Ablation | Overall accuracy | Drop |
|---|---|---|
| Full DocSage | 0.892 | - |
| w/o Structured Extraction | 0.691 | -20.1 |
| w/o Schema-Guided Reasoning | 0.773 | -11.9 |
| w/o Schema Discovery | 0.781 | -11.1 |
| w/o CLEAR logic checking | 0.849 | -4.3 |
| w/ Passive Schema Discovery | 0.863 | -2.9 |
Converting text into clean relational tuples is the single most important step. Offloading multi-hop reasoning to SQL is second. The interactive ASK component and CLEAR logic checks are smaller but consistent wins, and they matter more when documents are noisy or ambiguous.
Where this fits, and where it doesn't
DocSage looks strongest exactly where standard RAG stumbles: questions that require joining, aggregating, or comparing structured facts about many entities across many documents. Financial filings analysis, clinical trial synthesis, legal contract review, and any workflow where the answer really is a SQL query in disguise are natural fits.
The authors are candid about the downsides. The iterative multi-stage agentic process incurs non-trivial computational cost, and the current design assumes a degree of semantic coherence and factual consistency within the source documents, so performance may degrade with extremely noisy, contradictory, or domain-specialized texts. Every question effectively triggers schema discovery, extraction, and SQL compilation, which is heavier than a single retrieval call. It also inherits the capabilities and failure modes of the underlying LLMs used for schema derivation and extraction.
Source code and data are available at the anonymous repository linked in the paper. For teams currently patching a RAG stack with reranking and prompt tricks to handle multi-entity questions, the more interesting takeaway may be architectural: for a large class of enterprise QA problems, the right unit of representation is not a chunk or a triple but a table.