Package io.agentscope.core.rag.reader
Class TextReader
java.lang.Object
io.agentscope.core.rag.reader.AbstractChunkingReader
io.agentscope.core.rag.reader.TextReader
- All Implemented Interfaces:
Reader
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();
-
Field Summary
Fields inherited from class io.agentscope.core.rag.reader.AbstractChunkingReader
chunkSize, overlapSize, splitStrategy -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new TextReader with default settings.TextReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize) Creates a new TextReader 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
-
TextReader
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 textoverlapSize- 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: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")
-