Spring / Spring AI interview questions
What DocumentReaders does Spring AI provide for loading content into the RAG pipeline?
A DocumentReader is the entry point of the RAG ingestion pipeline — it reads raw source material and converts it into a List<Document> that can then be chunked and embedded. Spring AI ships several ready-made readers so you do not need to write file-parsing code yourself.
- PdfDocumentReader — reads PDF files using Apache PDFBox. Each page or a configurable page range becomes one Document, with page number stored in metadata.
- TikaDocumentReader — uses Apache Tika to extract text from Word documents, Excel files, PowerPoint presentations, HTML, and more. A single reader handles dozens of formats.
- TextReader — reads plain text files from classpath or filesystem.
- JsonReader — reads JSON documents and can extract specific fields via a JSON pointer.
- PagePdfDocumentReader — a variant of PdfDocumentReader that creates one Document per paragraph rather than per page, improving chunk granularity.
// PDF List<Document> pdfDocs = new PdfDocumentReader( new ClassPathResource("handbook.pdf")).get(); // Word / Office files via Tika List<Document> wordDocs = new TikaDocumentReader( new FileSystemResource("/data/policy.docx")).get();
You can chain readers with splitters and then hand the final chunk list to vectorStore.add(). For web pages, Spring AI does not include a built-in HTML reader as of 1.x — teams typically use JSoup to extract text and wrap it in Document objects manually, or use the ETL pipeline utilities.
More Related questions...