DocQAC: Adaptive Trie-Guided Decoding for Effective In-Document Query Auto-Completion

Rahul Mehta, Kavin R V, Indrajit Pal, Tushar Abhishek, Pawan Goyal, Manish Gupta

TL;DR

When searching within a long document, traditional web-based auto-completion fails because it prioritizes global popularity over local context. This paper introduces DocQAC, a framework that uses an adaptive, trie-guided decoding mechanism to softly steer small language models toward valid document-specific terms. The resulting system allows compact models like T5 and BART to outperform models over 20 times their size while maintaining the ultra-low latency required for real-world deployment.

What Problem Does This Paper Address?

Query Auto-Completion (QAC) is a ubiquitous feature in web search engines—think of typing "fr" into Google and instantly seeing suggestions like "facebook" or "free games." However, this approach fails when you are trying to search within a specific document (e.g., a 100-page legal brief or a dense technical manual). In this setting, termed DocQAC, global popularity is irrelevant. If you are reading a document about Paris, typing "fr" should suggest "france capital" or "france landmarks," not "free fire max."

DocQAC presents three unique challenges:

  1. Intent Locality: User intent is tightly bound to the active document.
  2. Vocabulary Shift: Documents often contain rare, domain-specific terminology or named entities absent from global search logs.
  3. Contextual Grounding: The exact same prefix requires entirely different completions depending on which document is being viewed.

While Large Language Models (LLMs) can generate text based on context, they suffer from "generative drift"—hallucinating plausible-sounding completions that don't actually exist in the document. Conversely, rigid rule-based systems lack the semantic flexibility to handle complex queries. This paper bridges that gap.

Methods

The authors propose an Adaptive Trie-Guided Decoding Framework that combines the semantic power of sequence-to-sequence models (like T5 and BART) with the strict grounding of trie data structures.

Instead of forcing hard constraints on the language model's output, the framework applies a soft, dynamic penalty to tokens during the decoding phase. At each step, if a predicted token diverges from the valid paths in the document's query or content trie, its logit score is penalized using an annealing schedule:

$$\text{annealed\_bias} = \text{initial\_bias} \cdot e^{-\alpha \cdot \text{length}} \cdot e^{-\beta \cdot \text{beam\_depth}}$$

This mathematical formulation allows the model to strictly adhere to the document's vocabulary during the early stages of typing, while gradually opening up room for creative and fluent generation as the query lengthens or drops into lower-ranked beams.

To feed the document context into the language models efficiently, the authors explored several input representations, as illustrated below:

Input Representations and DocQAC Methods

These include:

  • Short Inputs: Prefix only, or Prefix + Title + URL.
  • Longer Representations: Document summaries generated via ChatGPT, or keyphrases extracted using YAKE.
  • Retrieval-Augmented Generation (RAG): Dynamically pulling relevant text chunks using sparse (BM25) or dense similarity metrics.

Datasets

Because no dedicated dataset existed for this task, the authors constructed a new DocQAC benchmark derived from the ORCAS dataset (which contains 1.4M documents and 10M real-world user queries).

The dataset construction pipeline involves several rigorous steps:

  • Query Augmentation: Expanding the dataset by pulling the 100 most similar queries from Bing search logs using DeBERTa embeddings.
  • Relevance Labeling: Using GPT-4 as a binary classifier to filter out noisy or irrelevant query-document pairs.
  • Click Popularity Estimation: Calculating pseudo-counts for augmented queries based on historical click data.

The final benchmark is split into four distinct test scenarios to evaluate robustness: Seen Query-Seen Document (SS), Seen Query-Unseen Document (SU), Unseen Query-Seen Document (US), and Unseen Query-Unseen Document (UU).

Figure 1: DocQAC Dataset Construction Pipeline (detailed in Section 4). A document 𝐷in ORCAS has clicked queries 𝑄. Query Augmentation augments 𝐷with non-clicked queries 𝑄′ which are similar to 𝑄. Relevance Labeling filters queries in 𝑄and 𝑄′

Key Insights and Ideas

  • Small and Guided > Big and Blind: One of the most striking takeaways is that compact encoder-decoder models (like T5-Small or BART-Base) equipped with trie guidance consistently beat massive, unguided instruction-tuned models like LLaMA-3.2 (3B) and Phi-3.5 (3B) in seen-query settings. Guidance effectively compensates for a lack of raw parameters.
  • Soft Constraints Preserve Fluency: Hard constraint mechanisms often break the natural language flow of generative models. By using an annealed penalty, the system maintains a principled trade-off between model confidence and trie-based grounding.
  • Solving Tokenization Mismatch: A major engineering hurdle in trie-guided decoding is that users type character-by-character, but language models process text via subword tokens. The authors solved this by generating all possible character-level prefix-suffix splits during trie creation and introducing a unique separator token ([SEP_SPLIT]) to handle transitions cleanly at inference time.

Key Results

  • Performance Boost: On the Seen Query-Seen Document (SS) split, applying guided decoding to a standard BART model yielded a massive 48.1% improvement in Mean Reciprocal Rank (MRR) (jumping from 0.486 to 0.720) and a 19.4% increase in Typing Effort Saved (TES).
  • Efficiency Gains: The trie-guided T5 and BART models achieved these superior results while being 23x to 52.5x smaller than LLaMA-3.2 and Phi-3.5.
  • Production-Ready Latency: The soft-trie guidance adds a negligible overhead of only ~12 ms (e.g., T5 Guided DocQ + Sparse RAG takes 88 ms vs. 76 ms unguided), making it highly practical for real-time applications where sub-100ms response times are mandatory.

Limitations and Future Work

While the trie-guided approach dominates when the document or query has been seen during training, it faces a cold-start challenge on completely novel data. For the Unseen Query-Unseen Document (UU) split, larger generative models like LLaMA-3.2 and Phi-3.5 still achieve better aggregated results because a historical query trie cannot be pre-compiled.

The authors note that future work will focus on optimizing these specialized decoding algorithms using high-performance inference frameworks like TensorRT-LLM or FasterTransformers, and exploring ways to construct effective content-based tries dynamically on the fly for entirely unseen documents.

Summary updated

BibTeX
@inproceedings{mehta2026docqac,
  author = {Rahul Mehta and Kavin R V and Indrajit Pal and Tushar Abhishek and Pawan Goyal and Manish Gupta},
  title = {{DocQAC: Adaptive Trie-Guided Decoding for Effective In-Document Query Auto-Completion}},
  booktitle = {International ACM SIGIR Conference on Research and Development in Information Retrieval},
  year = {2026},
  doi = {10.1145/3805712.3809644},
}

Loading related content...

Figure