Building an AI Contract Review System with Spring AI & RAG: 2-Month Case Study
This article details the development of an AI-powered contract review system using RAG and Spring AI, covering the tech stack (Java 21, Spring Boot 3.x, MySQL, Redis, MinIO), document parsing with Apache Tika and PaddleOCR, user roles, and features like clause-level risk detection, version control, and knowledge base management.
Project Overview
The author, a freelance developer known as Xiao Meng, describes a contracted project to build an AI-powered contract review system for 150,000 RMB with a two-month timeline and a team of three engineers. The system leverages Retrieval-Augmented Generation (RAG) to analyze uploaded contracts against enterprise policies, legal regulations, standard templates, and historical review cases. It identifies risk clauses, missing clauses, ambiguous wording, and compliance issues, providing risk explanations and modification suggestions. The AI assists decision-making but does not replace legal professionals' final judgment.
Core Features (Phase 1)
Upload and parse Word (DOCX), PDF, and TXT contracts
Contract classification
Intelligent clause-by-clause review with suggestions
Online revision and version management
Knowledge base management (enterprise policies, laws, templates, historical cases)
Report export
Business Process
The system follows a hybrid retrieval approach: document parsing, text chunking, embedding generation, vector storage, and hybrid retrieval (keyword + semantic) before passing relevant context to a large language model for analysis. The author references a business process diagram illustrating the flow from upload to risk report generation.
Tech Stack
Java 21 – Backend language, chosen for long-term support.
Spring Boot 3.x – Web services, dependency management, configuration, and base framework.
Spring AI – Large model invocation, prompt templates, structured output, embeddings, vector store, and RAG orchestration.
Spring Security + JWT – Authentication, API authorization, and RBAC permission control.
MyBatis-Plus – Business data access and pagination; JPA is an alternative.
MySQL 8.x – Structured data storage for users, contracts, review results, versions, rules, and logs.
Redis 7.x – Sessions, verification codes, caching, distributed locks, rate limiting, task progress, and short-term context.
Redisson – Distributed locks, rate limiters, and concurrency control.
MinIO / Object Storage – Storage for original contracts, knowledge files, exported files, and intermediate artifacts.
Apache Tika + POI + PDFBox – DOCX/PDF/TXT content parsing and DOCX generation.
OCR Service – Scanned contract text recognition; integrates PaddleOCR (GitHub: https://github.com/PaddlePaddle/PaddleOCR) or cloud OCR APIs.
SSE / WebSocket – Incremental push of review progress and results; SSE preferred for simplicity.
Spring Boot Actuator – Health checks and runtime metrics exposure.
OpenAPI / Knife4j – API documentation and integration testing.
User Roles
Regular business users
Legal personnel
Knowledge base administrators
System administrators
Auditors (optional)
Demo and Code
The article includes several screenshots demonstrating the system UI (contract upload, review results, clause suggestions, version comparison, knowledge base management, and report export). The author shares a demo code archive via Baidu Netdisk (link omitted as non-Git reference) and a contract template for freelance engagements.
PaddleOCR repository: https://github.com/PaddlePaddle/PaddleOCR
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
SpringMeng
Focused on software development, sharing source code and tutorials for various systems.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
