Abstract
A limitation of modern document retrieval embedding methods is that they typically encode passages (chunks) from the same documents independently, often overlooking crucial contextual information from the rest of the document that could greatly improve individual chunk representations. In this work, we introduce ConTEB (Contextaware Text Embedding Benchmark), a benchmark designed to evaluate retrieval models on their ability to leverage document-wide context. Our results show that state-of-the-art embedding models struggle in retrieval scenarios where context is required. To address this limitation, we propose InSeNT (In-sequence Negative Training), a novel contrastive posttraining approach which combined with late chunking pooling enhances contextual representation learning while preserving computational efficiency. Our method significantly improves retrieval quality on ConTEB without sacrificing base model performance. We further find chunks embedded with our method are more robust to suboptimal chunking strategies and larger retrieval corpus sizes. We opensource all artifacts at https://github.com/illuin-tech/contextual-embeddings.
Introduction
In modern Retrieval-Augmented Generation (RAG) pipelines, long documents are typically partitioned into smaller "chunks" to accommodate the context window constraints of vector databases and embedding models. Traditionally, these chunks are embedded independently, a practice that leads to "context blindness." For instance, a chunk stating, "He became emperor in 1804," loses its semantic utility if the antecedent "Napoleon" appeared several paragraphs prior. By stripping away the surrounding document structure, retrievers lose co-references, hierarchy, and disambiguating details. While Large Language Model (LLM) based reformulation can mitigate this, such methods are often prohibitively expensive and slow for industrial-scale applications.
Methodology
To resolve the context-blindness problem without the overhead of LLMs, we propose a two-pronged approach combining architectural innovation with a novel training objective.
Late Chunking
Instead of embedding chunks in isolation, we utilize a long-context encoder (e.g., ModernBERT) to process the entire document (up to 8,192 tokens). Chunk-level embeddings are generated via "late pooling"—averaging token representations only after the model has processed the full document context. This allows information to flow across chunk boundaries during the encoding phase.
In-sequence Negative Training (InSeNT)
Naively applying late chunking can lead to "embedding collapse," where all chunks within a document become too similar to be distinguished. To counter this, we introduce InSeNT. During contrastive training, the model must distinguish a "gold" chunk from two types of negatives: standard in-batch negatives (from other documents) and in-sequence negatives (other chunks from the same document). This forces the model to integrate document-wide context while preserving the unique semantic signature of each specific passage.
The ConTEB Benchmark
We introduce the Context-aware Text Embedding Benchmark (ConTEB) to evaluate models in scenarios where context is mandatory. ConTEB includes:
- Controlled Tasks: Datasets like Football and Geography where subjects are replaced with pronouns, requiring document-header lookups.
- Industrial Scenarios: ESG reports and insurance documents requiring structural disambiguation.
- Academic Repurposing: Context-dependent subsets of MLDR, NarrativeQA, and SQuAD.
Key Results and Discussion
Our experiments demonstrate that the combination of ModernBERT and InSeNT yields massive accuracy gains. On the ConTEB benchmark, our model achieved an nDCG@10 of 75.6, a significant leap from the 52.0 baseline of standard ModernBERT.
Beyond accuracy, our method offers several practical advantages:
- Efficiency: InSeNT is 120x faster at indexing than LLM-based reformulation methods because it requires only a single encoder forward pass.
- Robustness: Contextual embeddings are significantly more resilient to suboptimal chunking strategies. Even if a sentence is split across chunks, the model retains the full semantic meaning through the shared document context.
- Scalability: The performance gap between contextual and non-contextual models widens as the corpus size grows, suggesting that context is a critical factor for maintaining precision in large-scale production environments.
Conclusion
Contextual document embeddings represent a significant step forward for retrieval systems. By leveraging Late Chunking and InSeNT, we can achieve LLM-level retrieval quality with the efficiency of traditional encoder models. Future work will explore extending these techniques to decoder-only architectures and visually rich multimodal documents.
Summary updated