ScaleDoc: Scaling LLM-based Predicates over Large Document Collections

Hengrui Zhang, Yulong Hui, Yihao Liu, Huanchen Zhang

TL;DR

ScaleDoc is a new system designed to run complex semantic queries (e.g., "Find medical papers about new drug discoveries") over millions of documents without breaking the bank. By decoupling expensive LLM processing into a one-time offline embedding phase and a query-specific online "proxy" phase, it reduces expensive LLM calls by up to 85% and achieves a 2× end-to-end speedup while strictly maintaining user-defined accuracy targets.

What Problem Does This Paper Address?

Traditional databases are great at "value-based" filtering—think WHERE price > 100. However, modern data analysis often requires "semantic" filtering, such as identifying reports where customers express "dissatisfaction with service quality."

While Large Language Models (LLMs) like GPT-4o are incredibly good at these "zero-shot" semantic judgments, they are far too slow and expensive to run on millions of documents for every new query. Existing solutions often try to "cascade" queries, using a smaller LLM (like Llama-3B) to filter easy cases before sending hard ones to a big LLM. But even these smaller LLMs are computationally heavy when scaled to massive document collections. The core challenge is the capacity mismatch: how do we get the semantic "intelligence" of an LLM at the speed and cost of a simple database filter?

Methods

ScaleDoc introduces a two-phase architecture:

  1. Offline Representation Phase: Every document in the collection is processed once using a mid-sized LLM (e.g., a 7B parameter model) to generate a high-dimensional semantic embedding. These embeddings are stored and reused for all future queries.
  2. Online Processing Phase: When a user submits a new query, ScaleDoc:
  3. Samples and Labels: It takes a small sample (e.g., 5-10%) of documents and asks a powerful "Oracle" LLM (like GPT-4o) to label them.
  4. Trains a Proxy: It trains a "tiny" proxy model (a 3-layer MLP) on the fly. This proxy learns to map the pre-computed document embeddings to the Oracle's labels.
  5. Contrastive Learning: To ensure the proxy is reliable, the authors use a two-phase training strategy. Phase 1 ensures Semantic Monotonicity (relevant docs get higher scores). Phase 2 enforces Bipolarity, using "bellwether" samples to push positive and negative scores to opposite ends of the spectrum, creating a clear "gap" for easier filtering.
  6. Adaptive Cascade: Using a novel calibration workflow (stratified sampling + jittering + density estimation), the system determines the optimal thresholds to filter out "definitely yes" and "definitely no" documents, forwarding only the "ambiguous" cases to the expensive Oracle.

Datasets

The researchers evaluated ScaleDoc using three diverse real-world document collections:

  • PubMed: 10,000 medical abstracts.
  • BigPatent: 10,000 US patent summaries.
  • GovReport: 10,000 government reports. They manually crafted 20 distinct natural language queries for each collection, ranging from simple topic classification to complex reasoning.

Key Insights and Ideas

  • Embeddings as "Compressed Intelligence": Instead of re-reading the full text for every query, ScaleDoc treats the offline embeddings as a rich, compressed semantic summary that the tiny proxy model can digest instantly.
  • Distribution Shaping: Most proxy models produce "mushy" probability scores where positives and negatives overlap in the middle. ScaleDoc’s use of Contrastive Bipolarity is an "aha moment"—it explicitly trains the model to create a "no-man's land" in the score distribution, which makes threshold selection much more robust.
  • Calibration over Counting: On small samples (5%), simple counting is noisy. ScaleDoc reconstructs continuous probability density functions (PDFs) using linear interpolation and moving averages. This allows the system to find the "Pareto-frontier" of thresholds—the exact point where cost is minimized without violating the user's accuracy requirement.

Key Results

  • Efficiency: ScaleDoc achieved over a 2× end-to-end speedup compared to state-of-the-art baselines like LOTUS and BARGAIN.
  • Cost Savings: It reduced expensive Oracle LLM invocations by up to 85%.
  • Computational Footprint: In terms of total FLOPs (Floating Point Operations), ScaleDoc required only 140P compared to 500P for an Oracle-only approach.
  • Accuracy: The system successfully met user-specified accuracy targets (e.g., 90% F1-score) across varying levels of data "selectivity" (i.e., whether 1% or 50% of the documents were relevant).

Limitations and Future Work

  • Symbolic Reasoning: The authors note that while ScaleDoc excels at semantic meaning, it struggles with Quantitative Analysis (e.g., "Find papers where p-value < 0.05") and Composite Predicates (complex logical AND/OR conditions). This is because current embedding models are better at "vibe-checking" than precise symbolic logic.
  • Offline Cold Start: The system requires an initial offline pass to generate embeddings. While this is a one-time cost, it remains a hurdle for extremely dynamic or frequently changing document sets.
  • Future Directions: The authors suggest exploring more advanced embedding models or hybrid approaches that combine semantic embeddings with traditional structured metadata to handle the "symbolic" gap.

Summary updated

BibTeX
@article{zhang2026scaledoc,
  author = {Hengrui Zhang and Yulong Hui and Yihao Liu and Huanchen Zhang},
  title = {{ScaleDoc: Scaling LLM-based Predicates over Large Document Collections}},
  journal = {Proc. ACM Manag. Data},
  year = {2026},
  doi = {10.1145/3802106},
}
Figure