Class TikaReader

All Implemented Interfaces:
Reader

public class TikaReader extends AbstractChunkingReader
TikaReader is a document reader that uses Apache Tika to extract text from various document formats.

It supports various document formats (e.g. DOC, XSL, PDF, PPT ...) and splitting strategies.

Example usage:


 TikaReader reader = new TikaReader();
 ReaderInput input = ReaderInput.fromPath("/path/to/file");
 List<Document> documents = reader.read(input).block();
 
  • Constructor Details

    • TikaReader

      public TikaReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, ContentHandler handler)
      Creates a new TikaReader 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
      handler - the content handler to use for text extraction
      Throws:
      IllegalArgumentException - if parameters are invalid
    • TikaReader

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

      Defaults: chunkSize=512, strategy=PARAGRAPH, overlapSize=50, handler=BodyContentHandler(-1)

  • 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")