Package io.agentscope.core.rag.reader
Class TikaReader
java.lang.Object
io.agentscope.core.rag.reader.AbstractChunkingReader
io.agentscope.core.rag.reader.TikaReader
- All Implemented Interfaces:
Reader
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();
-
Field Summary
Fields inherited from class io.agentscope.core.rag.reader.AbstractChunkingReader
chunkSize, overlapSize, splitStrategy -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TikaReader with default settings.TikaReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, ContentHandler handler) Creates a new TikaReader with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionGets the list of file formats supported by this reader.reactor.core.publisher.Mono<List<io.agentscope.core.rag.model.Document>>read(ReaderInput input) Reads a document and returns a list of chunked Document objects.Methods inherited from class io.agentscope.core.rag.reader.AbstractChunkingReader
getChunkSize, getOverlapSize, getSplitStrategy, validateChunkingParameters
-
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 textoverlapSize- the number of characters/tokens to overlap between chunkshandler- 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:ReaderReads 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
Description copied from interface:ReaderGets the list of file formats supported by this reader.- Returns:
- a list of supported file extensions (e.g., "txt", "md", "pdf")
-