How shobhit-shukla/rag-legal-docs works
GDPR Legal RAG turns a user’s legal question into a cited, grounded answer: the Streamlit chat submits it to an in-process chain or the FastAPI backend, which retrieves and reranks legal passages before generation. A separate ingestion stage parses PDFs into article-aware chunks and builds indexes. The repository also includes an agentic four-tool router and a production pgvector retrieval option. The graph reflects documented and excerpted relationships; unsampled implementation details are omitted rather than inferred.
Main entry points: main.py FastAPI endpoints · chain.py RAG chain · retriever.py Chroma hybrid search · app.py Streamlit chat
Components 16
User experience
- Streamlit chat
app.py - FastAPI endpoints
src/api/main.py
Query and generation
- RAG chain
src/generation/chain.py - Agentic router
src/generation/agent.py - LLM provider
- Langfuse tracing
Retrieval and storage
- Cross-encoder reranker
src/retrieval/reranker.py - Chroma hybrid search
src/retrieval/retriever.py - pgvector hybrid search
src/retrieval/pg_retriever.py - ChromaDB index
- Postgres pgvector
- BM25 index
data/bm25.pkl
Legal document ingestion
- Legal PDF
data/raw/gdpr.pdf - Article-aware parser
src/ingestion/pdf_parser.py
Configuration
- Runtime settings
src/config.py
Other components
- Questioner
Connections 23
- Questioner → Streamlit chat: asks question
README.md - Streamlit chat → RAG chain: runs or streams
app.py - Streamlit chat → FastAPI endpoints: posts query
app.py - FastAPI endpoints → RAG chain: runs or streams
src/api/main.py - FastAPI endpoints → Article-aware parser: parses PDF
src/api/main.py - FastAPI endpoints → Chroma hybrid search: builds index
src/api/main.py - FastAPI endpoints → pgvector hybrid search: builds index
src/api/main.py - RAG chain → Chroma hybrid search: retrieves passages
src/generation/chain.py - RAG chain → Cross-encoder reranker: reranks shortlist
src/generation/chain.py - RAG chain → LLM provider: generates answer
src/generation/chain.py - RAG chain → Langfuse tracing: traces optionally
src/generation/chain.py - Agentic router → Chroma hybrid search: searches articles
src/generation/agent.py - Agentic router → Cross-encoder reranker: reranks shortlist
src/generation/agent.py - Agentic router → LLM provider: routes and answers
src/generation/agent.py - Chroma hybrid search → ChromaDB index: queries and stores
README.md - Chroma hybrid search → BM25 index: fuses sparse results
README.md - pgvector hybrid search → Postgres pgvector: queries and stores
src/retrieval/pg_retriever.py - pgvector hybrid search → BM25 index: fuses sparse results
src/retrieval/pg_retriever.py - Legal PDF → Article-aware parser: supplies document
README.md - Article-aware parser → Chroma hybrid search: provides chunks
scripts/ingest.py - Article-aware parser → pgvector hybrid search: provides chunks
src/api/main.py - Runtime settings → FastAPI endpoints: configures backend
src/api/main.py - Runtime settings → Streamlit chat: configures runtime
app.py