How it works
A retrieval-augmented assistant (RAG) with the controls a production AI system needs: guardrails, verified citations, cost limits, an audit log and a quality gate.
What happens when you ask
- Clean and mask. Emails, phone numbers, Aadhaar, PAN and card numbers (Luhn-checked) are replaced with placeholders. Only the masked text goes any further.
- Guardrail. Obvious attempts to change the assistant's instructions are refused without calling the model.
- Limits. Per-visitor rate limits at two layers (the web server and the API), plus a daily cap on model calls, so a busy day can't exhaust the free API quota.
- Search. An open embedding model running on this server finds the most relevant passages across the sites (at most two per page, for variety). If nothing is relevant enough, you get an honest “not on these sites” and no model call is made.
- Answer. The passages are sent to Gemini, fenced as data, with instructions to use only them and to return a fixed JSON shape: answer, citations, answerable. The fast model goes first; a stronger one is the fallback.
- Verify. Every citation must point to a passage that was actually provided. An answer that cites nothing valid is replaced with “not found”. No unsupported answers get through.
- Log. Outcome, timings, tokens and sources go to the audit log, which feeds the stats page.
Keeping the knowledge fresh and correct
- Every 24 hours the public pages are re-read from the sites' sitemaps, split into passages and embedded locally.
- Each new index is tested before it goes live against a fixed set of questions with known right pages. If it scores below the bar, or worse than the current index, it's rejected and the current one stays.
Architecture
| Part | Choice | Why |
|---|---|---|
| Embeddings | EmbeddingGemma, running on this server | No per-request cost or quota; the search step never leaves the server |
| Vector store | Postgres + pgvector (HNSW index) | One database for vectors, audit log and cache; no extra service |
| Answer model | Gemini Flash-Lite, falling back to Gemini Flash | Measured about 2 s vs 7–18 s; the fallback covers outages |
| Model access | One gateway module | Model choice, timeouts, fallback and token accounting in one place; changing provider touches one file |
| Network | Database on an internal network with no internet; only the API can reach out | Smallest possible exposure |
| Secrets | Mounted by Docker from outside the code repository | Nothing sensitive in Git |
Privacy
- The assistant only reads public pages on these sites.
- Personal details you type are masked before anything is sent or stored.
- Your masked question and the relevant passages are sent to Google's Gemini API to write the answer. On the free tier, Google may use this to improve its services, so please don't type anything private.
- The audit log keeps the masked question, outcome and timings for 30 days, then deletes them. It stores no IP address: only a one-way hash with a key that changes daily, used for rate limiting.
- Questions are never written to web server logs, and there are no cookies or trackers on this site.