spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

TokenTextSplitter.split() splits small text into multiple chunks if there is no ./?/!/\n at the end.

Open ilyakastsenevich opened this issue 1 year ago • 0 comments

spring ai version: 1.1.0

Steps to reproduce

    TokenTextSplitter splitter = TokenTextSplitter.builder()
        .withKeepSeparator(true)
        .withChunkSize(10000)
        .withMinChunkSizeChars(10)
        .build();

    Document testDoc = new Document("Hi. This is a small text without one of the ending chars. It is splitted into multiple chunks but shouldn't");
    List<Document> splitted = splitter.split(testDoc);
    for (Document doc : splitted) {
      System.out.println("content: " + doc.getText());
    }

console output: content: Hi. This is a small text without one of the ending chars. content: It is splitted into multiple chunks but shouldn't

Expected behavior only 1 chunk returned (no split because token count is small)

console output: content: Hi. This is a small text without one of the ending chars. It is splitted into multiple chunks but shouldn't

ilyakastsenevich avatar Nov 27 '25 15:11 ilyakastsenevich