How khadija20032003/lawyerchat works
Purpose and Entry Points
This repository is a Python RAG application for answering natural-language questions about SEC 10-K risk-factor disclosures, optionally combined with user-uploaded PDFs. The interactive runtime starts at chatbot/app.py; its UI delegates model and retrieval work to the chatbot layer. Dataset refreshes run separately through scripts/daily_update_hf.py, scheduled by .github/workflows/daily_update.yml.
Interactive Application Boundary
chatbot/app.py owns the Gradio Blocks interface, chat state, file upload interaction, and application startup. chatbot/config.py centralizes model identifiers, retrieval/generation settings, device selection, and storage locations. The UI is an adapter: domain retrieval and generation behavior is kept in chatbot/chains.py rather than embedded in interface callbacks.
RAG Orchestration
chatbot/chains.py constructs the retrieval-augmented generation flow: embed a user question, retrieve relevant chunks, format grounded context, and invoke the instruction-tuned LLM. chatbot/models.py loads the Hugging Face LLM and Sentence-Transformer embedding model. This establishes a local/in-Space inference boundary: the application downloads/caches model weights but performs embedding and generation in its Python runtime.
Retrieval and Document Sources
The persistent SEC corpus is a ChromaDB vector collection, expected to be acquired from a Hugging Face dataset and stored locally. chatbot/helpers.py supports document ingestion and utility operations used by the UI/RAG flow, including uploaded-PDF processing. Queries can retrieve from both the persistent SEC store and a transient/per-session uploaded-document index, then combine results before prompting the model.
SEC Corpus Update Pipeline
The sec_risk_factors package is the offline data-ingestion domain. sec_risk_factors/pipeline.py coordinates fetching filings, extracting target content, producing artifacts, and writing searchable records. sec_risk_factors/sec_client.py is the external SEC access boundary; sec_risk_factors/extractors.py isolates 10-K risk-factor extraction from raw filing material.
Storage and Publishing
sec_risk_factors/store.py manages vector-store persistence/updating, while sec_risk_factors/artifacts.py handles produced dataset artifacts. scripts/daily_update_hf.py connects the ingestion pipeline to Hugging Face dataset publication. The GitHub Actions workflow in .github/workflows/daily_update.yml automates this refresh, separating scheduled corpus maintenance from the online chat-serving process.
Runtime and External Dependencies
The primary runtime is Python 3.8+ with LangChain, Gradio, ChromaDB, Transformers/Sentence-Transformers, and PDF extraction dependencies declared in requirements.txt. External services are SEC filing endpoints and Hugging Face for model and vector-dataset distribution. ChromaDB provides local SQLite/HNSW-backed semantic retrieval; CPU is supported, with optional CUDA acceleration.
Main entry points: pipeline.py SEC Ingestion Pipeline · chains.py RAG Chains · app.py Gradio App · daily_update_hf.py Dataset Update Script
Components 17
Interactive RAG
Online chat-serving runtime.
- Gradio App · Owns chat state, uploads, and startup.
chatbot/app.py - Runtime Config
chatbot/config.py - RAG Chains · Embeds questions, retrieves context, and generates answers.
chatbot/chains.py - Local Models · Loads Hugging Face generation and embedding models.
chatbot/models.py - Upload Processing · Processes uploaded PDFs and supports RAG utilities.
chatbot/helpers.py - SEC Vector Collection · Persistent local semantic index of SEC risk factors.
- Session Document Index · Per-session index for uploaded PDFs.
Corpus Refresh
Scheduled SEC ingestion and publication.
- Daily Update Workflow · Schedules corpus refreshes.
.github/workflows/daily_update.yml - Dataset Update Script · Connects ingestion with Hugging Face publication.
scripts/daily_update_hf.py - SEC Ingestion Pipeline · Fetches, extracts, and writes searchable SEC records.
sec_risk_factors/pipeline.py - SEC Client
sec_risk_factors/sec_client.py - Risk Factor Extractor · Isolates 10-K risk-factor disclosures from filings.
sec_risk_factors/extractors.py - Vector Store Writer · Updates persisted vector-store records.
sec_risk_factors/store.py - Dataset Artifacts
sec_risk_factors/artifacts.py
External Systems
- SEC Filing Endpoints
- Hugging Face · Supplies model weights and publishes the vector dataset.
Other components
- Python Dependencies · Declares Python, LangChain, Gradio, ChromaDB, and model dependencies.
requirements.txt
Connections 19
- Gradio App → Runtime Config: reads settings
- Gradio App → RAG Chains: answers questions
- Gradio App → Upload Processing: processes uploads
- RAG Chains → Local Models: embeds and generates
- RAG Chains → SEC Vector Collection: retrieves SEC context
- RAG Chains → Session Document Index: retrieves upload context
- Upload Processing → Session Document Index: indexes PDFs
- Local Models → Hugging Face: downloads weights
- Daily Update Workflow → Dataset Update Script: scheduled trigger
- Dataset Update Script → SEC Ingestion Pipeline: runs ingestion
- Dataset Update Script → Hugging Face: publishes dataset
- SEC Ingestion Pipeline → SEC Client: fetches filings
- SEC Client → SEC Filing Endpoints: requests filings
- SEC Ingestion Pipeline → Risk Factor Extractor: extracts risk factors
- SEC Ingestion Pipeline → Dataset Artifacts: produces artifacts
- SEC Ingestion Pipeline → Vector Store Writer: writes records
- Vector Store Writer → SEC Vector Collection: persists index
- Hugging Face → SEC Vector Collection: distributes corpus
- Python Dependencies → Gradio App: runtime dependencies