LegalBro is an AI-powered legal assistant focused on Bangladeshi law and constitution.
It uses a Retrieval-Augmented Generation (RAG) system to provide accurate, context-aware answers from legal documents, simplified into plain English.
- 🔍 AI-powered legal Q&A (RAG-based)
- 📚 Hybrid retrieval (Semantic + Keyword search)
- 🇧🇩 Focused on Bangladeshi law & constitution
- 🧠 Context-aware answers from legal PDFs
- ⚡ FastAPI backend with clean architecture
- 🔌 Pluggable LLM support (OpenAI / OpenRouter / DeepSeek)
- 📦 Preprocessed vector store (optimized for deployment)
- 📄 Legal PDFs are ingested and cleaned
- ✂️ Text is chunked using structure-aware + contextual chunking
- 🔗 Embeddings are generated using sentence-transformers
- 🗂️ Stored in FAISS vector database
- 🔎 Hybrid retrieval:
- Semantic search (FAISS)
- Keyword filtering (precision boost)
- 🤖 LLM generates answers grounded in retrieved context
app/ ├── rag/ │ ├── ingest/ # PDF loading, cleaning, chunking │ ├── retrieval/ # Hybrid retrieval logic │ ├── vectorstore/ # FAISS + metadata │ └── embedder.py ├── services/ # RAG + LLM orchestration ├── ai/ # LLM integration ├── api/ # API routes └── main.py # FastAPI entry point
data/ ├── processed/ # chunks.json └── vectorstore/ # index.faiss, metadata.pkl
git clone https://github.com/fiction17/LegalBroBD.git
cd LegalBro
python -m venv .venv source .venv/bin/activate
pip install -r requirements.txt
Create .env:
OPENAI_API_KEY=your_api_key
uvicorn app.main:app --reload
Visit:
Example:
/ask?question=What is the basic structure of the Constitution of Bangladesh?
Response:
{
"answer": "...",
"sources": ["...", "..."]
}PDF → Clean → Chunk → Embed → FAISS
Query → Embed → Retrieve → LLM → Answer
- Backend: Render
- Frontend: (Planned) Vercel
- 🔥 Reranker (Cross-Encoder for better retrieval)
- 📄 Advanced legal chunking (section-aware)
- 🧾 Contract generation (e.g., partnership deed)
- 🧠 Multi-model support (DeepSeek, GPT, etc.)
- 🔐 Authentication & usage tracking
⚠️ Disclaimer
This project provides informational assistance only and does not constitute legal advice.
👨💻 Author
Built by Reyad