About this project
PolicyDesk
By Uriel Papa · github.com/Edamuza · linkedin.com/in/uriel-papa-vitese01
The problem
HR and payroll teams answer the same questions every week — leave balances, paydays, overtime rules, 13th-month pay. Each answer takes minutes to look up, and a wrong one creates payroll disputes, compliance risk and lost trust.
Generic chatbots make it worse: they answer confidently from general knowledge, not the company's own policy, and give no way to check where an answer came from.
The approach
Retrieval-augmented generation with citations and abstention. Policies are split into heading-aware passages (~400–800 characters) and embedded. A question is embedded too, and the top 4 passages by cosine similarity are retrieved.
If no passage clears a relevance threshold, the app abstains without calling the model. Otherwise the model is instructed to answer only from the numbered passages, cite them as [n], and abstain if they don't contain the answer. Only passages the model actually cited are shown.
An evaluation harness runs a 15-question test set (including 3 out-of-scope questions) through the exact same pipeline. An AI grader checks key facts; citation accuracy and abstention are checked by deterministic rules. Scores are stored per run so changes to chunking, prompts or thresholds can be measured.
Architecture
Browser (React, TanStack Start) │ reads demo data (read-only, row-level security) ▼ Server functions ── Lovable AI Gateway │ • google/gemini-embedding-2 (3072-d vectors) │ • openai/gpt-6-astra (answers + grading) ▼ Lovable Cloud Postgres + pgvector
Tables: documents, chunks (with vector embedding), test_cases, eval_runs, eval_results. Database function: match_chunks (cosine similarity search).
Server functions: askQuestion, addDocument, deleteDocument, resetDemo, startEvalRun, runEvalItem, finishEvalRun. All model calls and writes happen server-side; the browser only has read access.
What I'd do next in a real deployment
- SSO login with role-based access, so documents can be scoped by country, team or employment type.
- Hybrid retrieval (vector + keyword) and a reranker, tuned against a larger, HR-authored test set.
- Document versioning with effective dates, so answers cite the policy in force on a given date.
- Connect PDF/Google Drive sources and the HRIS for personalised answers (e.g. "my" leave balance).
- Feedback buttons and a "hand off to HR" ticket flow; run evaluations in CI on every prompt change.