RIVET: Regex-to-Indexable Keys via Neural Translation for Interactive LIMIT-k Retrieval

Dong Wang, Yingze Li, Zihang Yu, Ziqing Zeng, Zongdai Jiang, Yuhao Zhang, Kaixin Zhang, shuangshuang cui, Hongzhi WangNeurIPS 2026

TL;DR

Searching massive database columns with regular expressions (regexes) is painfully slow when the pattern contains wildcards that bypass standard indexes—especially when you only want a quick preview of the first k matches. RIVET solves this by training a lightweight neural model to "translate" complex regexes into short, column-specific prefix keys that can use existing indexes. By jumping straight to high-yield buckets of data and letting the native database engine verify the final outputs, RIVET speeds up interactive queries by up to 36× over state-of-the-art regex indexes with zero loss in exactness.

What Problem Does This Paper Address?

Imagine it’s late, an outage is unfolding, and you’re querying millions of log lines with a regex, adding LIMIT 64 just to preview if your pattern works. Under the hood, regex engines are exact verifiers, not searchers; checking millions of rows one by one (a sequential scan) takes forever.

Databases usually accelerate this using a "key-then-verify" approach: extract literal substrings or trigrams directly from the regex surface, probe an index to grab candidate rows, and run the expensive regex check only on the survivors.

Figure 1: RIVET casts interactive LIMIT-k regex retrieval as constrained regex-to-key generation. (A) Keys read off the regex surface are column-agnostic and often low-yield. (B) RIVET’s column- specific translator emits indexable keys that need not appear in the regex. (C) A Key+Verify executor probes the index, verifies with the regex engine, and stops once k matches are found.

Here is the catch: reading keys off the regex surface is completely blind to the actual data distribution. Take the query ^T.*son$ on a column of names. A traditional index extractor might grab son, pulling in thousands of "Andersons" and "Aaronsons" that fail verification. Meanwhile, a prefix like Tho or Tim isn't explicitly in the regex, yet in this specific column, it points straight to "Thompson" and "Timson". For LIMIT-k queries, the bottleneck is finding a handful of indexable keys that point to match-rich candidate buckets first, so the engine can find k matches and clock out early.

Methods

RIVET reframes candidate selection as constrained neural translation, pairing a small learned model with standard, battle-tested database machinery.

  • What’s New (Offline & Online Translation): Without needing historical query logs, RIVET samples "anchor" records directly from the target text column, synthesizes regexes that match them, and extracts each record's fixed-length prefix (e.g., first $\ell$ characters). A compact (30M-parameter), character-level Transformer seq2seq model is trained to translate a regex into these prefixes. Because the same synthesized regex naturally hits multiple records during sampling, the model learns to place probability mass across multiple valid prefixes. At query time, RIVET uses a mix of beam search (for high-probability hits) and temperature sampling (for diversity) to propose keys, filters them against the column's actual prefix dictionary, deduplicates them, and caps them at a strict budget ($t_{\text{max}}$).
  • What’s Standard (Execution & Exactness): Databases don't trust neural nets with exact semantics—and RIVET doesn't ask them to. The generated prefixes simply become standard indexed queries (like LIKE 'Tho%' on an existing B-tree). The native regex engine verifies every retrieved candidate, halting the moment k matches are found. If the key budget runs dry before hitting k—say, if you strictly require a full limit rather than a quick preview—a residual table scan cleanly finishes the job.
Figure 2: RIVET system overview. Offline, RIVET builds column-derived supervision pairing each regex with multiple prefix keys and trains a translator fθ. Online, fθ produces a proposal stream that is dictionary-filtered, deduplicated, and budget-capped into a small key set Kθ(Q). The executor probes existing indices with Kθ(Q), verifies candidates with the regex engine, and stops when k matches are found or the budget is exhausted.

Datasets

RIVET is evaluated on four large text columns ranging from 2 million to 24 million rows:

  • IMDB person names (5.0M rows)
  • WIKI article titles (2.0M rows)
  • TPC-H lineitem.comment strings (24.0M rows)
  • US-Acc traffic accident descriptions (7.72M rows)

Alongside four synthesized PostgreSQL regex workloads varying in wildcard complexity, the authors introduce an out-of-distribution (OOD) benchmark of 80 human-authored regexes mined from StackOverflow and arXiv—featuring denser character classes and tricky infix/suffix constraints—without retraining the models.

Key Insights and Ideas

  • Useful keys live in the column, not the query: A literal fragment might be rare in names, ubiquitous in server logs, and absent from the surface of an alternation-heavy regex. Specializing a tiny translator to a single column captures local templates and formatting regularities that static extraction rules miss.
  • General-purpose LLMs flop at this task: Can a massive LLM guess good prefix keys using world knowledge? Nope. Zero-shot giants (up to 671B parameters like DeepSeek-V3.2 and Qwen3.5) only hit valid column prefixes 26%–33% of the time (vs. 97%–99% for RIVET) while running up to 1,040× slower. Useful index keys are a property of your specific table, not natural language priors.
  • Probability concentration + diversity = early stopping: You don't need every matching bucket—just enough to hit k rows. Combining greedy high-mass beams with stochastic temperature sampling dramatically outperforms either alone, pushing Recall@64 from ~0.45–0.69 (single greedy decode) to 0.986.

Key Results

Single-column LIMIT-64 latency and speedups across datasets

Single-column LIMIT-64 latency and speedups across datasets
  • Blazing Single-Column Speed: For LIMIT 64 queries, RIVET achieves 26.3–71.3 ms latency (35.8 ms median) with ~0.986 recall under its fixed key budget. It beats the fastest regex-indexing baseline (REI) by 3.4×–36.2× and sequential scans by up to 1,773×.
  • Interactive Previews & Plans: Under a strict 500 ms interactive budget, RIVET completes 99% of LIMIT 64 preview queries (REI manages 74%). Dropped into full multi-table TPC-H query plans, it trims end-to-end execution latency by 1.23×–1.77×.
  • OOD & Deployment Practicality: On the 80 wild human regexes, fixed-budget RIVET hits 0.622–0.878 recall in 48–92 ms (and adding a residual scan for 100% recall is still 3.6×–33.9× faster than scanning from scratch). Training takes ~39 minutes per column, yields a ~60 MB model, and breaks even on compute investment in under 2 days at 5,000 queries/day.

Limitations and Future Work

  • Dispersed and non-prefix patterns: Because RIVET instantiates keys as prefixes, regexes constrained purely by suffixes, infixes, or matches thinly scattered across hundreds of tiny prefix buckets can exhaust its key budget, forcing a fallback to slower residual scans.
  • Per-column upkeep and hardware: Every indexed column needs its own trained specialist (pooling columns degrades recall) and lightweight periodic fine-tuning if data drifts (~2 minutes per partition). Additionally, sub-75ms latencies rely on colocated GPU inference; CPU-only inference bumps median translator time to ~154 ms, and sequential scans still win on tiny tables (<5,000 rows).
  • Future Directions: The authors note that on hard OOD queries, the fastest path to 100% completion varies by dataset—motivating future cost-based query planners that dynamically route between RIVET, traditional n-gram filters, or scans.

Summary updated

Abstract

Interactive regex search over large text columns needs exact matches under low latency, but indexes help only when a pattern exposes selective fragments. For LIMIT-k queries, the immediate bottleneck is choosing a few indexable keys that reach match-rich candidate buckets before regex verification. RIVET casts this step as constrained regex-to-key generation: a column-specific translator emits short keys, an existing index retrieves candidates, and the native regex engine verifies every output record. Training from repeated regex-key hits moves probability mass toward effective keys, so finite online sampling spends fewer regex checks before collecting the requested matches. Across four large datasets, RIVET reaches 35.8 ms median latency, improves over the strongest baseline REI by 3.4–36×, and reaches up to 1773× speedup over sequential scan. The same mechanism improves TPC-H query plans, preview retrieval under latency budgets, and 80 human-authored OOD regex queries, showing that regex-to-key generation translates into end-to-end system gains.
BibTeX
@inproceedings{wang2026rivet,
  author = {Dong Wang and Yingze Li and Zihang Yu and Ziqing Zeng and Zongdai Jiang and Yuhao ZHANG and Kaixin Zhang and shuangshuang cui and Hongzhi Wang},
  title = {{RIVET: Regex-to-Indexable Keys via Neural Translation for Interactive LIMIT-k Retrieval}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=SU1cZgGHjB},
}
Figure