Introduction
Over 80% of global data resides in unstructured formats like PDFs, Word documents, and reports. While Large Language Models (LLMs) have revolutionized text processing, querying these massive unstructured collections remains inefficient and expensive. Current solutions typically fall into two categories: feeding entire documents into LLMs (Vanilla LLMs) or using Retrieval-Augmented Generation (RAG). Vanilla LLMs are prohibitively costly and often hit context window limits, while RAG frequently fails on complex analytical queries because it lacks an understanding of a document's inherent semantic structure.
ZenDB addresses these challenges by exploiting the "templatized" nature of many professional documents—such as meeting agendas, scientific papers, and legal notices—to bridge the gap between unstructured text and structured SQL analytics.
Methodology: The Semantic Hierarchical Tree (SHT)
The core innovation of ZenDB is the Semantic Hierarchical Tree (SHT). Unlike traditional methods that treat a document as a flat string or a collection of independent chunks, ZenDB recognizes that documents are organized into nested hierarchies of headers and content.
SHT Construction and Template Leveraging
ZenDB uses visual cues such as font size, bolding, and alignment to cluster text. It then employs a minimal number of LLM calls to identify which clusters serve as logical headers. These headers are assembled into a tree reflecting the document's structure. To optimize performance, ZenDB creates "templates" for recurring document types, allowing it to process subsequent documents in a collection using fast, rule-based pattern matching rather than repeated LLM calls.
Query Execution
When a SQL query is issued, ZenDB's engine navigates the SHT using "summary sketches" at each node. This allows the system to prune irrelevant branches and only extract the specific text spans needed for the query. This "lazy population" strategy ensures that attributes are only extracted when requested, drastically reducing token consumption.
Evaluation and Results
ZenDB was evaluated across three diverse real-world datasets: Civic Agenda Reports from the City of Malibu, scientific publications on data management, and Department of Transportation "Notice of Violation" documents.
The results demonstrate that structural indexing allows ZenDB to significantly outperform both vanilla LLM and RAG-based approaches in both accuracy and cost-efficiency.
Key performance metrics include:
- Cost Savings: ZenDB achieved up to 30x cost savings compared to passing full documents to GPT-4.
- Accuracy Gains: In the Civic Agenda dataset, ZenDB improved precision by 28% and recall by 39% over vanilla LLM strategies. Compared to RAG baselines, precision improved by up to 61% and recall by 80%.
- Model Agnostic Efficiency: Using GPT-3.5-Turbo with ZenDB's structural indexing yielded high accuracy at 100x lower cost than GPT-4, proving that structural awareness is more critical than raw model size for document analytics.
Conclusion and Future Work
ZenDB demonstrates that visual formatting is a powerful proxy for semantic meaning. By prioritizing document structure over simple embedding similarity, ZenDB enables precise, SQL-powered analytics on unstructured data at a fraction of the current cost. Future work will focus on expanding the system's capabilities to handle cross-document joins and improving provenance tools to allow users to trace query results back to specific source text.
Summary updated