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
+20
View File
@@ -0,0 +1,20 @@
-- The schema the application expects. docker-compose.yml runs this on first start, and
-- scripts/pg-up.sh runs it against a local PostgreSQL. initialize-schema is false in
-- application.yml, so the application never creates or alters any of this itself.
CREATE EXTENSION IF NOT EXISTS vector;
CREATE SCHEMA IF NOT EXISTS rag;
-- metadata is json, the type Spring AI's PgVectorStore writes and its filter queries cast from.
-- 1536 is the size of a text-embedding-3-small vector; change it together with the model.
CREATE TABLE IF NOT EXISTS rag.document_chunks (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
content text,
metadata json,
embedding vector(1536)
);
-- HNSW with cosine distance, matching index-type and distance-type in application.yml.
CREATE INDEX IF NOT EXISTS document_chunks_embedding_idx
ON rag.document_chunks USING hnsw (embedding vector_cosine_ops);