A stateless Retrieval-Augmented Generation (RAG) assistant for Nepali law. It uses:
- Google Gemini for embeddings and generation
- ChromaDB for vector search
- FastAPI for the backend
- Vite/React and Shadcn/UI for the modern frontend user interface
This bot answers only from the ingested legal documents:
- Constitution of Nepal 2072
- The Criminal Offences Act 2074
- The Labour Act 2074
- The National Civil Act 2074
- The National Penal Act 2074
- Bank and Financial Institution Act 2073
- Banking Offence and Punishment Act 2064
- Electronic Commerce Act 2081
- International Financial Transactions Act 2054
- The Income Tax Act 2058
- Small-talk guard and domain classification (Nepali law only)
- Query rewriting to improve retrieval quality
- ChromaDB retrieval with metadata-rich source display
- Gemini 2.5 Pro/Flash for grounded answer generation
- Streamlit chat UI with collapsible sources and search query display
- Adaptive answer format:
- Short Answer
- What the Law Says (cites articles/clauses)
- Practical Steps (only for action/procedure queries)
- Disclaimer
.
ββ backend/
β ββ main.py # FastAPI stateless RAG pipeline
β
ββ chroma_db/ # ChromaDB persistent directory (auto-generated)
β
ββ config/
β ββ __init__.py
β ββ paths.py # Project path utilities (optional)
β
ββ data/
β ββ raw/ # Raw legal documents (if building vectors)
β ββ processed/ # Converted & cleaned JSON docs
β ββ evaluation/ # Test sets, metrics, prompts
β
ββ documentation/
β ββ LiteratureReview.pdf
β ββ Proposal.pdf
β
ββ frontend/
β ββ index.html
β ββ package.json
β ββ vite.config.ts
β ββ tailwind.config.ts
β ββ postcss.config.js
β ββ public/
β ββ src/
β ββ main.tsx # React entry point
β ββ App.tsx # Root wrapper component
β ββ App.css # Global component styling
β ββ index.css # Tailwind + base styles
β β
β ββ pages/
β β ββ Index.tsx # Landing page (hero + CTA)
β β ββ NotFound.tsx # 404 handler
β β
β ββ components/
β β ββ Hero.tsx # Homepage hero UI
β β ββ NavLink.tsx # Navbar interactive link component
β β ββ LegalAssistant.tsx # Main chat screen
β β ββ ui/ # shadcn component library
β β
β ββ hooks/
β β ββ use-mobile.tsx
β β ββ use-toast.ts
β β
β ββ lib/
β ββ utils.ts # Shared helpers (stream UI, formatting)
β
ββ notebooks/
β ββ baseline_data_ingestion_pipeline.ipynb
β ββ baseline_retrieval_pipeline.ipynb
β ββ data_ingestion_multimodel.ipynb
β ββ final_data_ingestion_pipeline.ipynb
β ββ final_retreval_pipeline.ipynb
β ββ final_retriever_evaluation.ipynb
β ββ generator_evaluation.ipynb
β ββ multimodel_evaluation.ipynb
β ββ multimodel_split_evaluation.ipynb
β ββ retriever_evaluation.ipynb
β
ββ .env # GEMINI_API_KEY
ββ .gitignore
ββ generator_evaluation_results.csv
ββ generator_evaluation_results.json
ββ requirements.txt
ββ run.py # Optional pipeline runner
ββ README.md
- Backend: FastAPI, Pydantic, Uvicorn
- Vector Store: ChromaDB (persistent)
- LLM + Embeddings: Google Gemini (via
google-genai)- Generation: gemini-2.5-pro (fallback: gemini-2.5-flash)
- Embeddings: models/text-embedding-004
- Frontend: Frontend β Vite + React + TypeScript + Tailwind + Shadcn/UI
- Python 3.10+
- A Google Gemini API key (from Google AI Studio)
- macOS, Linux, or Windows
Create a .env in the repo root:
GEMINI_API_KEY=your_gemini_api_key_hereCreate a virtual environment and install:
python -m venv .venv
# Windows: .venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
pip install -r requirements.txt- If
./backend/chroma_db/already contains a collection namedlegal_docs, youβre set. - Otherwise, build it using your ingestion notebooks:
- Recommended:
notebooks/final_data_ingestion_pipeline.ipynb
- Recommended:
- Place raw text/markdown under
data/raw/(or what your notebook expects). - Output should be a persistent Chroma collection at
./backend/../chroma_db(repo root./chroma_db).
The backend looks for a Chroma collection named
legal_docsat repo-root./chroma_db.
From repo root:
uvicorn backend.main:app --host 0.0.0.0 --port 8000 --reloadYou should see: ββ MyPocketLawyer backend (completely stateless) is live.β
In a separate terminal, follow these steps to launch the React application:
cd frontendnpm installnpm run devIf run.py orchestrates both backend and frontend on your machine, run:
python run.py(If not implemented to launch both, use the separate commands above.)
- What are the three organs of the Government under the Constitution of Nepal?
- What is the overtime pay in Nepali like?
- What happens if someone is found planting explosives?