How anonymousbeliever/pocket-lawyer works
Pocket Lawyer Kenya serves legal-information questions with answers grounded in Kenyan legal sources and citations. The main workflow enters through the FastAPI ask route: optional intent classification sends conversational input to a direct reply, while legal questions go through retrieval, reranking, and grounded generation. A separate ingestion workflow extracts, cleans, structures, validates, chunks, embeds, and stores legal documents for retrieval. The graph reflects documented ingestion stages and sampled runtime wiring; unsampled subsystem links are kept conservative.
Main entry points: run.py Ingestion runner · routes.py Ask and health routes · rag.py Legal RAG · retriever.py Hybrid retriever
Components 22
API and Routing
- FastAPI app
backend/app/main.py - Ask and health routes
backend/app/api/routes.py - Intent classifier
backend/app/ai/intent.py - Conversational reply
backend/app/ai/intent.py
Legal Answering
- Legal RAG
backend/app/ai/rag.py - Hybrid retriever
backend/app/ai/retriever.py - Passage reranker
backend/app/ai/reranker.py - Answer generation
backend/app/ai/llm.py - Citation and answer format
backend/app/ai/answer.py
Legal Data Ingestion
- Legal source documents
- Ingestion runner
data_pipeline/run.py - PDF extraction
data_pipeline/extractors/pdf_extractor.py - Document cleaners
data_pipeline/cleaners - Legal structure adapters
data_pipeline/structure - Content validators
data_pipeline/validators - Passage chunking
data_pipeline/chunking/chunker.py - Embedding and ingestion
data_pipeline/vectorstore/ingest.py
Models and Storage
- Qdrant collection
- Embedding model
- OpenAI API
Other components
- Questioner
- Legal information seeker
Connections 22
- Legal information seeker → FastAPI app: submits question
- FastAPI app → Ask and health routes: mounts routes
- Ask and health routes → Intent classifier: classifies query
- Ask and health routes → Conversational reply: answers conversational
- Ask and health routes → Legal RAG: asks legal question
- Legal RAG → Hybrid retriever: retrieves passages
- Legal RAG → Passage reranker: reranks candidates
- Legal RAG → Answer generation: generates grounded answer
- Answer generation → Citation and answer format: validates citations
- Hybrid retriever → Qdrant collection: searches vectors
- Hybrid retriever → Embedding model: embeds query
- Answer generation → OpenAI API: requests generation
- Ask and health routes → Legal information seeker: returns answer
- Legal source documents → Ingestion runner: provides documents
- Ingestion runner → PDF extraction: extracts text
- Ingestion runner → Document cleaners: cleans text
- Ingestion runner → Legal structure adapters: parses legal units
- Ingestion runner → Content validators: validates content
- Ingestion runner → Passage chunking: builds chunks
- Ingestion runner → Embedding and ingestion: ingests chunks
- Embedding and ingestion → Embedding model: embeds passages
- Embedding and ingestion → Qdrant collection: upserts vectors