A production-oriented retrieval-augmented generation project built with Java, Spring Boot, n8n, PostgreSQL/pgvector, MongoDB, and Redis. It runs without an API key in local mode and can use a local Ollama model for generated, citation-aware answers.
- Ingests text through the REST API, dashboard, or an n8n webhook.
- Splits documents into overlapping chunks and creates deterministic 384-dimensional embeddings.
- Retrieves the closest chunks in memory for a zero-setup demo or from PostgreSQL with pgvector in production.
- Produces keyless extractive answers, with optional Ollama generation.
- Caches repeat questions in Redis and invalidates them when the knowledge base changes.
- Stores query and ingestion audit events in MongoDB.
- Exposes health, metrics, and service status endpoints.
- Builds and tests every change with GitHub Actions, then publishes the application image to GHCR.
flowchart LR
User[Dashboard or API client] --> API[Spring Boot RAG API]
Automation[n8n webhook] --> API
API --> Chunk[Chunk and embed]
Chunk --> PG[(PostgreSQL + pgvector)]
API <--> Redis[(Redis query cache)]
API --> Mongo[(MongoDB audit log)]
API -. optional .-> Ollama[Ollama chat model]
Actions[GitHub Actions] --> Tests[Tests and image build]
Actions --> GHCR[GitHub Container Registry]
| Component | Responsibility |
|---|---|
| Spring Boot | REST API, validation, retrieval, answer orchestration, dashboard |
| PostgreSQL + pgvector | Documents, chunks, vector similarity search |
| MongoDB | Append-only ingestion and query audit events |
| Redis | Time-limited query response cache |
| n8n | Validated document-ingestion webhook automation |
| Ollama | Optional local answer generation; no cloud key required |
Local mode needs only Java 21. It keeps vectors, cache entries, and audit events in memory.
.\mvnw.cmd spring-boot:runOpen http://localhost:8080, or run the automated smoke test in a second PowerShell window:
.\scripts\smoke-test.ps1Install Docker Desktop, then:
Copy-Item .env.example .env
# Change the example passwords and encryption key in .env.
docker compose up --buildThe services are:
- Dashboard and API: http://localhost:8080
- n8n: http://localhost:5678
- Spring health: http://localhost:8080/actuator/health
The compose stack imports and activates RAG - Document Ingestion Webhook. After creating the first n8n owner account, call its production webhook:
$body = @{
title = "Support handbook"
source = "n8n-webhook"
content = "Priority one incidents require an acknowledgement within fifteen minutes."
} | ConvertTo-Json
Invoke-RestMethod `
-Method Post `
-Uri http://localhost:5678/webhook/knowledge-ingest `
-ContentType application/json `
-Body $bodyThe default answer provider quotes the best matching passages and needs no model download. To generate a composed answer, install Ollama, pull a model, and set this in .env:
ollama pull llama3.2:3bANSWER_PROVIDER=ollama
OLLAMA_BASE_URL=http://host.docker.internal:11434
OLLAMA_CHAT_MODEL=llama3.2:3bRestart the application service after changing the values:
docker compose up -d --build appPOST /api/v1/documents
{
"title": "Incident handbook",
"source": "internal-runbook",
"content": "When Redis is unavailable, restart the service and verify connectivity."
}POST /api/v1/query
{
"question": "How should Redis be recovered?",
"topK": 4,
"conversationId": "incident-42"
}The response contains the answer, similarity-ranked source chunks, their scores, a cache flag, and a conversation ID.
GET /api/v1/status
The endpoint reports the document count and active vector, cache, audit, and answer providers.
| Variable | Default | Purpose |
|---|---|---|
SPRING_PROFILES_ACTIVE |
default local profile | Use production for the database-backed stack |
ANSWER_PROVIDER |
extractive |
Set to ollama for generated answers |
OLLAMA_BASE_URL |
http://localhost:11434 |
Ollama API address |
OLLAMA_CHAT_MODEL |
llama3.2:3b |
Ollama chat model |
POSTGRES_* |
development values | PostgreSQL connection and initialization |
MONGODB_URI |
local development URI | MongoDB audit database |
REDIS_PASSWORD |
ragredis |
Redis authentication |
See .env.example for the complete deployment template.
Run all tests and create the executable JAR:
.\mvnw.cmd verifyThe project includes tests for chunk overlap, normalized embeddings, ingestion, retrieval, cache behavior, API status, and validation. CI also validates the Compose file and builds the container image.
Every push to main runs CI and publishes:
ghcr.io/javaprogswing/rag-n8n-spring-platform:latest
Pull that image into any Docker or Kubernetes environment and provide the same production environment variables shown in compose.yml.
Released under the MIT License.