spring-projects / spring-projects/spring-ai

Support for Text Chunking with Overlap in TokenTextSplitter

Open
#2,123 6 comments 52 reactions 1 assignee View on GitHub

@sobychacko is already working on this.

Since Aug 25, 2026.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Expected Behavior

The TokenTextSplitter class should support splitting text into chunks with an optional overlap between them. This would enable better context preservation when processing long texts that are chunked for downstream tasks such as embeddings or text analysis.

TokenTextSplitter splitter = TokenTextSplitter.builder().withChunkSize(800).withOverlapSize(50).build();

Current Behavior

Currently, the TokenTextSplitter class splits text into chunks without any overlap. While this works for cases where chunks are fully independent, it may result in loss of context between adjacent chunks, particularly in tasks like embeddings where continuity can improve results.

Context

Why it's needed
Chunking with overlap is critical for use cases where preserving context across chunks is necessary. For example:

  • Embedding generation, where continuity between chunks improves semantic representations.
  • Language models that benefit from adjacent context during token predictions.

Alternatives considered
The functionality can be implemented by extending TokenTextSplitter locally. However, a native implementation would ensure consistency and reusability across projects.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.