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
@@ -0,0 +1,31 @@
# RecursiveChunker and SemanticChunker
--- RecursiveChunker(maxChars=400, overlapChars=80) ---
chunks: 14, longest: 395 characters
chunk 0: 314 chars, starts "Sentence 1 describes the", ends "very full-time employee."
chunk 1: 388 chars, starts "for item 3 and states th", ends "very full-time employee."
chunk 2: 387 chars, starts "for item 6 and states th", ends "very full-time employee."
chunk 3: 394 chars, starts "for item 9 and states th", ends "very full-time employee."
chunk 4: 394 chars, starts "for item 12 and states t", ends "very full-time employee."
chunk 5: 395 chars, starts "for item 15 and states t", ends "very full-time employee."
chunk 6: 395 chars, starts "for item 18 and states t", ends "very full-time employee."
chunk 7: 394 chars, starts "for item 21 and states t", ends "very full-time employee."
chunk 8: 395 chars, starts "for item 24 and states t", ends "very full-time employee."
chunk 9: 394 chars, starts "for item 27 and states t", ends "very full-time employee."
chunk 10: 395 chars, starts "for item 30 and states t", ends "very full-time employee."
chunk 11: 395 chars, starts "for item 33 and states t", ends "very full-time employee."
chunk 12: 394 chars, starts "for item 36 and states t", ends "very full-time employee."
chunk 13: 180 chars, starts "for item 39 and states t", ends "very full-time employee."
metadata of chunk 2: {chunk_index=2, chunk_total=14, page_number=1, source_file=long.txt}
boundaries where the next chunk opens with words the previous one ended with: 13 of 13
--- one 900-character word-salad with no separators falls back to a hard cut ---
chunks: [400, 400, 100]
--- SemanticChunker(distance 0.9) on three topics, four sentences each ---
chunks: 3
[0] Annual leave is twenty days per year. Unused annual leave carries over until March. Leave requests go through the HR portal. Annual leave accrues monthly.
[1] Expenses need a receipt above fifty euros. Expense claims must be filed within thirty days. Receipts for expenses are uploaded as photos. Approved expenses are paid with salary.
[2] Remote work is allowed two days per week. Managers agree the remote work days. Remote work needs a quiet workspace. Remote work days are recorded in the calendar.
texts sent to the embedding model: 12 (12 sentences, one batched call)