Inferensys

Glossary

Document Expansion

A technique for improving sparse retrieval by using a generative model to add relevant terms to a document's representation before indexing, increasing its likelihood of matching future queries.
Developer building retrieval augmentation on laptop, document chunks and embeddings visualized, technical workspace.
SPARSE RETRIEVAL OPTIMIZATION

What is Document Expansion?

Document Expansion is a technique for improving sparse retrieval by using a generative model to add relevant terms to a document's representation before indexing, increasing its likelihood of matching future queries.

Document Expansion is a pre-indexing process where a generative model, often a sequence-to-sequence transformer, enriches a document's textual representation with additional, contextually relevant terms. This bridges the vocabulary gap between a document's original wording and the diverse language users employ in queries, directly improving recall for sparse retrieval algorithms like BM25 Scoring.

Unlike Query Expansion, which modifies the search input, document expansion shifts the computational burden to indexing time. A model like doc2query predicts queries the document might answer, appending them to the text. This creates a more robust, keyword-rich inverted index entry, ensuring the document is surfaced even when the user's query contains no exact lexical overlap with the original source material.

Core Mechanisms

Key Characteristics of Document Expansion

Document expansion bridges the lexical gap between user queries and indexed content by enriching document representations with additional, relevant terms before indexing. This shifts the computational burden to ingestion time, ensuring faster, more accurate retrieval.

01

Pre-Indexing Enrichment

Unlike query expansion, which modifies the user's input at search time, document expansion processes the entire corpus offline. A generative model analyzes each document and appends relevant terms, synonyms, or even full hypothetical sentences directly to the document's text or sparse representation. This ensures the expanded terms are indexed and immediately searchable via standard inverted indexes like BM25, without adding latency to the retrieval pipeline.

02

Bridging the Lexical Gap

The core problem solved is vocabulary mismatch. A user searching for 'cardiac arrest' might miss a document only containing 'myocardial infarction'. Document expansion uses a model to predict that these terms are contextually related and adds 'cardiac arrest' to the document's index entry. This improves recall for sparse retrieval methods by creating a denser, more semantically rich term space without abandoning the efficiency of keyword matching.

03

Generative Expansion with Doc2Query

A prominent technique uses a sequence-to-sequence model, often a fine-tuned T5 variant, trained to generate potential queries that a given document can answer. For each document, the model predicts multiple queries (e.g., 5-10), which are then appended to the document. This is known as Doc2Query. The expanded document is then indexed normally, making it highly likely to match a user's future, similarly phrased question.

04

Sparse Neural Representations

An alternative to generative text expansion is Learned Sparse Retrieval, where a neural model like SPLADE directly predicts term importance weights for the entire vocabulary. This creates a high-dimensional, sparse vector for each document where terms not originally present can have a non-zero weight. This effectively performs document expansion in a latent, weighted space, combining the interpretability of sparse vectors with the semantic power of neural models.

05

Controlled Vocabulary Augmentation

Expansion can be guided by structured knowledge. Using an enterprise knowledge graph or a domain-specific ontology, a document mentioning 'Apple' can be unambiguously expanded with 'AAPL', 'Cupertino', and 'Tim Cook' if the entity is resolved to the technology company. This entity linking step ensures high-precision expansion, adding only verified, disambiguated terms and avoiding the noise that can be introduced by purely generative models.

06

Trade-off: Recall vs. Precision

The primary risk of document expansion is query drift or a loss of precision. Adding too many loosely related terms can cause a document to be retrieved for irrelevant queries. For example, expanding a document about 'python' (the snake) with terms like 'programming' and 'script' would be incorrect. Effective deployment requires careful model tuning, often using pseudo-relevance feedback signals, to balance the significant gains in recall against the potential degradation in precision.

RETRIEVAL OPTIMIZATION STRATEGIES

Document Expansion vs. Query Expansion

A technical comparison of the two primary vocabulary gap bridging techniques, contrasting when terms are added to the index versus when they are added to the search request.

FeatureDocument ExpansionQuery ExpansionHybrid Expansion

Processing Target

Document corpus (offline)

User query (online)

Both index and query

Primary Goal

Increase recall for sparse retrieval

Increase recall for sparse retrieval

Maximize recall and precision

Computational Cost

High (one-time indexing)

Low (per-query inference)

High (indexing) + Low (query)

Latency Impact

None at query time

Adds 50-500ms per query

Minimal at query time

Vocabulary Gap Solution

Adds terms to documents

Adds terms to query

Bidirectional term injection

Risk of Query Drift

None

Moderate to High

Low

Sparse Retrieval Compatibility

Dense Retrieval Compatibility

DOCUMENT EXPANSION

Frequently Asked Questions

Clear, technical answers to the most common questions about using generative models to enrich document representations for improved sparse retrieval.

Document expansion is a retrieval augmentation technique where a generative model adds relevant terms to a document's textual representation before it is indexed, rather than modifying the user's query. The process works by feeding the original document text to a sequence-to-sequence model, such as Doc2Query or a fine-tuned T5 model, which predicts a set of queries or keywords that the document can answer. These generated terms are appended to the document's indexed fields, effectively increasing its term overlap with potential future queries. This bridges the vocabulary gap between the precise language of a document and the diverse, often imprecise, language of a searcher, dramatically improving sparse retrieval metrics like recall without any change to the search infrastructure at query time.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.