WARP.md
Guides WARP terminal AI on commands, architecture, and models for a legal document summarization tool using RAG and transformers.
What this file does
Guides WARP terminal AI on commands, architecture, and models for a legal document summarization tool using RAG and transformers.
When to use it
- Setting up WARP to assist with a Python project that has separate backend and frontend
- Onboarding a new developer to a legal NLP project with multiple models and pipelines
- Configuring WARP to understand project-specific commands and data flow
- Documenting a project's architecture for AI-assisted development
Assumes this stack
WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
Project Overview
AI-Powered Legal Document Summarization System using NLP, RAG (Retrieval-Augmented Generation), and transformer models (BERT, T5, BART, LexT5) for forensic and legal document analysis.
Common Commands
Backend
Install Dependencies:
cd backend
pip install -r requirements.txt
Download Required Models:
python -m spacy download en_core_web_sm
python -c "import nltk; nltk.download('stopwords')"
Run Flask API Server:
cd backend
python app.py
Server runs on http://127.0.0.1:5000
Test NLP Pipeline:
cd backend
python test_nlp_pipeline.py
Frontend
Run Streamlit UI:
cd frontend
streamlit run streamlit_app.py
Note: Both backend (Flask on port 5000) and frontend (Streamlit) must run simultaneously for full functionality.
Architecture Overview
Backend Structure
backend/app.py — Main Flask API server
ForensicDocumentAnalyzerclass: Core document analysis orchestrator- Lazy-loads heavy models (LexT5) to optimize startup time
- Key endpoints:
/api/test- Health check/api/analyze- PDF upload & summarization (extractive/hybrid modes)/api/query- RAG-based semantic search and answer generation
backend/nlp_module/ — NLP Processing Pipeline
text_preprocessing.py- SpaCy-based entity extraction (PERSON, ORG, DATE, GPE, CASE_ID) + custom legal patternsextractive_summarization.py- Hybrid TextRank + TF-IDF with legal document boosting (handles long legal sentences)abstractive_summarization.py- LexT5 (Legal T5) for refinement with chunking strategysentiment_risk_analyzer.py- Forensic intelligence extractionmodel_wrapper.py- Model abstraction layer
backend/rag_module/ — RAG Engine
rag_engine.py- FAISS-based vector store withsentence-transformers/all-MiniLM-L6-v2embeddings- Uses
pszemraj/led-large-book-summaryfor answer generation - Persists index to
vector_store/legal_faiss.indexandvector_store/legal_metadata.json
Frontend Structure
frontend/streamlit_app.py — Glassmorphic web interface
- Two-tab design: Document Analysis and RAG Query
- Communicates with Flask backend via HTTP POST
- Custom CSS with glassmorphism and animations
Data Flow
- Document Upload → PDF extracted with PyMuPDF (
fitz) - Text Preprocessing → SpaCy sentence splitting + entity recognition
- Extractive Summarization → Hybrid scoring (TextRank + TF-IDF)
- Optional Abstractive Refinement → LexT5 model compresses extractive output
- RAG Indexing → Document chunks embedded and stored in FAISS
- Query Processing → Semantic search → Context retrieval → LED model generates answer
Key Design Patterns
Lazy Model Loading:
get_abstractive_model()function defers LexT5 loading until hybrid mode is requested- Reduces memory footprint for extractive-only workflows
Singleton Pattern:
get_analyzer()ensures singleForensicDocumentAnalyzerinstancerag_engineinstantiated as global inapp.py
Legal Text Handling:
- Custom sentence splitting for long legal sentences (40-50 words/sentence)
- Legal markers (
<HD>,Section,held that) receive 20% score boost in extractive summarization - Corruption detection for scanned PDFs (single-letter patterns, repetition)
Chunking Strategy:
- Extractive summary fed to abstractive model to prevent context loss
- LexT5 uses 512-token chunks with sentence boundary preservation
- Compression ratio maintained at 50-70% to preserve legal detail
Data Directory
data/ contains 85 legal case files (LNIND_1951_CAL_*.txt) from 1951 Calcutta High Court - used for testing and RAG indexing.
Model Information
Extractive Models:
- SpaCy:
en_core_web_sm - TextRank via NetworkX PageRank
- TF-IDF via scikit-learn
Abstractive Models:
- Primary:
santoshtyss/lt5-small(LexT5 - Legal T5) - RAG Generator:
pszemraj/led-large-book-summary(LED model)
Embedding Models:
sentence-transformers/all-MiniLM-L6-v2(384-dim vectors)
Testing Approach
Use backend/test_nlp_pipeline.py to test individual NLP modules with sample legal text. No formal test framework detected - tests are manual via sample inputs.
Important Notes
- Windows Environment: This project uses PowerShell commands (adjust for Unix if needed)
- GPU Acceleration: Models auto-detect CUDA; CPU fallback available
- PDF Requirements: Only accepts
.pdffiles; scanned PDFs are detected and rejected - FAISS Persistence: Vector store automatically saves after each document addition
- File Cleanup: Uploaded PDFs are deleted after analysis (see
finallyblock in/api/analyze) - CORS: Backend enables CORS for all origins on
/api/*routes
Requirements
Key dependencies:
- Flask + flask-cors
- spacy + en_core_web_sm model
- nltk
- transformers + torch
- sentence-transformers
- scikit-learn
- faiss-cpu or faiss-gpu
- pymupdf (fitz)
- streamlit + streamlit-lottie
What's inside
7 sections: project overview, commands, architecture, data, models, testing, notes. 6 code blocks, 4 endpoints listed.
Change this for your project
- Replace
manish3089/Legal-Research-Summarization-Toolwith your own repository name - Replace
santoshtyss/lt5-smallwith your own abstractive model if different - Replace
pszemraj/led-large-book-summarywith your own RAG generator model - Replace
data/path and file names likeLNIND_1951_CAL_*.txtwith your own test data
Where it goes
Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.
Worth borrowing
- Lazy-load heavy models to reduce startup time for workflows that don't need them
- Use a singleton pattern for the main analyzer to avoid redundant model initialization
- Boost legal document markers in extractive summarization scoring
Related Documents
SUMMARY
Proposes three on-prem AI architectures, modular, hybrid, and fully local RAG, with hardware specs and vendor lists.
Retrieval & Prompts
Explains how CharMemory's extraction prompt and Vector Storage settings determine memory retrieval quality in SillyTavern.
Advanced RAG Techniques
Surveys advanced RAG architectures, Agentic, Corrective, Self-RAG, Graph RAG, RAPTOR, Multimodal, Temporal, with design trade-offs and decision guidance.
RFC-BLite: High-Performance Embedded Document Database for .NET
Specifies an embedded document database for.NET with zero-allocation I/O, C-BSON format, and ACID transactions.