Class TextReader

All Implemented Interfaces:
Reader

public class TextReader extends AbstractChunkingReader
Text reader implementation that reads and chunks text documents.

This reader supports various text formats and splitting strategies. It can read text from strings or files and split them into chunks according to the specified strategy.

Example usage:


 TextReader reader = new TextReader(512, SplitStrategy.PARAGRAPH, 50);
 ReaderInput input = ReaderInput.fromString("Long text content...");
 List<Document> documents = reader.read(input).block();
 
  • Constructor Details

    • TextReader

      public TextReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize)
      Creates a new TextReader with the specified configuration.
      Parameters:
      chunkSize - the target size for each chunk (interpreted based on strategy)
      splitStrategy - the strategy for splitting text
      overlapSize - the number of characters/tokens to overlap between chunks
      Throws:
      IllegalArgumentException - if parameters are invalid
    • TextReader

      public TextReader()
      Creates a new TextReader with default settings.

      Defaults: chunkSize=512, strategy=PARAGRAPH, overlapSize=50

  • Method Details

    • read

      public reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>> read(ReaderInput input)
      Description copied from interface: Reader
      Reads a document and returns a list of chunked Document objects.

      Errors during reading are propagated through the Mono via Mono.error().

      Parameters:
      input - the input to read (text, file path, URL, etc.)
      Returns:
      a Mono that emits a list of Document objects, or an error signal on failure
    • getSupportedFormats

      public List<String> getSupportedFormats()
      Description copied from interface: Reader
      Gets the list of file formats supported by this reader.
      Returns:
      a list of supported file extensions (e.g., "txt", "md", "pdf")