How saina-panda12/legal_qa works
Project Type and Purpose
• This is a backend-only, Retrieval-Augmented Generation (RAG) service for Legal QA.
• It exposes REST endpoints via FastAPI, orchestrates NER and semantic search over legal documents, then generates answers using an LLM pipeline (LangChain + HuggingFace).
File Structure Analysis
Top-level modules:
• main.py, app.py – FastAPI application entrypoints
• auth_routes.py – authentication endpoints (JWT)
• chat_routes.py – conversational QA endpoints
• doc_routes.py – document ingestion/search endpoints
• database.py, collection.py, rag.db – persistence (vector DB & metadata)
• embedding_model.py, vectorization.py – embedding generator
• q_client.py – Qdrant client wrapper
• model.py, response_model1.py, response_model2.py, schemas.py – Pydantic models & response schemas
• jwt.py – JWT token utilities
• logging_config.py – centralized logging setup
README Insights
• Named Entity Recognition (NER) for legal entities
• Sentence-Transformer embeddings stored in Qdrant
• LangChain orchestrates retrieval + LLM generation
• API deployed via FastAPI
a. Main Components
1) Client(s) (e.g., Web UI, CLI)
2) FastAPI Service
– auth_routes.py
– doc_routes.py
– chat_routes.py
3) Service Layer
– JWT auth (jwt.py)
– NER & preprocessing (embedding_model.py + vectorization.py)
– LangChain pipeline (model.py + response_model*.py)
4) Data Layer
– Qdrant Vector DB (q_client.py + collection.py)
– rag.db (SQLite or metadata store via database.py)
5) External Services
– HuggingFace / Sentence-Transformers model repo
– Qdrant server (vector storage)
b. Relationships & Data Flow
1) HTTP Request → FastAPI endpoint (auth / chat / doc)
2) Auth endpoint uses jwt.py → returns access token
3) Document endpoint
• NER extraction → creates embeddings → stores to Qdrant via q_client.py
4) Chat endpoint
• Receives query → vectorizes query → Qdrant similarity search → retrieves top-k docs
• Feeds docs + query into LangChain chain → LLM generates answer
5) FastAPI serializes response via Pydantic models → returns JSON
c. Architectural Patterns
– Layered: API layer, Service/Orchestration layer, Data layer
– RAG pipeline pattern (Retrieve → Augment → Generate)
– Modular routing (auth, doc, chat)
– Dependency injection (FastAPI Depends)
d. Key Technologies
– FastAPI (API framework)
– Pydantic (schemas & validation)
– JWT (authentication)
– Sentence-Transformers (embeddings)
– Qdrant (vector DB)
– LangChain (pipeline orchestration)
– HuggingFace LLMs
Final Advice
• Be exhaustive: show all major modules and how they interact.
• Keep it clear: group related files into logical clusters (e.g., routing, models, data).
• Avoid clutter: collapse trivial utilities (logging_config.py) into a “Utilities” grouping.