How ritiksontakke/multi-model-rag works
Purpose and Entry Points
This is a FastAPI backend for a department-isolated company knowledge assistant. It authenticates users, ingests authorized PDF documents into a vector store, and answers knowledge queries through LangChain agents and RAG. The ASGI entry point is src/main.py; versioned HTTP routes are in src/api/v1/auth.py, src/api/v1/documents.py, and src/api/v1/knowledge.py. A separate static/demo frontend exists under frontend/.
API, Authentication, and User Persistence
Auth endpoints implement signup and OAuth2 password-flow login, producing JWT bearer tokens. User services/repositories separate business and persistence concerns, while SQLAlchemy stores users with role and department attributes in PostgreSQL.
• src/auth/auth_handler.py
• src/services/auth_service.py
• src/repositories/user_repository.py
• src/db/database.py
Authorization and Tenant Boundary
RBAC controls which operations each employee, manager, or admin may invoke. Department is the principal tenant boundary: uploads must match the authenticated department, and retrieval/document operations are constrained to it. Permission checks occur during agent tool selection and again in sensitive tools.
• src/access_control/permission_manager.py
• src/access_control/tool_registry.py
• src/access_control/permission.py
Agent Orchestration and Tool Boundary
The API passes authenticated user context and request intent to an orchestrator agent. It delegates knowledge questions, document-management actions, and uploads to specialized agents. Agents act through tool modules rather than directly exposing storage operations; this is the principal policy and capability boundary.
• src/agents/Orchestrator_Agent.py
• src/agents/knowledge_agent.py
• src/agents/document_management_agent.py
• src/tools/search_documents.py
• src/tools/upload_document.py
Document Ingestion Pipeline
Authorized PDF upload reaches the upload tool, which drives loading, chunking, embedding, and vector persistence. Qdrant records chunks plus source, page, uploader, and department metadata. Temporary API-upload files are cleaned after processing.
• src/rag/ingestion/pipeline.py
• src/rag/ingestion/loader.py
• src/rag/ingestion/chunker.py
• src/rag/ingestion/embedder.py
• src/rag/ingestion/qdrant_store.py
Retrieval and Answer Generation
For knowledge requests, the system embeds the query, searches Qdrant’s company_documents collection with a department filter, applies the configured relevance threshold, then generates an answer constrained to retrieved content. The generator is responsible for the “not found in company documents” fallback behavior.
• src/rag/retrieval/pipeline.py
• src/rag/retrieval/qdrant_search.py
• src/rag/generation/pipeline.py
• src/rag/generation/generator.py
Runtime and External Dependencies
The runtime is FastAPI/Uvicorn with Pydantic and SQLAlchemy. PostgreSQL holds user identities; Qdrant holds 384-dimensional BAAI/bge-small-en-v1.5 embeddings and payload indexes. OpenAI supplies chat generation (configured model noted as gpt-5.4-nano); Langfuse supplies prompt retrieval and tracing. Configuration/environment integration is centralized in src/core/config.py; startup database/vector initialization is under src/db/init_db.py and src/main.py.
Main entry points: main.py FastAPI ASGI app · Orchestrator_Agent.py Orchestrator agent · auth.py Versioned routes · upload_document.py Upload document tool
Components 20
HTTP & Identity
- Static demo frontend
- FastAPI ASGI app · Initializes database and vector services.
src/main.py - Versioned routes · Auth, document, and knowledge endpoints.
src/api/v1/auth.py - Auth service & JWT
src/auth/auth_handler.py - User repository · Stores users, roles, and departments.
src/repositories/user_repository.py
Agents & Policy
- RBAC permission manager · Enforces role and department access.
src/access_control/permission_manager.py - Tool registry · Controls tools available to each principal.
src/access_control/tool_registry.py - Orchestrator agent · Routes authenticated intent to specialized agents.
src/agents/Orchestrator_Agent.py - Knowledge agent
src/agents/knowledge_agent.py - Document management agent
src/agents/document_management_agent.py - Upload document tool · Rechecks sensitive upload authorization.
src/tools/upload_document.py - Search documents tool
src/tools/search_documents.py
RAG Pipeline
- PDF ingestion pipeline · Loads, chunks, embeds, and persists authorized PDFs.
src/rag/ingestion/pipeline.py - Retrieval pipeline · Embeds queries and applies department-filtered relevance search.
src/rag/retrieval/pipeline.py - Answer generator · Answers only from retrieved content or returns the not-found fallback.
src/rag/generation/generator.py
Data & External Services
- PostgreSQL
src/db/database.py - Qdrant company_documents · Stores 384-dimensional embeddings and department metadata.
src/rag/ingestion/qdrant_store.py - OpenAI · Provides chat generation and embeddings.
- Langfuse · Supplies prompts and tracing.
- Runtime configuration · Centralizes environment integration.
src/core/config.py
Connections 22
- Static demo frontend → FastAPI ASGI app: HTTP requests
- FastAPI ASGI app → Versioned routes: mounts
- Versioned routes → Auth service & JWT: signup and login
- Auth service & JWT → User repository: user persistence
- User repository → PostgreSQL: SQLAlchemy
- Versioned routes → Orchestrator agent: authenticated intent + context
- Orchestrator agent → RBAC permission manager: authorizes actions
- RBAC permission manager → Tool registry: selects allowed tools
- Orchestrator agent → Knowledge agent: knowledge requests
- Orchestrator agent → Document management agent: document actions
- Knowledge agent → Search documents tool: uses
- Document management agent → Upload document tool: uses
- Upload document tool → RBAC permission manager: rechecks access
- Upload document tool → PDF ingestion pipeline: authorized PDF
- PDF ingestion pipeline → Qdrant company_documents: chunk embeddings + metadata
- Search documents tool → Retrieval pipeline: department-scoped query
- Retrieval pipeline → Qdrant company_documents: filtered similarity search
- Retrieval pipeline → Answer generator: retrieved content
- Answer generator → OpenAI: chat completion
- PDF ingestion pipeline → OpenAI: embeddings
- FastAPI ASGI app → Runtime configuration: loads
- FastAPI ASGI app → Langfuse: tracing