Inspiration
In Bangladesh, land-related problems can become extremely complicated. Many citizens know that they have legal rights, but they often don't know which law applies, which section protects them, or what procedure they need to follow.
Understanding land law can require navigating lengthy legal documents, unfamiliar terminology, government procedures, and sometimes expensive professional assistance. This creates a gap between having rights and understanding how to exercise those rights.
We built TerraLaw BD to address this problem.
Our inspiration was simple: What if an ordinary citizen could ask a land-law question in plain language and immediately understand what the relevant law says, with the exact Act and Section to verify it?
TerraLaw is designed to improve bureaucratic and legal literacy, helping citizens become more informed when interacting with government offices, legal professionals, and land administration systems.
What it does
TerraLaw BD is an AI-powered informational assistant focused on Bangladeshi land law.
Users can ask questions naturally, for example:
"My father sold part of our family land to an outsider without informing the other co-sharers. Can I claim pre-emption?"
TerraLaw analyzes the question, identifies the relevant dispute type, searches a database of Bangladeshi land statutes, reranks the most relevant legal provisions, and generates an easy-to-understand answer based on those retrieved sources.
The response includes Act and Section citations, allowing users to trace the answer back to the relevant legislation.
The current knowledge base covers:
- Transfer of Property Act, 1882
- State Acquisition and Tenancy Act, 1950
- Non-Agricultural Tenancy Act, 1949
- Acquisition and Requisition of Immovable Property Act, 2017
- Land Development Tax Act, 2023
TerraLaw is not intended to replace lawyers, courts, or government officials. Instead, it acts as an accessible information layer that helps citizens understand the law before taking further action.
How we built it
TerraLaw combines a modern web application with a Retrieval-Augmented Generation (RAG) pipeline and a domain-specialized QLoRA model.
Application Architecture
- Frontend: Next.js, React, TypeScript, Tailwind CSS
- Backend: FastAPI + Uvicorn
- Database: Neon PostgreSQL
- Vector Database: Pinecone
- Embeddings:
all-MiniLM-L6-v2— 384 dimensions - Reranking:
cross-encoder/ms-marco-MiniLM-L-6-v2 - LLM: Groq or our QLoRA fine-tuned Qwen2.5-3B
- GPU: Kaggle Tesla T4 for model training and experimental serving
RAG Pipeline
When a user asks a question:
Question → Dispute Classification → Embedding → Pinecone Retrieval → Reranking → LLM → Citations
The system initially retrieves around 20 potentially relevant legal chunks from Pinecone, reranks them, and provides the strongest passages to the LLM.
This helps ground the generated response in the actual statutory material rather than relying solely on the model's internal knowledge.
Domain-Specialized QLoRA Model
We also built a QLoRA training pipeline for Qwen2.5-3B-Instruct.
The model was:
- Quantized to 4-bit NF4
- Fine-tuned using LoRA
- Trained on 1,121 land-law instruction examples
- Trained on a Tesla T4
- Completed in approximately 39.5 minutes
- Achieved approximately 86.4% token accuracy
The trained adapter can be loaded on top of the quantized model and served through an OpenAI-compatible API.
This gives TerraLaw the flexibility to use either a hosted LLM or our domain-specialized model.
Challenges We Ran Into
Building TerraLaw required solving problems across LLM fine-tuning, RAG, web development, deployment, and GPU infrastructure.
1. Making RAG actually retrieve the right law
Legal questions can be semantically similar while referring to very different sections.
For example, a question about the legal meaning of a "sale" needs to retrieve Section 54 of the Transfer of Property Act, rather than simply finding another nearby property-related section.
We addressed this through semantic retrieval, metadata-aware filtering, dispute classification, and cross-encoder reranking.
2. Fine-tuning on a T4 GPU
Training a 3B-parameter model on limited GPU resources required careful memory optimization.
We used:
4-bit NF4 quantization + QLoRA + gradient accumulation + 8-bit optimizer
We also encountered compatibility problems involving mixed precision, bitsandbytes, and TRL, requiring changes to the training configuration.
3. Serving the model remotely
Our QLoRA model runs on a Kaggle Tesla T4 rather than the local machine.
We built an OpenAI-compatible FastAPI serving layer and exposed it through a Cloudflare tunnel so that TerraLaw's backend could communicate with the GPU server.
However, Kaggle sessions are temporary, meaning the model server and tunnel must be recreated when a session ends.
4. Frontend-to-backend communication
Next.js 16 introduced development-origin issues between localhost and 127.0.0.1.
We solved this by using a Next.js backend proxy and configuring the allowed development origins correctly.
5. Keeping the system grounded
A legal AI system cannot simply produce convincing answers. It needs to provide information that can be traced back to a source.
This led us to prioritize retrieval quality, statutory citations, and source-grounded generation rather than treating the LLM as the source of truth.
Accomplishments We're Proud Of
We are particularly proud that TerraLaw is more than a chatbot prototype — it is a complete working system.
🚀 End-to-end platform
We built the complete pipeline from:
User → Next.js → FastAPI → RAG → Pinecone → LLM → Citations → PostgreSQL
🧠 Domain-specific AI
We successfully fine-tuned Qwen2.5-3B using QLoRA specifically for Bangladeshi land-law content.
📚 Legal knowledge base
We processed and indexed five important Bangladeshi land-related statutes into a searchable semantic knowledge base.
🔎 Source-grounded answers
The system doesn't simply generate an answer. It identifies and exposes the relevant Act and Section, making the information easier to verify.
💻 Resource-efficient training
We demonstrated that a domain-specialized 3B-parameter model can be fine-tuned using a single Tesla T4 GPU through quantization and parameter-efficient training.
🌍 Social impact
Most importantly, we built the system around a real societal problem:
reducing the information barrier between ordinary citizens and bureaucracy.
What We Learned
One of our biggest lessons was that building a useful AI system is not simply about choosing a powerful model.
Retrieval quality can be just as important as model quality.
A smaller model with the correct legal context can be more useful than a much larger model that generates an answer without reliable sources.
We also learned that:
- Domain-specific data is extremely valuable.
- Fine-tuning and RAG solve different problems and can complement each other.
- Legal applications require stronger emphasis on grounding and verification.
- Quantization makes specialized models much more accessible on limited hardware.
- System architecture matters as much as individual ML components.
- Building a real product requires solving problems beyond the model — authentication, databases, APIs, monitoring, deployment, and user experience all matter.
Most importantly, we learned that AI can be used not only to automate tasks, but also to reduce information inequality.
What's Next for TerraLaw
TerraLaw is currently focused on Bangladeshi land law, but our vision is much broader.
🇧🇩 Bengali Legal Assistance
Introduce strong Bengali-language support so citizens can interact with the system in the language they are most comfortable using.
📄 Document & Notice Analysis
Allow users to upload land-related government notices and documents and identify the relevant laws, sections, deadlines, and required actions.
🏛️ Bureaucratic Procedure Guidance
Expand beyond legislation to explain government procedures, required documents, and administrative workflows in simple language.
🎙️ Voice Interface
Enable citizens with limited digital literacy to ask questions using voice rather than typing.
📚 Expanded Legal Coverage
Gradually incorporate additional Bangladeshi laws, regulations, rules, and publicly available government resources.
🔐 Local & Private Deployment
Explore offline and on-premise deployment for organizations that require greater control over sensitive information.
🤝 Citizen Empowerment
Ultimately, we want TerraLaw to become more than a land-law chatbot.
We envision it as a digital bureaucratic literacy platform for Bangladesh — helping citizens understand laws, procedures, government documents, and their rights in a way that is accessible, transparent, and easy to verify.
Our vision is simple: technology should not make citizens more dependent on systems they don't understand. It should help them understand those systems better.
Built With
- docker
- fastapi
- groq
- hugging-face
- langchain
- neon
- next.js
- pinecone
- postgresql
- python
- rag
- railway
- react
- sentence-transformers
- tailwindcss
- typescript
- uvicorn
- vercel
Log in or sign up for Devpost to join the conversation.