arXiv(opens in a new tab)cs.CLSep 2024Cited by 10 papers on PaperVantage

Manuscript Offprint

arXiv:2409.04701

Late Chunking: Contextual Chunk Embeddings Using Long-Context Embedding Models

Michael Günther, Isabelle Mohr, Daniel James Williams, Bo Wang, Han Xiao

ABSTRACT

Many use cases require retrieving smaller portions of text, and dense vector-based retrieval systems often perform better with shorter text segments, as the semantics are less likely to be “over-compressed” in the embeddings. Consequently, practitioners often split text documents into smaller chunks and encode them separately. However, chunk embeddings created in this way can lose contextual information from surrounding chunks, resulting in sub-optimal representations. In this paper, we introduce a novel method called “late chunking”, which leverages long context embedding models to first embed all tokens of the long text, with chunking applied after the transformer model and just before mean pooling - hence the term “late” in its naming. The resulting chunk embeddings capture the full contextual information, leading to superior results across various retrieval tasks. The method is generic enough to be applied to a wide range of long-context embedding models and works without additional training. To further increase the effectiveness of late chunking, we propose a dedicated fine-tuning approach for embedding models.

1 INTRODUCTION

Neural information retrieval (IR) relies on text embedding models (Reimers & Gurevych, 2019) that are primarily based on the transformer architecture (Devlin et al., 2019) and have been pre-trained using very large text corpora. These models capture important elements of texts' semantics in the form of dense vectors whose spatial relations - particularly cosine distance - are good proxies for text similarity and relevancy. For many neural IR use cases like the well-known RAG (Retrieval Augmented Generation) approach (Lewis et al., 2020), applications require splitting documents into limited-size text chunks, and storing them and their vector embeddings in a database. At run-time, neural IR techniques are used to retrieve chunks of text relevant to a user's requests, which are, in the case of RAG, presented to an LLM as a basis for synthesizing a response. Furthermore, many other applications require processing small text segments (Salton et al., 1993; Demszky et al., 2020), and therefore rely on chunking, e.g., to quickly navigate a user to the relevant passage in a document Callan (1994).

Moreover, while long context embedding models can improve retrieval performance on long texts (Günther et al., 2023), they still perform better on short texts (Zhou et al., 2024). As a result, chunking generally improves retrieval, even with models that support long contexts. (See Appendix A.1.) However, long-distance semantic dependencies – when the relevant information to interpret one chunk of text is located in one or more other chunks – reduce the effectiveness of this search strategy. Figure 1 displays a Wikipedia article 1^{1} that is split into chunks of sentences. One can see that phrases like “its” and “the city” referencing “Berlin” which is mentioned only in the first sentence, e.g., it is harder for the embedding model to link it to the respective entity to produce a high-quality representation.

To overcome this limitation, we introduce a novel technique called late chunking. This method leverages the long text embedding capabilities of recently published models (Günther et al., 2023;

1^{1}https://en.wikipedia.org/wiki/Berlin (Access 09-30-2024)

Berlin[a] is the capital and largest city of Germany, both by area and by population. [11] Its more than 3.85 million inhabitants.[12] make it the European Union's most populous city, as measured by population within city limits.[13] The city is also one of the states of Germany, and is the third smallest state in the country in terms of area. Berlin is surrounded by the state of Brandenburg, and Brandenburg's capital Potsdam is nearby. The urban area of Berlin has a population of over 4.5 million and is therefore the most populous urban area in Germany.[5][14] The Berlin-Brandenburg capital region has around 6.2 million inhabitants and is Germany's second-largest metropolitan region after the Rhine-Ruhr region, and the sixth-biggest metropolitan region by GDP in the European Union.[15]

Berlin[a] is the capital and largest city of Germany, both by area and by population. [11]

Its more than 3.85 million inhabitants[12] make it the European Union's most populous city, as measured by population within city limits.[13]

The city is also one of the states of Germany, and is the third smallest state in the country in terms of area.

Figure 1: An illustration of the lost context problem. A Wikipedia article about Berlin is split into chunks. One can see that phrases like “its” and “the city” reference “Berlin,” which is mentioned only in the first sentence. This makes it harder for the embedding model to link these references to the correct entity, thereby producing a lower-quality vector representation.

Table 1: Comparing the embedding of the term “Berlin” to various sentences from the article about Berlin using cosine similarity. The column “Sim. naive” shows the similarity values between the query embedding of “Berlin” and the embeddings using naive chunking, while “Sim. late” represents the results with the late chunking method.

TextSim. NaiveSim. Late
Berlin is the capital and largest city of Germany, both by area and by population.0.84860.8495
Its more than 3.85 million inhabitants make it the European Union's most populous city, as measured by population within city limits.0.70840.8249
The city is also one of the states of Germany, and is the third smallest state in the country in terms of area.0.75350.8498

Nussbaum et al., 2024) to, first, encode all tokens of an entire document with their full in-document context into a sequence of token embeddings, and then break this sequence up into chunks, which receive embeddings via mean pooling of their token embeddings. This way, chunk embeddings include relevant semantic information derived from their place in the whole text.

As an example of how late chunking works, we encode the texts in Figure 1 with a long-context embedding model, jina-embeddings-v2-small, using both naive and late chunking methods. We then calculate the similarity of the resulting embeddings to the embedding of the word “Berlin”. Table 1 shows that, with naive chunking, texts that do not contain the word “Berlin” have low similarity scores, even though both sentences, in context, refer to the city of Berlin. With late chunking, you can see that the similarity scores are much higher. The late chunking strategy has encoded “Berlin” into the embeddings of “Its” and “the city” because it sees them in their context before chunking the text.

Late chunking is an architectural change that can be implemented in any long-context text embedding model that uses mean pooling with any chunking technique and does not require additional model training. It leads to superior results compared to naive chunking across a wide range of retrieval benchmarks. To demonstrate the replicability of our results, we are publishing the code via GitHub 2^{2} . In particular, we make the following contributions:

  • Late Chunking: We describe our novel late chunking technique in Section 3 and demonstrate that it leads to superior results compared to naive chunking across a wide range of retrieval benchmarks.

2^{2} https://github.com/jina-ai/late-chunking

• Extended Algorithm for Long Documents: For encoding long documents with more tokens than long-context embedding models can handle, we propose a long late chunking approach (see Section 3.1) and prove its effectiveness in Section 4.3.

• Training for Late Chunking: While late chunking does not require additional training, we propose a novel training method to further enhance retrieval accuracy when using it (see Section 3.2). We conduct an evaluation to show its advantage over comparable contrastive training in Section 4.4.

• Comprehensive Evaluation: We conduct a comprehensive empirical evaluation to identify scenarios where late chunking performs superior to naive chunking and scenarios where the standard method yields comparable or superior results (see Sections 4.1 and 4.2).

References (38)