Skip to main content
QUICK REVIEW

[Paper Review] Contextual Document Embeddings

John X. Morris, Alexander M. Rush|arXiv (Cornell University)|Oct 3, 2024
Natural Language Processing TechniquesComputer Science3 citations
TL;DR

This paper proposes Contextual Document Embeddings (CDE), a dual approach to improve neural retrieval by incorporating neighboring documents into both training and model architecture. By using contextual contrastive learning and a context-augmented encoder, CDE achieves state-of-the-art performance on the MTEB benchmark without hard negative mining or large batch sizes, especially excelling in out-of-domain and low-resource settings.

ABSTRACT

Dense document embeddings are central to neural retrieval. The dominant paradigm is to train and construct embeddings by running encoders directly on individual documents. In this work, we argue that these embeddings, while effective, are implicitly out-of-context for targeted use cases of retrieval, and that a contextualized document embedding should take into account both the document and neighboring documents in context - analogous to contextualized word embeddings. We propose two complementary methods for contextualized document embeddings: first, an alternative contrastive learning objective that explicitly incorporates the document neighbors into the intra-batch contextual loss; second, a new contextual architecture that explicitly encodes neighbor document information into the encoded representation. Results show that both methods achieve better performance than biencoders in several settings, with differences especially pronounced out-of-domain. We achieve state-of-the-art results on the MTEB benchmark with no hard negative mining, score distillation, dataset-specific instructions, intra-GPU example-sharing, or extremely large batch sizes. Our method can be applied to improve performance on any contrastive learning dataset and any biencoder.

Motivation & Objective

  • To address the limitation of standard biencoder models that produce embeddings independent of document context, which hinders performance in domain-specific or out-of-domain retrieval.
  • To improve retrieval performance by explicitly incorporating neighboring documents into the training objective and model architecture.
  • To develop a training-free, scalable method for test-time adaptation that enhances generalization across diverse domains.
  • To demonstrate that contextualization of document embeddings leads to more robust and domain-aware representations without increasing inference cost.
  • To achieve state-of-the-art results on the MTEB benchmark using only standard contrastive training and a novel architecture, without relying on hard negatives, distillation, or large batch sizes.

Proposed method

  • Proposes a contextual contrastive learning objective that clusters documents in-batch and uses neighboring documents as negatives, increasing batch difficulty and improving representation learning.
  • Introduces a new encoder architecture that injects aggregated information from neighboring documents into the main document embedding via conditional conditioning.
  • Uses fast query-document clustering to identify relevant neighbors during pre-training, ensuring that each batch contains semantically similar documents for stronger contrastive signals.
  • Employs a dual-stage process: first, a corpus characterization phase to identify contextual neighbors; second, a final embedding phase that incorporates this context into the model output.
  • Maintains standard embedding dimensionality, enabling compatibility with existing retrieval pipelines without additional storage or inference overhead.
  • Applies the method to any biencoder or contrastive learning setup, enabling performance gains across diverse retrieval tasks.

Experimental results

Research questions

  • RQ1Can improving the contrastive learning objective by incorporating document neighbors lead to better generalization in retrieval tasks?
  • RQ2Does explicitly encoding contextual document information in the model architecture improve performance, especially in low-resource or out-of-domain settings?
  • RQ3Can a contextualized training and architecture approach achieve state-of-the-art results without relying on hard negative mining, data-specific instructions, or extremely large batch sizes?
  • RQ4How does the inclusion of in-domain contextual documents affect performance across different domains, such as medical, financial, or forum-based text?
  • RQ5To what extent does the model’s performance degrade when contextual information is replaced with random documents, indicating the importance of context?

Key findings

  • CDE achieves state-of-the-art performance on the MTEB benchmark for models with 250M parameters or fewer, outperforming models like BGE, GTE, and Nomic-Embed without hard negatives or distillation.
  • The contextual contrastive training method improves performance across all MTEB tasks, with a 1.2-point average drop in performance when random documents replace contextual ones, indicating strong dependency on context.
  • The contextual encoder architecture improves performance over baseline models in all tested settings, with larger gains in specialized domains such as medical and financial text.
  • Larger batch sizes lead to easier negatives, while smaller cluster sizes increase the average difficulty of in-batch negatives, which correlates with improved performance.
  • On the CQADupstack forum dataset, in-domain contextual documents consistently improve performance, with red squares in Figure 7 indicating that domain-specific context is most effective.
  • The model maintains high performance across diverse tasks including classification, clustering, semantic similarity, and retrieval, demonstrating broad applicability.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.