InsightHub RAG
completed
30-second summary
InsightHub is a local RAG notebook: upload .txt, .md or .pdf files, ingest them asynchronously, ask questions and review citations. Duy wrote the whole implementation, including the DevOps, security, observability and cost-tracking layers, on a repository supplied by the instructor.
Turn raw files into structured, traceable knowledge: each answer must trace back to a chunk and its source document, and the database must prevent invalid states, for example a document marked ready without stored vectors.
Wrote the whole implementation on the instructor's repository.
Verified — InsightHub has a public GitHub repository owned by Duy (an implementation built from the instructor's repository). Existence of the public repository
Context and problem
An implementation built from the instructor's repository: the instructor supplied the starting repository and Duy wrote the implementation. Language models answer better about new documents when relevant passages are retrieved and supplied as context, and RAG also allows citing sources.
Turn raw files into structured, traceable knowledge: each answer must trace back to a chunk and its source document, and the database must prevent invalid states, for example a document marked ready without stored vectors.
Individual role
Wrote the whole implementation on the instructor's repository.
The web, API and ingestion worker; the PostgreSQL plus pgvector data model; Terraform and Helm, GitHub Actions and Checkov for the local path; guardrails on input, context and output; Prometheus and Grafana monitoring; a chat-ops bot; per-workflow budget keys.
Duy wrote the implementation; the original repository was provided by the instructor.
Constraints
Everything runs locally (Docker Desktop Kubernetes, Ollama on the host); no AWS runtime was executed and nothing was applied to a cloud. The embedding model's 512-token context limited chunk size. The project was a seven-day piece of work.
Architecture
Next.js web, FastAPI, a Redis/ARQ queue, a separate ingestion worker and PostgreSQL 16 with pgvector. Upload returns HTTP 202 after enqueueing; the worker chunks, embeds and stores with bounded retry and idempotent replay. Chat retrieves context, goes through LiteLLM to a local Ollama model, and validates structured output and citations; guardrails on input, context and output fail closed. Data model: documents, chunks (text plus a 1024-dimension vector) and an embedding identity table; a B-tree index on status and an HNSW index on vectors; cosine-distance search. Monitoring with Prometheus and Grafana.
Decisions and alternatives
Integrity rules live in the schema, not only in the application: keys, a CHECK that a ready document has chunks, unique chunk order, cascading deletes and a fixed vector size. Ingestion is one transaction with row locking; an embedding failure rolls back to failed instead of a fake ready. Vectors from different models are never mixed, guarded by the embedding identity table. Citations derive from retrieval results rather than a separate table. Three LiteLLM virtual keys with a maximum budget attribute spend per workflow.
LLM-only answering versus RAG, where retrieval supplies context and citations.
Implementation
Terraform and Helm with pinned versions, policies, Checkov and GitHub Actions for the local and static path, plus opt-in protected OIDC AWS jobs that were never applied. MCP with four pinned backends and read-only access. Security work: input, context and output guards, prompt-leak and poisoning handling, Promptfoo. Layout: web, api, ingestion-worker, chatops-bot, infra, observability, security, finops, tests.
Validation
End-to-end local check: upload HTTP 202, ingestion ready, embedding HTTP 200 (1024 dimensions), RAG HTTP 200, citations verified; this is not a general accuracy benchmark, and the repository makes no claim of passing every security test.
Results and evidence
A real incident was fixed: embedding requests failed with HTTP 400 because chunks exceeded the model's 512-token context. Reducing the conservative chunk budget from 800 to 400 let three failed documents be reprocessed to ready (124 chunks each) without losing IDs or payload, with the same model and data. The local runtime works; the AWS runtime was not executed. Answer quality: not measured. Local model cost is zero.
Verified — InsightHub has a public GitHub repository owned by Duy (an implementation built from the instructor's repository). Existence of the public repository
Limits and lessons — If I did it again
A useful RAG starts with organised, traceable data: structure (keys and identities), discipline (states, transactions, constraints) and verifiability (retrieve and cite). Do not replace database volumes or the embedding identity on restart. Historical failures are kept visible rather than hidden, and the repository makes no claim of passing every security test, AWS deployment or production readiness.