How rahullbs/rag-assist works
1. This repository is a single Spring Boot application that implements a local Retrieval-Augmented Generation (RAG) system. The main runtime is Java 17 with Maven packaging, and the application is started from DocAssistApplication.
2. The system has three core layers inside the Spring Boot service:
- controller for HTTP APIs
- service for RAG/business logic
- repository for database access and vector search
3. The primary external dependencies are both local services:
- PostgreSQL with the pgvector extension for storage and similarity search
- Ollama for model inference, using nomic-embed-text for embeddings and mistral for generation
This means the app does not call hosted AI APIs; all model traffic stays on the local network.
4. The document ingestion path is: client request → DocumentController → DocumentService → embedding generation via EmbeddingService → persistence through DocumentRepository into PostgreSQL. Each stored record contains the raw text plus its embedding vector.
5. The retrieval path is: client query → controller → service → embedding the query with the same embedding model → vector similarity search in PostgreSQL via pgvector. The README indicates cosine similarity with an HNSW index, so database-side nearest-neighbor search is a major architectural boundary.
6. The full RAG answer path is: user question → query embedding → top-k retrieval from the document store → context assembly in the service layer → prompt sent to Ollama’s chat model (mistral) → generated answer returned to the caller. The prompt construction happens in application code, not in the database or model server.
7. EmbeddingService is the integration point for model embedding calls. It is important because the embedding dimension is fixed at 768, matching the database schema. This alignment is a hard architectural contract between the Ollama model and the pgvector column.
8. DocumentRepository represents the persistence boundary. The repository is responsible for storing documents and issuing vector search queries against PostgreSQL. The README notes a casting issue was solved with explicit vector casting, which reinforces that the repository layer is tightly coupled to pgvector semantics.
9. The database setup is separated from the application code in rag_database_setup. That area contains the SQL schema and Docker setup used to provision PostgreSQL, enable vector, create the documents table, and add the HNSW index. In architecture terms, this is the infrastructure/bootstrap side of the system.
10. application.yaml is the configuration seam for all external connections: PostgreSQL datasource settings and Ollama base URL/model names. These settings define the service boundaries at runtime and are the main place where environment-specific wiring lives.
11. EmbeddingController likely exposes embedding-related or diagnostic endpoints alongside DocumentController, but the main functional API surface described in the README is document ingestion, search, and question answering. The controllers are thin HTTP adapters; the real orchestration is in the service layer.
12. The project is intentionally production-shaped but local-only: one application process coordinates two external local services, with PostgreSQL handling durable storage and fast vector retrieval, and Ollama handling both embedding and generation. The key architecture diagram should show a single Spring Boot core with two outbound dependencies, one to the database and one to the model server.
Main entry points: DocumentService.java Document service · EmbeddingService.java Embedding service · DocAssistApplication.java DocAssist · application.yaml App config
Components 13
Spring Boot app
Main Java 17 application and runtime layers
- DocAssist · Spring Boot entrypoint for the RAG service
docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java - Doc API · HTTP endpoints for document ingestion and RAG requests
docAssist/src/main/java/com/docassist/Rag/controller/DocumentController.java - Embed API · HTTP endpoints related to embeddings or diagnostics
docAssist/src/main/java/com/docassist/Rag/controller/EmbeddingController.java - Document service · Orchestrates ingestion, retrieval, and answer generation
docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java - Embedding service · Calls the local embedding model and enforces the vector contract
docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java - Document repo · Persistence boundary for storing documents and vector search
docAssist/src/main/java/com/docassist/Rag/repository/DocumentRepository.java - App config · Datasource and Ollama wiring for runtime connections
docAssist/src/main/resources/application.yaml
Local services
External local runtime dependencies
- PostgreSQL · Durable storage and pgvector similarity search
- Ollama · Local inference server for embeddings and chat generation
- nomic-embed-text · 768-dimension embedding model used for documents and queries
- mistral · Local generation model used to produce answers
Database setup
Bootstrap and schema for PostgreSQL + pgvector
- Schema SQL · Creates documents table, vector column, and HNSW index
rag_database_setup/database/schema.sql - Docker compose · Starts PostgreSQL and provisions the local database stack
rag_database_setup/docker/docker-compose.yml
Connections 17
- DocAssist → Doc API: wires · Spring MVC HTTP layer
- DocAssist → Embed API: wires · Additional HTTP endpoints
- Doc API → Document service: delegates · Hands ingestion, search, and QA requests to service logic
- Embed API → Embedding service: delegates · Routes embedding-related requests
- Document service → Embedding service: uses · Generates document and query embeddings
- Document service → Document repo: stores/searches · Persists documents and performs vector retrieval
- Embedding service → Ollama: calls · Uses local model inference for embeddings
- Document service → Ollama: calls · Sends assembled prompts for answer generation
- Document repo → PostgreSQL: queries · Uses pgvector similarity search and document storage
- App config → PostgreSQL: configures · Datasource connection settings
- App config → Ollama: configures · Base URL and model names
- nomic-embed-text → Embedding service: provides · Embedding model integrated through the service boundary
- mistral → Ollama: served by · Chat model hosted locally on Ollama
- Schema SQL → PostgreSQL: provisions · Defines vector-enabled schema and HNSW index
- Docker compose → PostgreSQL: starts · Bootstraps the local PostgreSQL service
- Document service → PostgreSQL: top-k search · Retrieves nearest neighbors for context assembly
- Document service → nomic-embed-text: embeds query · Uses the same 768-dimension embedding contract