How milihwork/document_rag works
Document RAG is a local-first platform for ingesting PDFs or raw text and answering questions with document-grounded responses and source attribution. Users enter through the React UI and Gateway, or AI agents through MCP tools. Ingestion extracts and chunks text, then embeds and stores it; question answering coordinates safeguards, embedding, retrieval, optional rewriting and reranking, ML analysis, and LLM generation. The README documents backend capabilities and integrations beyond the sampled excerpts; edges for those are cited to the README, while uncertain internal wiring is omitted.
Main entry points: app/main.py RAG orchestration · app/main.py Ingestion API · rag_tools.py MCP tools · factory.py ML component factory
Components 23
User interfaces
- React UI
frontend/src/App.tsx - UI API client
frontend/src/api.ts - Express Gateway
backend/services/gateway/src/app.ts - MCP tools
mcp_service/rag_tools.py
Backend services
- Ingestion API
backend/services/ingestion/app/main.py - Embedding API
backend/services/embedding/app/main.py - Retrieval API
backend/services/retrieval/app/main.py - RAG orchestration
backend/services/rag/app/main.py - ML analysis API
backend/services/ml/app/main.py
Quality and safety
- ML component factory
backend/services/ml/app/components/factory.py - Injection detector
backend/services/ml/app/components/injection_detector.py - Query classifier
backend/services/ml/app/components/query_classifier.py - Retrieval scorer
backend/services/ml/app/components/retrieval_scorer.py - Document classifier
backend/services/ml/app/components/document_classifier.py - Input/output safeguards
backend/services/safeguard/basic_guard.py - Query rewriting
backend/shared/query_rewriter/llm_rewriter.py - BGE reranking
backend/shared/reranker/bge_reranker.py
Shared processing
- PDF extraction
backend/shared/pdf_parser.py - Text chunking
backend/shared/chunker.py
AI and storage providers
- Vector database
- LLM provider
Other components
- Document user
- AI agent
Connections 32
- Document user → React UI: asks or uploads
README.md - React UI → UI API client: calls API client
frontend/src/App.tsx - UI API client → Express Gateway: sends requests
README.md - Document user → Express Gateway: uses API
README.md - AI agent → MCP tools: invokes tools
README.md - MCP tools → Ingestion API: posts text
mcp_service/rag_tools.py - MCP tools → Embedding API: embeds search query
mcp_service/rag_tools.py - MCP tools → Retrieval API: searches chunks
mcp_service/rag_tools.py - MCP tools → RAG orchestration: requests answers
mcp_service/rag_tools.py - Express Gateway → Ingestion API: proxies PDF upload
backend/services/gateway/src/app.ts - Express Gateway → RAG orchestration: proxies chat
backend/services/gateway/src/app.ts - Ingestion API → PDF extraction: extracts PDF text
backend/services/ingestion/app/main.py - Ingestion API → Text chunking: chunks text
backend/services/ingestion/app/main.py - Ingestion API → Embedding API: requests embeddings
backend/services/ingestion/app/main.py - Ingestion API → Retrieval API: upserts points
backend/services/ingestion/app/main.py - Ingestion API → ML analysis API: classifies documents
backend/services/ingestion/app/main.py - Embedding API → LLM provider: uses local model
README.md - Retrieval API → Vector database: searches and stores vectors
README.md - RAG orchestration → Embedding API: embeds question
backend/services/rag/app/main.py - RAG orchestration → Retrieval API: searches chunks
backend/services/rag/app/main.py - RAG orchestration → ML analysis API: analyzes and scores
backend/services/rag/app/main.py - RAG orchestration → Input/output safeguards: validates input
backend/services/rag/app/main.py - RAG orchestration → Query rewriting: rewrites query
backend/services/rag/app/main.py - RAG orchestration → BGE reranking: reranks chunks
backend/services/rag/app/main.py - RAG orchestration → LLM provider: generates answer
README.md - ML analysis API → ML component factory: gets analysis components
backend/services/ml/app/main.py - ML component factory → Injection detector: creates detector
backend/services/ml/app/components/factory.py - ML component factory → Query classifier: creates classifier
backend/services/ml/app/components/factory.py - ML component factory → Retrieval scorer: creates scorer
backend/services/ml/app/components/factory.py - ML component factory → Document classifier: creates classifier
backend/services/ml/app/components/factory.py - ML analysis API → LLM provider: uses completion backend
README.md - Input/output safeguards → LLM provider: optional analysis