liveBook · Manning

TextReader

As explained in Spring AI in Action

TextReader is a Spring AI document reader that loads text-file contents into document objects.

TextReader is a Spring AI document reader for plain-text files. It reads a configured Resource and returns document objects that can enter a retrieval-augmented generation pipeline. section 4.3 section 4.3.3

Load and split a text file

A basic pipeline constructs TextReader with my-document.txt, obtains its documents, splits them with TokenTextSplitter, and passes the resulting chunks to a VectorStore. TextReader produces a single-entry List<Document> before splitting. section 4.3

Use TextReader when:

  • The source is a plain-text file and a simple document reader is sufficient. section 4.3.3
  • The resulting documents will be split into chunks before storage or downstream processing. section 4.3
  • Another reader is needed for JSON, PDF, or other formats; Spring AI also provides JsonReader and PDF readers. 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()));
}

Inspect the minimal Java pipeline from Resource through TextReader and TokenTextSplitter to VectorStore. section 4.3

How Spring AI in Action covers it

How deep it goes
Defines construction and output behavior, but does not detail TextReader internals or advanced format handling.
Examples
Uses my-document.txt in a pipeline that chunks its contents before saving them to a vector store.
What you can do after
Build a basic text-document ingestion pipeline with TextReader, TokenTextSplitter, and VectorStore.
How it connects
Connects DocumentReader with Resource, Document, TokenTextSplitter, and VectorStore.

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.