Sponsored by Deepsite.site

RagWiser

Created By
RobertoDure7 months ago
RagWiser is a Retrieval Augmented Generation (RAG) system built with Spring Boot that enables users to upload PDF documents, process them, and ask questions about their content using natural language.
Content

RagWiser

RagWiser is a Retrieval Augmented Generation (RAG) system built with Spring Boot that enables users to upload PDF documents, process them, and ask questions about their content using natural language.

Project Overview

RagWiser uses Spring AI and PGVector to create an advanced document question-answering system. It processes PDF documents, stores their vectorized representation in a PostgreSQL database with pgvector extension, and answers user queries by retrieving relevant context and generating responses using OpenAI's GPT models.

Features

  • PDF Document Upload: Upload and process PDF documents through a REST API
  • Document Vectorization: Automatically extracts text from PDFs, splits it into chunks, and stores embeddings
  • Semantic Search: Query documents using natural language
  • RAG-powered Response Generation: Get accurate answers based on the content of your documents
  • Spring AI Integration: Leverages Spring AI for vector stores and LLM integration
  • Docker Support: Containerized PostgreSQL with pgvector extension

Technology Stack

  • Java 21
  • Spring Boot 3.3.2
  • Spring AI 1.0.0-M1
  • PostgreSQL with pgvector extension
  • Docker
  • OpenAI GPT-4

Getting Started

Prerequisites

  • Java Development Kit (JDK) 21
  • Docker and Docker Compose
  • OpenAI API Key

Setup and Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/RagWiser.git
    cd RagWiser
    
  2. Configure your OpenAI API key in src/main/resources/application.yaml:

    spring:
      ai:
        openai:
          api-key: YOUR_OPENAI_API_KEY
    
  3. Start the PostgreSQL database with pgvector:

    docker-compose up -d
    
  4. Build and run the application:

    ./mvnw spring-boot:run
    

API Endpoints

Upload a PDF Document

POST /api/rag/upload
Content-Type: multipart/form-data

Parameters:

  • file: PDF file (required)

Ask a Question

GET /api/rag?question=YOUR_QUESTION_HERE

Parameters:

  • question: The question to be answered (default: "List all the Articles in the Irish Constitution")

How It Works

  1. Document Processing:

    • PDF documents are uploaded via the /api/rag/upload endpoint
    • The application uses PagePdfDocumentReader to extract text from PDFs
    • Text is split into chunks using TokenTextSplitter
    • Text chunks are embedded and stored in the vector database
  2. Question Answering:

    • User submits a question via the /api/question endpoint
    • The system retrieves the most relevant document chunks using vector similarity search
    • A prompt template combines the question and retrieved documents
    • OpenAI's GPT model generates an answer based on the context
  3. MCP Integration:

    • The application also provides a Tool-based integration for RAG capabilities using Spring AI's Tool Callbacks
    • This enables the RAG functionality to be used as a tool by other AI systems

Database Schema

The application uses a PostgreSQL database with the pgvector extension for storing document embeddings:

CREATE TABLE vector_store (
    id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
    content text,
    metadata json,
    embedding vector(1536)
);

CREATE INDEX ON vector_store USING HNSW (embedding vector_cosine_ops);

Configuration

Key configuration options in application.yaml:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/rag_db
    username: postgres
    password: postgres
  ai:
    openai:
      api-key: YOUR_OPENAI_API_KEY
      chat:
        options:
          model: gpt-4
  vectorstore:
    pgvector:
      index-type: HNSW
      distance-type: COSINE_DISTANCE
      dimensions: 1536
  servlet:
    multipart:
      enabled: true
      max-file-size: 100MB
      max-request-size: 100MB

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Acknowledgements

  • Spring AI Team for their excellent framework
  • PostgreSQL and pgvector for vector storage capabilities
  • OpenAI for their powerful language models
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Amap Maps高德地图官方 MCP Server
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Tavily Mcp
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
ChatWiseThe second fastest AI chatbot™
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Serper MCP ServerA Serper MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
DeepChatYour AI Partner on Desktop
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Playwright McpPlaywright MCP server
WindsurfThe new purpose-built IDE to harness magic
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
CursorThe AI Code Editor