liveBook · Manning

Text chunk

As explained in Spring AI in Action

A document splitter divides a document into smaller chunks suitable for downstream processing.

Document chunking divides large documents into smaller Documents before embedding and storage, preventing an entire document from being sent as prompt context. section 4.3.3

A typical Spring AI loading pipeline connects these steps:

TokenTextSplitter targets a maximum of 800 tokens by default and avoids splitting mid-sentence. Its builder can adjust chunk size, separator retention, maximum chunk count, and minimum lengths. section 4.3.3

Configuring a splitter

TextSplitter splitter = TokenTextSplitter.builder()\n .withChunkSize(500)\n .withKeepSeparator(false)\n .withMinChunkLengthToEmbed(10)\n .build(); section 4.3.3

@Value("file://${HOME}/documents/my-document.txt")
private Resource documentResource;

public void loadDocument(VectorStore vectorStore) {
  DocumentReader reader = new TextReader(documentResource);
  TextSplitter splitter = TokenTextSplitter.builder().build();
  vectorStore.accept(splitter.apply(reader.get()));
}

See the smallest working pipeline: TextReader loads a resource, TokenTextSplitter creates chunks, and VectorStore accepts them. section 4.3

How Spring AI in Action covers it

How deep it goes
Explains token limits, sentence boundaries, reactive integration, and builder options, but leaves embedding and distance calculations to providers and vector stores.
Examples
Uses my-document.txt, uploaded game-rules documents, TokenTextSplitter settings, and a Board Game Buddy loading pipeline.
What you can do after
Build it from scratch by reading documents, configuring TokenTextSplitter, and sending the resulting chunks to a vector store.
How it connects
Connects document readers, vector stores, embeddings, metadata, and retrieval-augmented generation.

Also explained in

Compare how 19 books explain text chunk →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.