A document-grounded Retrieval-Augmented Generation (RAG) platform that combines FastAPI, PostgreSQL + pgvector, Redis, background ingestion, retry handling, vector retrieval, Docker Compose and nginx.
Rather than stopping at a notebook-level RAG demo, this repository separates the API, retrieval/services layer and background ingestion worker. Users can upload PDF, TXT or Markdown documents; the worker chunks and embeds them asynchronously; PostgreSQL/pgvector stores and retrieves vectorised content; Redis supports caching and the ingestion queue; and the question-answering path returns answers grounded in retrieved chunks with source filenames.
If relevant context is not indexed, the API reports that rather than inventing an answer.
- RAG / retrieval: document chunking, embeddings, pgvector similarity retrieval and source-aware answers
- Python backend: FastAPI endpoints for document ingestion, question answering, deletion and health checks
- Data infrastructure: PostgreSQL + pgvector for document/vector storage and Redis for caching/queueing
- Asynchronous processing: background ingestion worker with retry handling when embedding fails
- Deployment architecture: Dockerfile/Docker Compose-based services with nginx as the front/API entry point
- Operational behaviour: Postgres/Redis health checks and explicit handling of unavailable retrieval context
PDF / TXT / Markdown
|
v
FastAPI API
|
+----> document metadata / content ----> PostgreSQL + pgvector
|
+----> ingestion queue ----------------> Redis
|
v
Background Worker
|
chunk + embed + index
|
v
PostgreSQL + pgvector
Question ---> FastAPI ---> retrieve relevant chunks ---> grounded answer
|
+----> Redis cache
Client ---> nginx ---> API
- Upload documents:
POST /documents - Background ingestion with retries if embedding fails
- Ask grounded questions:
POST /ask - Return source filenames with answers
- Delete documents:
DELETE /documents/{id} - Check PostgreSQL and Redis health:
GET /health
cp .env.example .env
# set METIS_API_KEY in .env
docker compose up --buildOpen:
http://localhost— nginx entry pointhttp://localhost:8000— API directly
Answers are generated from retrieved document chunks. When nothing relevant is indexed, the service explicitly says so instead of guessing. This keeps the RAG behaviour inspectable and makes retrieval failure different from generation failure.
FastAPI • RAG • PostgreSQL • pgvector • Redis • Background Workers • Retry Handling • Docker • Docker Compose • nginx • Vector Retrieval