Package io.agentscope.core.rag.reader
Class PDFReader
java.lang.Object
io.agentscope.core.rag.reader.AbstractChunkingReader
io.agentscope.core.rag.reader.PDFReader
- All Implemented Interfaces:
Reader
PDF reader implementation that reads and extracts text from PDF files.
This reader extracts text content from PDF files and chunks it according to the specified strategy. It supports various text splitting strategies similar to TextReader.
Note: This is a basic implementation that reads PDF files as text. For full PDF parsing with proper text extraction, additional dependencies (e.g., Apache PDFBox) would be required. This implementation provides a foundation that can be extended.
Example usage:
PDFReader reader = new PDFReader(512, SplitStrategy.PARAGRAPH, 50);
ReaderInput input = ReaderInput.fromString("path/to/document.pdf");
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 PDFReader with default settings.PDFReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize) Creates a new PDFReader with the specified configuration.PDFReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, boolean extractImages) Creates a new PDFReader with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionGets the list of file formats supported by this reader.booleanChecks if image extraction is enabled.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
-
PDFReader
Creates a new PDFReader with the specified configuration.- Parameters:
chunkSize- the target size for each chunksplitStrategy- the strategy for splitting textoverlapSize- the number of characters to overlap between chunks- Throws:
IllegalArgumentException- if parameters are invalid
-
PDFReader
public PDFReader(int chunkSize, SplitStrategy splitStrategy, int overlapSize, boolean extractImages) Creates a new PDFReader with the specified configuration.- Parameters:
chunkSize- the target size for each chunksplitStrategy- the strategy for splitting textoverlapSize- the number of characters to overlap between chunksextractImages- true to extract images from PDF (placeholder for future implementation)- Throws:
IllegalArgumentException- if parameters are invalid
-
PDFReader
public PDFReader()Creates a new PDFReader 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")
-
isExtractImages
public boolean isExtractImages()Checks if image extraction is enabled.- Returns:
- true if image extraction is enabled
-