[ TRACE · LEXINSIGHT ]
Legal RAG over Philippine law — dual-mode chat, live in beta.
Full-stack — RAG core, realtime chat, database architecture|In progress (beta)
[ THE PROBLEM ]
Philippine legal knowledge sits behind expensive consultations. Individuals, small businesses, and student organizations navigate compliance requirements blind — the documents are public, but reading them like a lawyer isn't.
LexInSight is a legal assistant over Philippine law: ask in plain language, get answers grounded in retrieved statute text — with a compliance mode that checks documents you upload against the requirements that apply to them.
[ HOW IT WORKS ]
[ SPAN · RETRIEVAL PIPELINE ]
Queryplain language
Embedquery vector
Retrievepgvector · RLS-scoped
Generategrounded answer
Streamrealtime channel
- Every retrieval is scoped by Postgres Row Level Security — tenant isolation lives in the database, not in application code.
- Compliance mode checks up to three uploaded documents (5MB each) against retrieved Philippine legal requirements.
Next.js App Router front to back in TypeScript. Supabase provides Postgres, auth, and realtime; documents are chunked and embedded into pgvector, so rows, vectors, and access policies live in one database.
Chat runs in two modes: general legal Q&A, and a compliance mode that accepts up to three uploaded documents (5MB each) and checks them against retrieved Philippine legal requirements. Answers stream over a realtime channel.

[ TRADE-OFFS I MADE ]
01
pgvector inside Postgres, not a dedicated vector database
Keeping vectors next to relational rows means Row Level Security covers retrieval too, and there's one backup, one connection pool, one source of truth. The cost is raw similarity-search performance at scale — acceptable for a corpus of statutes; revisit if the corpus grows by orders of magnitude.
02
Tenant isolation in the database, not the app layer
RLS policies mean a leaked query can't cross tenants even if application code has a bug. The cost: policies are harder to write and debug than `where` clauses, and every new table needs its policy thought through.
03
Two modes, one retrieval pipeline
General legal Q&A and compliance document-checking share the same retrieval stack instead of living as separate tools — one corpus, one ranking path to maintain. The cost is prompting that has to adapt per mode, and a single pipeline whose failures affect both surfaces.
[ WHAT BROKE ]
INCIDENT NOTE · PENDING
Every system here has broken at least once. This section gets written from the engineer's incident notes, not generated — the honest version is coming.
[ RESULTS ]
- public beta — lexinsights.vercel.app
- Live
- chat modes — general & compliance
- 2
- documents checked per compliance run
- 3×5MB
[ STACK ]
- Next.js
- TypeScript
- Supabase
- PostgreSQL
- pgvector
- RLS
- Realtime
- Zustand
- Tailwind CSS