This project is a Full Stack implementation of a Retrieval-Augmented Generation (RAG) application using Spring AI for the backend and Angular 21 for the frontend.
It demonstrates how to build a chatbot that can answer questions based on your own documents (PDF/Text) using a local vector store and a Large Language Model (Google Gemini).
-
Spring AI Backend:
- Uses PGVector (PostgreSQL) as the Vector Store.
- Uses Local ONNX Embeddings (
all-MiniLM-L6-v2) viaspring-ai-transformers(No external embedding API cost). - Uses Google Gemini (via Vertex AI/GenAI) for the chat completion model.
- Optimized for macOS (includes fixes for DJL native library compatibility).
- Robust document ingestion (sanitizes null bytes).
- configured for 384-dimensional embeddings to match the local model.
-
Angular Frontend:
- Built with Angular 21.
- Uses Signals for state management.
- Material Design UI (
@angular/material). - Markdown rendering for chat responses.
- File upload with progress tracking.
- Java 25 (or compatible JDK for Spring Boot 3.5+)
- Node.js (v18 or higher) & npm
- Docker & Docker Compose (for PostgreSQL/PGVector)
- Google Cloud API Key (for Gemini)
The application uses a specific Docker image (pgvector/pgvector:pg16) to enable vector similarity search.
cd spring-rag
docker-compose up -dThis starts PostgreSQL on port 5432 with the vector extension enabled.
-
Configure API Keys: Open
spring-rag/src/main/resources/application.propertiesand set your Google GenAI credentials. Alternatively, use environment variables:spring.ai.google.genai.api-key=${GENAI_API_KEY} spring.ai.google.genai.project-id=${GENAI_PROJECT_ID}
-
Run the Application:
cd spring-rag ./mvnw spring-boot:runNote: On the first run, the application will download the ONNX embedding model (approx. 50-100MB). This is normal.
-
Install Dependencies:
cd angular-rag npm install -
Start the Development Server:
ng serve
-
Access the UI: Open your browser to http://localhost:4200.
-
Upload a Document:
- Navigate to the Upload tab.
- Select a text file (
.txt) containing the information you want the AI to know. - Click Upload. The content will be chunked, embedded locally, and stored in Postgres.
-
Chat:
- Navigate to the Chat tab.
- Ask a question related to the uploaded document.
- The backend will perform a similarity search in PGVector, retrieve the context, and prompt Gemini to answer your question.
- spring-rag/: Spring Boot application.
RagService.java: Handles ingestion (chunking/embedding) and retrieval (RAG).RagConfiguration.java: Custom configuration for 384-dimension VectorStore and Local EmbeddingModel.DocumentController.java: REST endpoints.
- angular-rag/: Angular application.
chat/: Chat component (Signals-based).upload/: File upload component.
Unexpected flavor: cpu(macOS): This project explicitly pins DJL dependencies to0.28.0inpom.xmlto avoid a known issue with0.32.0on macOS.expected 768 dimensions, not 384: If you see this error, it means the database table was created with the wrong dimensions. Drop thevector_storetable in the database, and the app will recreate it correctly with 384 dimensions on the next restart.- Database Connection: Ensure Docker is running and port 5432 is available.