TokenTextSplitter is a Spring AI TextSplitter that converts large Documents into smaller, token-bounded Documents before they are stored in a vector store. It supports document-ingestion pipelines for retrieval-augmented applications and avoids splitting text in the middle of a sentence. section 4.3 section 4.3.3
Configure the splitter through its builder when the default behavior does not fit the ingestion workload:
- Target chunks contain no more than 800 tokens by default; smaller chunks may result when sentence boundaries require them. section 4.3.3
A configured splitter
TextSplitter splitter = TokenTextSplitter.builder() .withChunkSize(500) .withKeepSeparator(false) .withMinChunkLengthToEmbed(10) .build();
