Skip to content

Spring Boot application that uses Spring AI implementing RAG (Retrieval-Augmented Generation) to help users understand and query documents. For this prototype I used the constitution of The Republic of Ireland, but any collection of documents can be used to achieve the state-of-the-art RAG in Java.

Notifications You must be signed in to change notification settings

RobertoDure/spring-ai-rag-pgvector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LawWiser

Overview

LawWiser is a Spring Boot application that uses Spring AI implementing RAG (Retrieval-Augmented Generation) to help users understand and query documents. For this prototype I used the constitution of The Republic of Ireland, but any collection of documents can be used to achieve the state-of-the-art RAG in Java.

Features

  • Natural Language Queries: Ask questions about the Irish Constitution in plain English
  • AI-Powered Responses: Leverages Spring AI and vector embeddings to generate accurate answers
  • Semantic Search: Finds relevant constitutional sections based on the meaning of your query, not just keywords
  • PDF Document Processing: Automatically extracts and processes constitutional text from PDF documents

Technology Stack

  • Spring Boot: Core application framework
  • Spring AI: AI capabilities and chat model integration
  • Vector Database: Stores document embeddings for semantic searching
  • PostgreSQL with pgvector: Database backend for vector storage
  • PDF Document Processing: Extracts constitutional text from PDF sources

Getting Started

Prerequisites

  • Java 17 or higher
  • Maven
  • PostgreSQL with pgvector extension

Running the Application

  1. Clone the repository
  2. Configure your database connection in application.yaml
  3. Run the application using Maven:
    ./mvnw spring-boot:run
    
  4. Access the API at http://localhost:8080

Usage

Send GET requests to the root endpoint with your question as a parameter:

GET /?question=What does Article 6 of the Irish Constitution say?

The application will:

  1. Process your query
  2. Search for relevant sections in the Irish Constitution
  3. Use AI to generate a comprehensive answer based on the constitutional text

How It Works

  1. Document Loading: The application loads the Irish Constitution PDF and splits it into manageable chunks
  2. Vector Embeddings: The text chunks are converted into vector embeddings and stored in a vector database
  3. Semantic Search: When a query is received, the application finds the most relevant constitutional sections
  4. AI Response Generation: The system prompts an AI model with your question and the relevant constitutional sections to generate an accurate answer

Project Structure

  • LawWiserApplication.java: Main application entry point
  • LawWiserController.java: REST controller handling user queries
  • DataLoader.java: Responsible for loading and processing the constitutional document

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Spring Boot application that uses Spring AI implementing RAG (Retrieval-Augmented Generation) to help users understand and query documents. For this prototype I used the constitution of The Republic of Ireland, but any collection of documents can be used to achieve the state-of-the-art RAG in Java.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages