- 2-layerTenant isolation · Postgres RLS
- 5Pluggable model protocols
- 12Architecture decisions documented
- 0-setupIn-process tracing dashboard
ForgeDocs AI
Production-grade agentic document intelligence — the flagship
project here, and the clearest picture of how I build AI systems.
Upload documents, extract structured data, and answer hard questions
over them with inline [n] citations that resolve to
document_id + page + char span. Grounding first: hybrid
retrieval (pgvector dense + Postgres BM25 fused with RRF),
a LangGraph Planner → Retriever → Synthesizer → Verifier
loop that refuses ungrounded answers, and honest abstention instead of
hallucination. Hardened like a service, not a demo: two-layer
multi-tenant isolation enforced by Postgres Row-Level
Security under a dedicated NOBYPASSRLS role,
tenant identity from a verified Supabase JWT, and an always-on eval
harness (faithfulness, citation validity, abstention) as an offline CI
floor. Every component — ChatModel, Embedder,
Reranker, OCRBackend, Tracer — is
a swappable protocol with local-first defaults, so CI runs fully
offline. Observability is built in: every step is a tracing span behind
a zero-setup GET /traces dashboard. Twelve architecture
decisions are written down with trade-offs.
Architecture
POST /ingest · PDF · text · md · image / scanned PDF
│
▼
ingestion: load → OCR (none|tesseract|vision) → structure-aware
chunk (~512 tok, ~15% overlap) → embed → index
· per-tenant dedupe: UNIQUE (tenant_id, sha256)
│
▼
┌───────────────────────────────────────────────┐
│ Postgres + pgvector (Supabase) │
│ · dense (cosine) + lexical (FTS / BM25) │
│ · Row-Level Security, GUC app.current_tenant │
│ · NOBYPASSRLS role · NULL tenant → 0 rows │
└───────────────────────┬───────────────────────┘
│ POST /query · /query/stream (SSE)
▼
retrieval: dense ∪ lexical → RRF (k=60) → rerank?
│
▼
agents (LangGraph): Planner → Retriever
→ Synthesizer → Verifier ⟲ self-correct
│ refuses ungrounded answers
▼
answer + [n] citations → document_id · page · span
│ │
▼ ▼
GET /traces (every step a span) eval harness:
in-proc recorder | Langfuse faithfulness ·
citation validity ·
abstention → CI floor