Ingestion
Validate the PDF, calculate SHA-256, establish the PostgreSQL lifecycle record and store the source atomically.
GenAI · RAG · AI Systems Engineering
Production-style evidence intelligence and policy RAG system.
A production-style evidence intelligence and policy RAG system with traceable citations, calibrated answerability, measurable evaluation and release-like operations.
Enterprise policy answers need to be traceable to the documents that support them. Retrieval similarity alone cannot establish that a passage directly answers a question, and weak evidence must not produce speculative prose.
The system also needs to keep provider outages distinct from unsupported questions. Reviewers must be able to inspect document lifecycle state, page-level evidence, evaluation results and operational readiness instead of trusting an opaque chat response.
PolicyGPT validates and registers policy PDFs with persistent identity, extracts page-aware text, creates metadata-rich chunks and indexes retrievable evidence in ChromaDB. Every question passes through an answerability gate before optional generation.
Supported results attach page-level citations and interpretable confidence diagnostics. Missing evidence produces a controlled unsupported response, while provider failure preserves answer-ready evidence through citation-only fallback. Evaluation artifacts and readiness views make quality and operational state inspectable.
I built PolicyGPT as an independent local engineering project for policy owners and reviewers who need to verify an answer against its source. The demo uses a fictional HR handbook.
| Reliability need | PolicyGPT Enterprise contract |
|---|---|
| Durable document identity | PostgreSQL UUID, lifecycle record and SHA-256 identity |
| Evidence decision | Answerability assessment before optional generation |
| Reviewable provenance | Document, page, section, chunk and excerpt |
| Unsupported questions | Controlled rejection with no unsupported generation |
| Provider failure | Citation-only evidence with explicit degraded state |
| Evaluation | Versioned 24-case holdout with case-level outcomes |
| Operations | Migrations, liveness, readiness, request IDs and release verification |
| Milestone | Delivered |
|---|---|
| Document ingestion | Validated PDFs, deduplicated by SHA-256, and tracked indexing state in PostgreSQL. |
| Retrieval and answer gating | Indexed page-aware evidence in ChromaDB and assessed direct support before deciding whether to generate. |
| Evidence review | Built the Next.js console to show cited passages, refusal reasons, and confidence diagnostics. |
| Reliability and evaluation | Added citation-only fallback for provider outages, Compose health checks, and read-only views over saved benchmark results. |
Primary skills demonstrated:
Architecture Flow
Bounded PDF checks, SHA-256 identity, PostgreSQL lifecycle and safe source storage
Page-aware cleaning with document, page, section and chunk metadata
Local SentenceTransformer embeddings persisted in ChromaDB
Candidate passages returned with page-level provenance and retrieval diagnostics
Evidence decision runs before optional provider generation
Citations, safe fallback, evaluation artifacts, request IDs and readiness state
The ownership boundaries are explicit: PostgreSQL owns identity and lifecycle, source storage owns original PDFs, ChromaDB owns retrievable evidence, and the evaluation workflow owns completed benchmark artifacts.
Validate the PDF, calculate SHA-256, establish the PostgreSQL lifecycle record and store the source atomically.
Extract and clean page-aware text, create metadata-rich chunks, embed locally and persist records in ChromaDB.
Embed the question and retrieve candidate passages with document, page, section, chunk and score metadata.
Combine retrieval strength with coverage, numeric consistency, direct support and scope-risk checks.
Call the optional provider only when the evidence gate permits it; otherwise preserve a safe outcome.
Return reviewable excerpts with document, page, section and retrieval diagnostics alongside the result.
Similarity is an engineering signal used inside this workflow. It is not a probability that an answer is correct.
Synchronous ingestion keeps lifecycle progress inspectable in the verified local release profile. The system validates the file and establishes durable identity before extraction or embedding work begins.
Controlled ingestion workflow
PostgreSQL is the source of truth for safe document identity and lifecycle metadata:
Persistent document registry
PostgreSQL
Identity, lifecycle, counts and safe operational metadata.
Source storage
Original PDF assets stored separately under generated keys.
ChromaDB
Page-aware chunks, metadata and vector evidence.
Source files and vector evidence remain separate persisted assets. Together with PostgreSQL they form one logical ingestion record, so a future backup must coordinate all three.
Document lifecycle detail
Page-level evidence is the primary review object. Generated prose is useful only after the system has established direct support.
Citation 1
Page 5
3. Remote and Hybrid Work
Employees approved for remote work must maintain a safe, private and reliable workspace. Approved ergonomic or productivity items may be reimbursed up to CAD 300 with receipts and prior approval.
Retrieval score
0.6217
A retrieval input—not guaranteed certainty.
The evidence view exposes the factors behind the answerability decision alongside the retrieved passages, so a reviewer can inspect both support quality and provenance.
Evidence and answerability diagnostics
The same retrieval path can produce three intentionally different outcomes:
Generate an evidence-bound answer and attach page-level citations and diagnostics.
Return citation-only evidence and identify the provider failure without calling the question unsupported.
Block generation and return a controlled unsupported response instead of speculative prose.
This separation prevents weak evidence and provider outages from collapsing into the same ambiguous “no answer” state.
Unsupported-answer guardrail
Confidence is an interpretable answerability signal—not guaranteed certainty, an LLM self-rating or a claim that the generated answer is correct.
It is informed by:
The final decision uses these diagnostics to explain why evidence was accepted or rejected. A high similarity score alone cannot override numeric contradictions, missing direct support or an external-authority question outside the indexed documents.
Confidence scoring
| Measure | Saved local run |
|---|---|
| Benchmark cases passed | 23/24 |
| Correct refusals | 4/4 |
| Request errors | 0 |
| Expected-page retrieval and answer-readiness accuracy | 100% each |
| Generated answers returned for answer-ready cases | 20/20 |
The one scored miss came from the keyword checker expecting “locked” when the generated answer said “lock.” The saved run retains that failure. This controlled holdout uses one fictional handbook and measures behavior on those 24 cases.
Final evaluation dashboard
The Evaluation console reads saved JSON and CSV artifacts. A previous provider-disabled run exercised citation-only fallback independently of this generated-answer holdout.
The v0.3.0 baseline is release-like local orchestration, not a production deployment.
Architecture Flow
Database health gate passes
Schema authority exits successfully
PostgreSQL and Chroma readiness checks pass
The server-side BFF confirms backend readiness
The local release profile includes:
The optional generation provider does not gate readiness because retrieval and citation review remain useful in citation-only mode.
System readiness
The Next.js enterprise console is organized around four product areas:
Upload PDFs, inspect registry records, lifecycle state, duplicate handling and document details.
Compose a policy question and review answerability, answer state, evidence, citations and diagnostics.
Inspect the latest validated benchmark, case outcomes, confidence factors and provider reliability.
Review frontend, backend, PostgreSQL, Chroma and optional-provider readiness without exposing internal URLs.
The interface distinguishes processing, ready, failed, unsupported, provider unavailable and dependency unavailable states. This prevents a loading state, ingestion failure, evidence rejection and optional-provider outage from appearing equivalent.
Built
Planned
The verified repository baseline includes:
230
Backend tests
128
Frontend tests
23/24
Final holdout cases passed
Passed
Frontend lint
Passed
Production build
Verified
Docker Compose health and release workflow
Validation also covers dataset schema, duplicate-upload behaviour, provider fallback, non-root images, health-gated startup, persistence across a safe Compose restart, smoke testing and release verification.
These are repository validation facts. They are not customer metrics, production usage, a service-level claim or proof of commercial adoption.
Challenge
Solution
Keep extraction and cleanup page-aware so document, page, section and chunk identity survive indexing.
Challenge
Solution
Hash the complete file and enforce PostgreSQL uniqueness before extraction and vector writes.
Challenge
Solution
Persist visible lifecycle stages, compensate for incomplete work and expose safe failure details.
Challenge
Solution
Add lexical, numeric, direct-support and scope-risk checks rather than treating one vector score as truth.
Challenge
Solution
Retry transient failures, then return citation-only evidence without hiding valid retrieval.
Challenge
Solution
Assign identity to PostgreSQL, sources to file storage, evidence to Chroma and results to evaluation storage.
Challenge
Solution
Gate migrations, backend readiness and frontend readiness in explicit order while keeping liveness lightweight.
Generation is optional and runs only after retrieved evidence passes the answerability decision. This keeps weak evidence from becoming fluent but unsupported prose.
Document identity, lifecycle and operational metadata have different responsibilities from vector retrieval evidence. Keeping those ownership boundaries explicit makes ingestion state, duplicate prevention and recovery easier to reason about.
A provider outage does not erase valid retrieved evidence. When evidence remains answer-ready, citation-only fallback preserves a useful and honest result instead of misclassifying the question as unsupported.
The confidence signal is derived from observable retrieval and evidence diagnostics, including strength, coverage, numeric consistency, direct support and scope risk. It does not ask a language model to grade its own answer.
PolicyGPT Enterprise is not a finished production platform. Current limitations are intentionally visible:
Additional production work would require TLS termination, retention and governance controls, recovery testing, broader domain validation and formal security review.
The next work is ordered by risk and operational dependency:
Agentic orchestration comes after identity, evaluation, observability and recovery controls—not before them.
I designed and implemented PolicyGPT Enterprise end to end. The project demonstrates production-style RAG architecture, evidence gating, page-level citation provenance, PostgreSQL and vector-store coordination, interpretable confidence diagnostics, safe unsupported and provider-failure fallbacks, versioned evaluation design, request-level observability and Docker Compose deployment engineering.
The strongest engineering result is the explicit system boundary: it is a verified local release profile with inspectable evidence and evaluation—not a commercial SaaS product, a cloud production deployment or proof of real-company adoption.
Inspect the implementation
Inspect the source code, evaluation framework, operational documentation and verified local release workflow.