NLP-LegalQA is a Vietnamese legal question answering toolkit. It combines legal document scraping, parsing, Neo4j graph import, vector retrieval, reranking, LLM-based answer generation, evaluation scripts, and a Streamlit chat UI.
The project is built for experiments around Vietnamese legal QA and retrieval-augmented generation over structured legal documents.
- Scrape Vietnamese legal documents from
phapluat.gov.vn. - Parse downloaded documents into structured JSON suitable for graph import.
- Import legal articles, clauses, and points into Neo4j.
- Generate embeddings and run vector, full-text, hybrid, and reranked retrieval.
- Run Legal QA chat through a FastAPI backend and Streamlit UI.
- Evaluate retrieval and generation pipelines with scripts for baseline RAG, rerankers, fine-tuned LLMs, BERTScore, ROUGE, and merged evaluation outputs.
- Provide annotation tooling for QA references.
| Path | Purpose |
|---|---|
src/legal_scraper/ |
CLI, scraper, parser, Neo4j importer, retrieval, API, and QA pipeline code. |
src/llm/ |
LLM-related helpers. |
src/annotate_qa/ |
FastAPI annotation tool for QA reference data. |
scripts/ |
Dataset generation, evaluation, fine-tuning, and result-processing scripts. |
streamlit_ui/ |
Streamlit frontend for the Legal QA API. |
tests/ |
Unit and integration-style tests for parsing, retrieval, embedding, and graph import behavior. |
notebook/ |
Exploratory notebooks and supporting resources. |
qa_dataset/ |
QA dataset artifacts used by the experiments. |
- Python 3.12+
- Neo4j for graph import, retrieval, and QA pipeline runs
uvorpip- Optional local or hosted OpenAI-compatible LLM endpoint
- Optional OpenRouter API key for hosted model experiments
With uv:
uv syncOr with pip:
python -m venv .venv
source .venv/bin/activate
pip install -e .For UI dependencies:
pip install -e '.[ui]'Copy the environment template:
cp .env.example .envConfigure Neo4j and model provider values in .env.
Search legal documents:
legal-scraper search "giao thông đường bộ" -n 10Scrape documents:
legal-scraper scrape "giao thông đường bộ" -n 20 -o dataParse downloaded documents:
legal-scraper parse -i data -o data/parsedImport parsed documents into Neo4j:
legal-scraper import-neo4j -i data/parsedRun vector search:
legal-scraper vector-search -q "quy định về tốc độ xe máy" --k 5Run the full QA pipeline:
legal-scraper query -q "Người điều khiển xe máy cần giấy tờ gì?"Start the FastAPI backend:
uv run uvicorn legal_scraper.api:app --host 0.0.0.0 --port 8000 --reloadRun the Streamlit UI:
cd streamlit_ui
streamlit run app.pyThe UI expects the API backend at http://localhost:8000.
pytestSome tests and pipeline commands require local data files, Neo4j, model weights, or API credentials. Keep secrets in .env; do not commit local credentials or generated payloads.
This is an active research/course project for Vietnamese legal QA. The codebase is organized for experimentation and evaluation, not yet as a packaged production service.
MIT