A Chinese Legal Chatbot Assembled from Supabase Parts
It exists to turn a repository of Chinese legal `.mdx` files into an OpenAI-powered Q&A interface.

What it does
This Next.js app ingests Chinese legal documents from the open LawRefBook repository and turns them into searchable vector embeddings. At build time, it slices .mdx statute files into chunks, generates embeddings via the OpenAI API, and stores them in PostgreSQL using pgvector. When you submit a question, the app performs a similarity search, stuffs the relevant legal passages into a GPT-3 completion prompt, and streams the synthesized answer back. It is, by the author’s own account, a domain-specific application of the Supabase nextjs-openai-doc-search starter.
The interesting bit
The build pipeline includes a pragmatic optimization: it generates checksums for each .mdx file and only re-creates embeddings when the underlying legal text actually changes. That is the kind of boring-but-valuable detail that keeps API costs sane when your knowledge base is mostly static. The runtime flow—query embedding, vector search, and completion—runs through Vercel edge functions, making the architecture a neat, if unoriginal, blueprint for grounded Q&A over static corpora.
Key highlights
- Document source is explicitly pinned to the
LawRefBook/Lawsrepository. - Uses
pgvectorinside PostgreSQL for similarity search, avoiding a separate vector database. - Build-time checksums prevent redundant and expensive re-embedding of unchanged statutes.
- Streams GPT-3 completions to the client via server-sent events.
- Vercel deployment integrates with Supabase to auto-provision the database schema.
Verdict A useful reference if you are building retrieval-augmented generation over structured, non-English documents and want to see the plumbing in action. Pass if you need original research or a battle-tested legal tool; the README candidly notes this is a starter-level assembly job.
Frequently asked
- What is lvwzhen/law-cn-ai?
- It exists to turn a repository of Chinese legal `.mdx` files into an OpenAI-powered Q&A interface.
- Is law-cn-ai open source?
- Yes — lvwzhen/law-cn-ai is an open-source project tracked on heatdrop.
- What language is law-cn-ai written in?
- lvwzhen/law-cn-ai is primarily written in MDX.
- How popular is law-cn-ai?
- lvwzhen/law-cn-ai has 4.9k stars on GitHub.
- Where can I find law-cn-ai?
- lvwzhen/law-cn-ai is on GitHub at https://github.com/lvwzhen/law-cn-ai.