You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Production-Grade Agentic GraphRAG Platform for Pakistani Law
An intelligent legal assistant that answers questions about Pakistani law โ Constitution 1973, Pakistan Penal Code, and Criminal Procedure Code โ using multi-agent reasoning, knowledge graphs, and hybrid retrieval with cross-encoder reranking.
graph LR
A[Planner] --> B[Router]
B --> C[Retriever]
C --> D[Generator]
D --> E{Verify?}
E -->|Low Confidence| F[Verifier]
F -->|Retry| C
E -->|High Confidence| G[Formatter]
G --> H[Response]
Loading
The Planner analyzes the query and selects a retrieval strategy:
vector_only โ simple factual questions
hybrid โ complex questions needing both vector + graph context
Note: Redis and Neo4j are optional โ the system degrades gracefully without them (uses in-memory fallbacks). PostgreSQL is required for session persistence.
๐ Supported Laws
Law
File
Coverage
๐๏ธ Constitution of Pakistan 1973
constitution_1973.pdf
All 280 Articles + Amendments
โ๏ธ Pakistan Penal Code (PPC)
ppc.pdf
All 511 Sections
๐ Criminal Procedure Code (CrPC) 1898
crpc1898.pdf
All 565 Sections
Adding New Documents
Navigate to Admin Dashboard โ http://localhost:3000/admin
Drag & drop PDF or ZIP files onto the upload zone
The system processes them in the background:
ZIP โ extract PDFs โ validate โ chunk โ embed โ index
Large files (up to 4 TB) are handled via chunked uploads โ never loaded into RAM
Check progress in real-time or come back later โ processing continues independently
๐ ๏ธ Tech Stack
Layer
Technology
LLM
Groq Cloud (llama-3.3-70b-versatile)
Embeddings
Local sentence-transformers/all-mpnet-base-v2 (768-dim)
Reranker
cross-encoder/ms-marco-MiniLM-L-12-v2
Vector Store
FAISS (IndexFlatIP + IndexIDMap)
Knowledge Graph
Neo4j 5 Community
Agent Framework
LangGraph (StateGraph)
Backend
FastAPI + Uvicorn
Frontend
Next.js 14 + React 18 + TailwindCSS
Cache
Redis 7 (LLM + embedding + retrieval caching)
Task Queue
Celery with Redis broker
Database
PostgreSQL 16 (chat session persistence)
Voice
Groq Whisper (STT) + Web Speech API (TTS)
Container
Docker Compose (7 services)
๐ณ Docker Services
Service
Port
Description
backend
8000
FastAPI application
frontend
3000
Next.js UI
postgres
5432
Chat session storage
redis
6379
Caching + Celery broker
neo4j
7474 / 7687
Knowledge graph
celery-worker
โ
Background task processing
๐ก API Endpoints
Chat
Method
Endpoint
Description
POST
/api/v1/chat
Send a message, get a response
POST
/api/v1/chat/stream
Streaming response (SSE)
Sessions
Method
Endpoint
Description
GET
/api/v1/sessions
List all chat sessions
GET
/api/v1/sessions/{id}
Get session messages
DELETE
/api/v1/sessions/{id}
Delete a session
PATCH
/api/v1/sessions/{id}
Rename a session
Upload & Documents
Method
Endpoint
Description
POST
/api/v1/upload/init
Initialize chunked upload
POST
/api/v1/upload/chunk
Upload a file chunk
POST
/api/v1/upload/complete
Signal upload done โ triggers background processing
GET
/api/v1/upload/progress/{id}
SSE progress stream
GET
/api/v1/documents
List uploaded documents
DELETE
/api/v1/documents/{name}
Delete a document
System
Method
Endpoint
Description
POST
/api/v1/ingest
Trigger document ingestion
GET
/api/v1/ingest/status
Ingestion pipeline status
GET
/api/v1/health
Service health check
GET
/api/v1/graph/stats
Neo4j graph statistics
GET
/api/v1/cache/stats
Redis cache hit rates
Voice
Method
Endpoint
Description
POST
/api/v1/voice/stt
Speech-to-text (audio โ text)
๐ค Large File Upload Architecture
QanoonAI handles files from kilobytes to terabytes without crashing: