# rahullbs/rag-assist architecture

> Architecture diagram of the GitHub repository rahullbs/rag-assist, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahullbs/rag-assist
- Repository: https://github.com/rahullbs/rag-assist

## Overview

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: [`docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java`](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java) (Document service), [`docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java`](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java) (Embedding service), [`docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java`](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java) (DocAssist), [`docAssist/src/main/resources/application.yaml`](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/resources/application.yaml) (App config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Spring Boot app"]
  node_docassist_app(("DocAssist<br/>boot app"))
  node_doc_controller["Doc API<br/>controller"]
  node_embed_controller["Embed API<br/>controller"]
  node_doc_service["Document service"]
  node_embed_service["Embedding service"]
  node_doc_repo[("Document repo")]
  node_app_yaml["App config<br/>[application.yaml]"]
end

subgraph group_infra["Local services"]
  node_postgres[("PostgreSQL<br/>vector db")]
  node_ollama["Ollama<br/>model server"]
  node_embed_model(("nomic-embed-text<br/>embedding model"))
  node_gen_model(("mistral<br/>chat model"))
end

subgraph group_setup["Database setup"]
  node_schema_sql["Schema SQL<br/>bootstrap sql<br/>[schema.sql]"]
  node_docker_compose["Docker compose<br/>infra compose<br/>[docker-compose.yml]"]
end

node_docassist_app -->|"wires"| node_doc_controller
node_docassist_app -->|"wires"| node_embed_controller
node_doc_controller -->|"delegates"| node_doc_service
node_embed_controller -->|"delegates"| node_embed_service
node_doc_service -->|"uses"| node_embed_service
node_doc_service -->|"stores/searches"| node_doc_repo
node_embed_service -->|"calls"| node_ollama
node_doc_service -->|"calls"| node_ollama
node_doc_repo -->|"queries"| node_postgres
node_app_yaml -.->|"configures"| node_postgres
node_app_yaml -.->|"configures"| node_ollama
node_embed_model -.->|"provides"| node_embed_service
node_gen_model -.->|"served by"| node_ollama
node_schema_sql -->|"provisions"| node_postgres
node_docker_compose -->|"starts"| node_postgres
node_doc_service -->|"top-k search"| node_postgres
node_doc_service -->|"embeds query"| node_embed_model

click node_docassist_app "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java"
click node_doc_controller "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/controller/DocumentController.java"
click node_embed_controller "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/controller/EmbeddingController.java"
click node_doc_service "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java"
click node_embed_service "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java"
click node_doc_repo "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/repository/DocumentRepository.java"
click node_app_yaml "https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/resources/application.yaml"
click node_schema_sql "https://github.com/rahullbs/rag-assist/blob/main/rag_database_setup/database/schema.sql"
click node_docker_compose "https://github.com/rahullbs/rag-assist/blob/main/rag_database_setup/docker/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_docassist_app,node_doc_controller,node_embed_controller,node_doc_service,node_embed_service,node_doc_repo,node_app_yaml toneBlue
class node_postgres,node_ollama,node_embed_model,node_gen_model toneAmber
class node_schema_sql,node_docker_compose toneMint
```

## Components

### Spring Boot app

Main Java 17 application and runtime layers

- [DocAssist](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java): boot app · Spring Boot entrypoint for the RAG service · `docAssist/src/main/java/com/docassist/Rag/DocAssistApplication.java`
- [Doc API](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/controller/DocumentController.java): controller · HTTP endpoints for document ingestion and RAG requests · `docAssist/src/main/java/com/docassist/Rag/controller/DocumentController.java`
- [Embed API](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/controller/EmbeddingController.java): controller · HTTP endpoints related to embeddings or diagnostics · `docAssist/src/main/java/com/docassist/Rag/controller/EmbeddingController.java`
- [Document service](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java): service · Orchestrates ingestion, retrieval, and answer generation · `docAssist/src/main/java/com/docassist/Rag/Service/DocumentService.java`
- [Embedding service](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java): service · Calls the local embedding model and enforces the vector contract · `docAssist/src/main/java/com/docassist/Rag/Service/EmbeddingService.java`
- [Document repo](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/java/com/docassist/Rag/repository/DocumentRepository.java): repository · Persistence boundary for storing documents and vector search · `docAssist/src/main/java/com/docassist/Rag/repository/DocumentRepository.java`
- [App config](https://github.com/rahullbs/rag-assist/blob/main/docAssist/src/main/resources/application.yaml): config · Datasource and Ollama wiring for runtime connections · `docAssist/src/main/resources/application.yaml`

### Local services

External local runtime dependencies

- **PostgreSQL**: vector db · Durable storage and pgvector similarity search
- **Ollama**: model server · Local inference server for embeddings and chat generation
- **nomic-embed-text**: embedding model · 768-dimension embedding model used for documents and queries
- **mistral**: chat model · Local generation model used to produce answers

### Database setup

Bootstrap and schema for PostgreSQL + pgvector

- [Schema SQL](https://github.com/rahullbs/rag-assist/blob/main/rag_database_setup/database/schema.sql): bootstrap sql · Creates documents table, vector column, and HNSW index · `rag_database_setup/database/schema.sql`
- [Docker compose](https://github.com/rahullbs/rag-assist/blob/main/rag_database_setup/docker/docker-compose.yml): infra compose · Starts PostgreSQL and provisions the local database stack · `rag_database_setup/docker/docker-compose.yml`

## Connections

- 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
