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:
Claude
2026-09-21 19:09:05 +00:00
commit 1d4625a1c2
62 changed files with 3715 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The dependency block of the 1.x version of the "Production-Grade RAG with Spring AI" article,
as it was published, with only the version made a property. It is not part of the build:
scripts/capture-legacy-compile.sh runs it on purpose, to show what happens.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ankurm</groupId>
<artifactId>legacy-1x</artifactId>
<version>0</version>
<packaging>pom</packaging>
<properties>
<spring-ai.version>1.1.0</spring-ai.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-pdf-document-reader</artifactId>
</dependency>
</dependencies>
</project>
+25
View File
@@ -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);
}
}