How weiyuu-zlc/rag-legal works
LegalMind is a Chinese-law RAG question-answering system. A user submits a question through the Streamlit app or CLI; the question processor retrieves relevant provisions, optionally reranks them, asks an LLM to answer from the retrieved context, and validates and formats article citations. Separately, the corpus workflow parses source laws, splits them into chunks, and builds unified BM25 and vector indexes. Evaluation generates questions from the corpus and measures retrieval and answer quality. The README documents the build sequence and optional reranking; some internal implementation details were not sampled, so uncertain connections are omitted.
Main entry points: questions_processing.py Question processor · api_requests.py LLM API adapter · retrieval.py Retrieval · evaluation.py Evaluation
Components 16
User interfaces
- Web interface
app.py - Command line
cli.py
Question answering
- Question processor
src/questions_processing.py - Retrieval
src/retrieval.py - LLM reranking
src/reranking.py - Prompt templates
src/prompts.py
Corpus and indexing
- Law source files
data - Law parser
src/legal_parser.py - Article chunking
src/text_splitter.py - Index builder
src/ingestion.py - Unified indexes
Model services
- LLM API adapter
src/api_requests.py - Parallel API processor
src/api_request_parallel_processor.py
Evaluation
- Evaluation
src/evaluation.py
Other components
- Questioner
- DashScope models
Connections 19
- Questioner → Web interface: asks via
README.md - Questioner → Command line: asks via
README.md - Web interface → Question processor: submits question
app.py - Command line → Question processor: submits question
cli.py - Question processor → Retrieval: retrieves provisions
src/questions_processing.py - Retrieval → Unified indexes: reads indexes
src/retrieval.py - Retrieval → LLM reranking: reranks candidates
src/retrieval.py - LLM reranking → Prompt templates: uses prompts
src/reranking.py - Question processor → LLM API adapter: requests answer
src/questions_processing.py - LLM API adapter → Prompt templates: uses prompts
src/api_requests.py - LLM API adapter → DashScope models: calls model
README.md - LLM API adapter → Parallel API processor: uses for parallel requests
src/api_requests.py - Law source files → Law parser: provides documents
README.md - Law parser → Article chunking: produces parsed laws
README.md - Article chunking → Index builder: provides chunks
README.md - Index builder → Unified indexes: writes indexes
src/ingestion.py - Evaluation → Retrieval: evaluates retrieval
src/evaluation.py - Evaluation → Question processor: evaluates answers
src/evaluation.py - Evaluation → DashScope models: generates and judges
README.md