How premjituri/local-rag-chat works
Purpose and topology
Local RAG chat application: users upload PDF, DOCX, or TXT files, then receive answers grounded only in indexed document content. A React SPA calls a Spring Boot REST API, which uses local Ollama for embeddings/chat generation and ChromaDB for vector persistence/search. Container orchestration is in docker-compose.yml and docker-compose.chroma.yml.
Entry points and API boundary
Backend startup is backend/src/main/java/com/ragsystem/rag/RagBackendApplication.java. HTTP endpoints are split by workflow:
• Upload: backend/src/main/java/com/ragsystem/rag/controller/UploadController.java
• Question answering: backend/src/main/java/com/ragsystem/rag/controller/AskController.java
• Indexed-data readiness: backend/src/main/java/com/ragsystem/rag/controller/StatusController.java
DTOs isolate API contracts from services, including backend/src/main/java/com/ragsystem/rag/dto/AskRequest.java and backend/src/main/java/com/ragsystem/rag/dto/AskResponse.java.
Document ingestion pipeline
UploadController delegates to backend/src/main/java/com/ragsystem/rag/service/UploadService.java, which validates and persists raw uploads, extracts readable text through backend/src/main/java/com/ragsystem/rag/service/DocumentParserService.java, and passes it to backend/src/main/java/com/ragsystem/rag/service/ChunkService.java. Chunks are overlapping text segments represented by backend/src/main/java/com/ragsystem/rag/model/Chunk.java.
backend/src/main/java/com/ragsystem/rag/service/VectorStoreService.java embeds chunks through Ollama/Spring AI and writes them with metadata into ChromaDB. This is the boundary between local file handling/parsing and durable semantic indexing.
Retrieval and generation pipeline
backend/src/main/java/com/ragsystem/rag/service/AskService.java enforces upload-first behavior, retrieves top-K similar chunks through VectorStoreService, and avoids generation when no useful context is found. It sends the grounded context and user question to backend/src/main/java/com/ragsystem/rag/service/ChatService.java, which owns LLM interaction and returns the answer. The key control boundary is retrieval before generation: Chroma results determine whether Ollama’s chat model is called.
Backend integration and lifecycle
Spring AI client wiring is centralized in backend/src/main/java/com/ragsystem/rag/config/ChatClientConfig.java. Chroma tenant/database/collection provisioning and ordering are handled by backend/src/main/java/com/ragsystem/rag/config/ChromaSchemaInitializer.java and backend/src/main/java/com/ragsystem/rag/config/ChromaSchemaOrderingConfig.java; the collection uses cosine similarity. Runtime settings, including chunking, retrieval count, storage, AI endpoints/models, and upload limits, are in backend/src/main/resources/application.yml.
Cross-origin access is controlled by backend/src/main/java/com/ragsystem/rag/config/CorsConfig.java. API failures become structured HTTP responses through backend/src/main/java/com/ragsystem/rag/exception/GlobalExceptionHandler.java.
Frontend application flow
The SPA boots at frontend/src/main.jsx and renders the RAG screen from frontend/src/pages/RagChatPage.jsx. frontend/src/components/DocumentUpload.jsx uploads documents; frontend/src/components/ChatBox.jsx submits questions; frontend/src/components/AnswerSection.jsx displays generated answers. On load, the UI checks readiness via frontend/src/services/statusService.js, preserving ask availability when Chroma data already exists.
Frontend-to-backend calls are centralized in frontend/src/services/apiClient.js, with workflow-specific clients in frontend/src/services/uploadService.js and frontend/src/services/askService.js. Development proxying is configured by frontend/vite.config.js; production serving is supported by frontend/nginx.conf.
Runtime infrastructure
Required local services are Ollama (port 11434) with embedding and chat models, ChromaDB (port 8000) with on-disk vector data, the Java 21 backend (8080), and React/Vite frontend (5173 in development). Docker definitions are backend/Dockerfile, frontend/Dockerfile, and docker-compose.yml; Ollama remains a host-provided runtime in the documented container deployment.
Components 18
React SPA
- SPA bootstrap
frontend/src/main.jsx - RAG chat screen · Coordinates upload, readiness, and question workflows.
frontend/src/pages/RagChatPage.jsx - Document upload UI
frontend/src/components/DocumentUpload.jsx - Question UI
frontend/src/components/ChatBox.jsx - API clients · Central client plus upload, ask, and status workflow calls.
frontend/src/services/apiClient.js
Spring Boot API
- Backend application
backend/src/main/java/com/ragsystem/rag/RagBackendApplication.java - Upload API
backend/src/main/java/com/ragsystem/rag/controller/UploadController.java - Ask API
backend/src/main/java/com/ragsystem/rag/controller/AskController.java - Readiness API
backend/src/main/java/com/ragsystem/rag/controller/StatusController.java
Document ingestion
- Upload service · Validates and persists uploads before parsing.
backend/src/main/java/com/ragsystem/rag/service/UploadService.java - Document parser · Reads PDF, DOCX, and TXT content.
backend/src/main/java/com/ragsystem/rag/service/DocumentParserService.java - Chunk service · Creates overlapping Chunk segments.
backend/src/main/java/com/ragsystem/rag/service/ChunkService.java
Retrieval & generation
- Vector store service · Embeds chunks and retrieves top-K semantic matches.
backend/src/main/java/com/ragsystem/rag/service/VectorStoreService.java - Ask service · Requires indexed context before allowing generation.
backend/src/main/java/com/ragsystem/rag/service/AskService.java - Chat service · Generates grounded answers from retrieved context.
backend/src/main/java/com/ragsystem/rag/service/ChatService.java
Local runtime
- ChromaDB · Persists cosine-similarity document embeddings.
- Ollama · Provides embedding and chat models.
- Container orchestration · Runs frontend, backend, and Chroma; Ollama is host-provided.
docker-compose.yml
Connections 24
- SPA bootstrap → RAG chat screen: renders
- RAG chat screen → Document upload UI: uses
- RAG chat screen → Question UI: uses
- Document upload UI → API clients: uploads via
- Question UI → API clients: asks via
- RAG chat screen → API clients: checks readiness
- API clients → Upload API: upload HTTP
- API clients → Ask API: ask HTTP
- API clients → Readiness API: status HTTP
- Backend application → Upload API: hosts
- Backend application → Ask API: hosts
- Backend application → Readiness API: hosts
- Upload API → Upload service: delegates
- Upload service → Document parser: extracts text
- Document parser → Chunk service: parsed text
- Chunk service → Vector store service: chunks
- Vector store service → Ollama: embeddings
- Vector store service → ChromaDB: writes and searches
- Ask API → Ask service: delegates
- Ask service → Vector store service: retrieves context
- Ask service → Chat service: context found only · No useful retrieval skips generation.
- Chat service → Ollama: grounded chat
- Container orchestration → Backend application: runs
- Container orchestration → ChromaDB: runs