Add rag module: Spring AI 2.0 RAG with pgvector, chunking, reranking and a faithfulness check
Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B38FGKKam5SCGgwgduVAh3
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.reader.pdf.PagePdfDocumentReader;
|
||||
import org.springframework.ai.reader.pdf.config.PdfDocumentReaderConfig;
|
||||
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* The two Spring AI calls from the 1.x article's ingestion service, unchanged (including the
|
||||
* regex, which lost its backslash when the article was first published). Compiled, not run.
|
||||
*/
|
||||
class LegacyIngestion {
|
||||
|
||||
List<Document> ingest(Resource pdfResource) {
|
||||
PdfDocumentReaderConfig readerConfig = PdfDocumentReaderConfig.builder()
|
||||
.withPageExtractedTextFormatter(text -> text.replaceAll("s{3,}", " "))
|
||||
.withPagesPerDocument(1)
|
||||
.build();
|
||||
List<Document> pages = new PagePdfDocumentReader(pdfResource, readerConfig).get();
|
||||
|
||||
TokenTextSplitter splitter = new TokenTextSplitter(512, 128, 5, 10_000, true);
|
||||
return splitter.apply(pages);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user