Filtering unstructured data with Large Language Models (LLMs) is powerful but notoriously expensive. If you have a million documents and want to find those "about baseball," a naive system makes a million LLM calls. SemReuse introduces a way to slash these costs by reusing results from previous, related queries—without sacrificing the accuracy of your results.
TL;DR
SemReuse is a framework for "certified reuse" of cached LLM filter results. By using a two-tier reasoner to infer logical relationships between natural-language queries and a rigorous statistical audit to verify those inferences, it reduces LLM calls by up to 15.4× while providing formal guarantees on recall and precision.
What Problem Does This Paper Address?
Semantic operators allow users to query unstructured data (like text) using natural language filters (e.g., sem_filter("is this a positive review?")). While powerful, these operators are "tuple-at-a-time," meaning every single row in a database triggers a costly LLM call.
Existing optimizations often focus on a single query in isolation. However, analytical workloads are rarely isolated. An analyst might first filter for "sports" and later narrow it down to "baseball." Standard semantic caches are "all-or-nothing"—they might reuse a result if the prompt is nearly identical, but they can't handle logical implications (like "baseball" implying "sports") or provide any guarantee that the reused results are actually correct.
The core challenge is that natural language doesn't have an exact algebra. If an LLM incorrectly judges that two conditions are equivalent, you might end up with a result set full of "hallucinated" inclusions or missing data.
Methods
SemReuse operates on a "trust aggressively, audit everything" philosophy. The system architecture is broken down into three main phases:
- Materialized View Store: Every query result is stored as a "view" containing the filter text, a bitmap of results, and lineage data.
- Two-Tier Reasoner: When a new query arrives, SemReuse compares it to cached views.
- Tier 1: A lightweight Natural Language Inference (NLI) model (DeBERTa) predicts if the new filter is equivalent to, broader than, narrower than, or disjoint from a cached one.
- Tier 2: If Tier 1 is uncertain, a small LLM call acts as an arbiter to decide the relationship.
- The Audit (The "Secret Sauce"): Because the reasoner can be wrong, SemReuse treats its plan as a hypothesis. It partitions the data into "candidates" (must be evaluated), "provisionally accepted," and "provisionally rejected" tuples. It then performs a pooled stratified audit using exact finite-population bounds (based on the hypergeometric distribution) to calculate per-query recall and precision certificates.
If the audit finds that the requested recall target (e.g., 90%) isn't met, the system "escalates" by evaluating more tuples until the guarantee is satisfied.
Datasets
The authors evaluated SemReuse using:
- 20 Newsgroups: A classic single-label dataset (7,951 docs).
- AG News: A larger dataset (up to 120,000 docs) with coarse classes.
- RCV1-v2: A massive multi-label, hierarchical dataset (up to 804,414 docs).
- Analyst Log: A custom log of 47 session-ordered filters used to test real-world LLM behavior (Llama-3.1, Qwen2.5, Mistral, and Gemma).
Key Insights and Ideas
- Directional vs. Symmetric Reuse: Traditional semantic caches use embedding similarity, which is symmetric. SemReuse recognizes that logic is directional: "baseball" implies "sports," but "sports" does not imply "baseball." This allows for much more granular reuse.
- The Consistency Bottleneck: A major "aha moment" in the paper is the discovery of cross-filter inconsistency. Even if an LLM "knows" at a language level that "A implies B," it might still label a specific tuple as A but not B. This inconsistency is the primary driver of "repair" costs in semantic systems.
- Constant Audit Cost: One of the most powerful features is that the audit sample size is largely independent of the total corpus size. Whether you have 10,000 or 1,000,000 rows, the number of samples needed to certify a result remains relatively flat.
Key Results
- Significant Speedups: On the AG News dataset, SemReuse reduced LLM calls by 14.66× compared to cold execution.
- Scalability: As shown in Figure 3, while the cost of cold evaluation grows linearly with the corpus size, the audit cost remains nearly constant. This means the efficiency of SemReuse actually improves as the dataset gets larger.
- Safety: Across tens of thousands of tests, the system never violated its certified precision and recall bounds when using a deterministic oracle.
Limitations and Future Work
- LLM Noise: The system assumes a deterministic oracle (fixed model, temperature 0). If the LLM itself is non-deterministic, the certificates can be violated.
- Unary Filters Only: Currently, SemReuse only handles simple filters. The authors suggest that extending this to semantic joins (comparing pairs of tuples) is a major area for future research.
- Repair Costs: If the LLM is highly inconsistent across related prompts, the "escalation" phase can become expensive, potentially eating into the savings gained from reuse. Future work will look at more cost-effective "repair" strategies.
Summary updated