How bavuong2005/legal-qa-system works
RoadLawQA turns Vietnamese traffic-law text into cited answers and multiple-choice quizzes. Its documented content workflow chunks statutes into context-enriched records, embeds and indexes them, then retrieves and reranks relevant passages for generation. Users can start through the Streamlit chat or quiz tabs, or the CLI pipelines; both ultimately use shared retrieval and Gemini generation. The README also documents hybrid BM25/dense search, adjustable result counts, source attribution, and performance metrics. Some source excerpts are partial, so the graph omits uncertain internal wiring while retaining documented product capabilities.
Main entry points: retriever_custom.py Hybrid retrieval · generator.py Answer and quiz generator · app.py Streamlit chat and quiz · rag_qa.py QA pipeline
Components 20
Law preparation
- Raw statutes
data/raw - Hierarchical chunker
backend/clean_and_split.py - Enriched chunks
data/processed - Index builder
backend/build_index.py
Retrieval
- LawChunks store
docker/docker-compose.yml - Hybrid retrieval
backend/retriever_custom.py - BM25 search
backend/retriever_custom.py - Dense search
backend/retriever_custom.py - Alpha tuning
backend/retriever_custom.py - Cross-encoder rerank
backend/retriever_custom.py - Ranked legal context
backend/retriever_custom.py
Generation
- QA pipeline
backend/rag_qa.py - Quiz pipeline
backend/rag_quiz.py - Answer and quiz generator
backend/generator.py - Quiz prompt
backend/prompts.py - Gemini service
User interfaces
- Streamlit chat and quiz
frontend/app.py - Cited answer
- Quiz questions
Other components
- Questioner
Connections 26
- Questioner → Streamlit chat and quiz: asks or selects
- Questioner → QA pipeline: asks via CLI
- Questioner → Quiz pipeline: requests via CLI
- Raw statutes → Hierarchical chunker: reads statutes
- Hierarchical chunker → Enriched chunks: writes chunks
- Enriched chunks → Index builder: reads chunks
- Index builder → LawChunks store: embeds and indexes
- Streamlit chat and quiz → Hybrid retrieval: retrieves context
- Streamlit chat and quiz → Answer and quiz generator: generates quiz
- Streamlit chat and quiz → Answer and quiz generator: generates answer
- QA pipeline → Hybrid retrieval: retrieves context
- QA pipeline → Answer and quiz generator: generates answer
- Quiz pipeline → Hybrid retrieval: retrieves chunks
- Quiz pipeline → Answer and quiz generator: generates quiz
- Hybrid retrieval → LawChunks store: queries vectors
- Hybrid retrieval → BM25 search: scores keywords
- Hybrid retrieval → Dense search: searches vectors
- Hybrid retrieval → Alpha tuning: tunes weighting
- Hybrid retrieval → Cross-encoder rerank: reranks candidates
- Hybrid retrieval → Ranked legal context: returns top results
- Answer and quiz generator → Gemini service: generates text
- Answer and quiz generator → Quiz prompt: formats quiz prompt
- Answer and quiz generator → Cited answer: returns answer and sources
- Answer and quiz generator → Quiz questions: returns quiz
- Streamlit chat and quiz → Cited answer: displays citations and metrics
- Streamlit chat and quiz → Quiz questions: displays questions