Kuwaiti Law RAG Agent
An agentic RAG system over Kuwait's legislation that answers with the exact article and line it relied on.
- Laws inContinuous ingestion
- Structure-aware chunksLaw, article, line
- Recursive clustering9 levels, RAPTOR-style
- Topic nodes + vectorsDenormalized pgvector
- Question inover gRPC
- Pre-filternarrow the corpus
- BM25 + vectortwo retrievers
- RRF fusionone ranked list
- Cited answer2nd LLM call, verbatim
The problem
A legal answer is only useful if someone can check it. A lawyer needs the exact article and line behind a claim, not a confident paraphrase.
It is used by lawyers at an office, who previously searched the statutes by hand.
What I built
A knowledge tree, not a pile of chunks
Structure-aware chunking follows how laws are written. Recursive clustering then builds a RAPTOR-style tree across 9 levels, so broad questions land on topic nodes and narrow ones on single articles.
Hybrid retrieval
Pre-filtering narrows the corpus, then BM25 and vector search run side by side and Reciprocal Rank Fusion merges them. Exact legal terms and loose phrasing both find the right article.
Citations you can verify
Every answer points to the line and article it came from, served over gRPC to the products that use it.
The calls
LangChain over LangGraph.
One decision point per turn. A graph would add state machinery the problem doesn’t need. Simpler was correct, not trendy.
Denormalized pgvector beside normalized Postgres.
The source of truth stays clean. Retrieval reads a flat copy, so there are no joins on the hot path.
A second LLM call just for citations.
A dedicated pass extracts verbatim quotes. It closes the citation gap I found in my own ProofRAG benchmark.