# ritiksontakke/multi-model-rag architecture

> Architecture diagram of the GitHub repository ritiksontakke/multi-model-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ritiksontakke/multi-model-rag
- Repository: https://github.com/ritiksontakke/multi-model-rag

## Overview

#### 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: [`src/main.py`](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/main.py) (FastAPI ASGI app), [`src/agents/Orchestrator_Agent.py`](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/Orchestrator_Agent.py) (Orchestrator agent), [`src/api/v1/auth.py`](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/api/v1/auth.py) (Versioned routes), [`src/tools/upload_document.py`](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/tools/upload_document.py) (Upload document tool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP &amp; Identity"]
  node_frontend["Static demo frontend"]
  node_main["FastAPI ASGI app<br/>api runtime<br/>[main.py]"]
  node_routes["Versioned routes<br/>HTTP endpoints<br/>[auth.py]"]
  node_auth["Auth service &amp; JWT<br/>identity service<br/>[auth_handler.py]"]
  node_users["User repository<br/>persistence layer<br/>[user_repository.py]"]
end

subgraph group_agents["Agents &amp; Policy"]
  node_permissions["RBAC permission manager<br/>authorization"]
  node_tool_registry["Tool registry<br/>capability boundary<br/>[tool_registry.py]"]
  node_orchestrator["Orchestrator agent<br/>agent router"]
  node_knowledge_agent["Knowledge agent<br/>specialized agent<br/>[knowledge_agent.py]"]
  node_document_agent["Document management agent<br/>specialized agent"]
  node_upload_tool["Upload document tool<br/>agent tool<br/>[upload_document.py]"]
  node_search_tool["Search documents tool<br/>agent tool"]
end

subgraph group_rag["RAG Pipeline"]
  node_ingestion["PDF ingestion pipeline<br/>RAG ingestion<br/>[pipeline.py]"]
  node_retrieval["Retrieval pipeline<br/>RAG retrieval<br/>[pipeline.py]"]
  node_generation["Answer generator<br/>grounded generation<br/>[generator.py]"]
end

subgraph group_data["Data &amp; External Services"]
  node_postgres[("PostgreSQL<br/>user database<br/>[database.py]")]
  node_qdrant[("Qdrant company_documents<br/>vector store<br/>[qdrant_store.py]")]
  node_openai{{"OpenAI<br/>LLM provider"}}
  node_langfuse{{"Langfuse<br/>observability"}}
  node_config["Runtime configuration<br/>[config.py]"]
end

node_frontend -->|"HTTP requests"| node_main
node_main -->|"mounts"| node_routes
node_routes -->|"signup and login"| node_auth
node_auth -->|"user persistence"| node_users
node_users -->|"SQLAlchemy"| node_postgres
node_routes -->|"authenticated intent + context"| node_orchestrator
node_orchestrator -->|"authorizes actions"| node_permissions
node_permissions -->|"selects allowed tools"| node_tool_registry
node_orchestrator -->|"knowledge requests"| node_knowledge_agent
node_orchestrator -->|"document actions"| node_document_agent
node_knowledge_agent -->|"uses"| node_search_tool
node_document_agent -->|"uses"| node_upload_tool
node_upload_tool -.->|"rechecks access"| node_permissions
node_upload_tool -->|"authorized PDF"| node_ingestion
node_ingestion -->|"chunk embeddings + metadata"| node_qdrant
node_search_tool -->|"department-scoped query"| node_retrieval
node_retrieval -->|"filtered similarity search"| node_qdrant
node_retrieval -->|"retrieved content"| node_generation
node_generation -->|"chat completion"| node_openai
node_ingestion -->|"embeddings"| node_openai
node_main -->|"loads"| node_config
node_main -.->|"tracing"| node_langfuse

click node_main "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/main.py"
click node_routes "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/api/v1/auth.py"
click node_auth "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/auth/auth_handler.py"
click node_users "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/repositories/user_repository.py"
click node_permissions "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/access_control/permission_manager.py"
click node_tool_registry "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/access_control/tool_registry.py"
click node_orchestrator "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/Orchestrator_Agent.py"
click node_knowledge_agent "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/knowledge_agent.py"
click node_document_agent "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/document_management_agent.py"
click node_upload_tool "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/tools/upload_document.py"
click node_search_tool "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/tools/search_documents.py"
click node_ingestion "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/ingestion/pipeline.py"
click node_retrieval "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/retrieval/pipeline.py"
click node_generation "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/generation/generator.py"
click node_postgres "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/db/database.py"
click node_qdrant "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/ingestion/qdrant_store.py"
click node_config "https://github.com/ritiksontakke/multi-model-rag/blob/main/src/core/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend,node_main,node_routes,node_auth,node_users toneBlue
class node_permissions,node_tool_registry,node_orchestrator,node_knowledge_agent,node_document_agent,node_upload_tool,node_search_tool toneAmber
class node_ingestion,node_retrieval,node_generation toneMint
class node_postgres,node_qdrant,node_openai,node_langfuse,node_config toneRose
```

## Components

### HTTP & Identity

- **Static demo frontend**: frontend
- [FastAPI ASGI app](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/main.py): api runtime · Initializes database and vector services. · `src/main.py`
- [Versioned routes](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/api/v1/auth.py): HTTP endpoints · Auth, document, and knowledge endpoints. · `src/api/v1/auth.py`
- [Auth service & JWT](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/auth/auth_handler.py): identity service · `src/auth/auth_handler.py`
- [User repository](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/repositories/user_repository.py): persistence layer · Stores users, roles, and departments. · `src/repositories/user_repository.py`

### Agents & Policy

- [RBAC permission manager](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/access_control/permission_manager.py): authorization · Enforces role and department access. · `src/access_control/permission_manager.py`
- [Tool registry](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/access_control/tool_registry.py): capability boundary · Controls tools available to each principal. · `src/access_control/tool_registry.py`
- [Orchestrator agent](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/Orchestrator_Agent.py): agent router · Routes authenticated intent to specialized agents. · `src/agents/Orchestrator_Agent.py`
- [Knowledge agent](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/knowledge_agent.py): specialized agent · `src/agents/knowledge_agent.py`
- [Document management agent](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/agents/document_management_agent.py): specialized agent · `src/agents/document_management_agent.py`
- [Upload document tool](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/tools/upload_document.py): agent tool · Rechecks sensitive upload authorization. · `src/tools/upload_document.py`
- [Search documents tool](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/tools/search_documents.py): agent tool · `src/tools/search_documents.py`

### RAG Pipeline

- [PDF ingestion pipeline](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/ingestion/pipeline.py): RAG ingestion · Loads, chunks, embeds, and persists authorized PDFs. · `src/rag/ingestion/pipeline.py`
- [Retrieval pipeline](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/retrieval/pipeline.py): RAG retrieval · Embeds queries and applies department-filtered relevance search. · `src/rag/retrieval/pipeline.py`
- [Answer generator](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/generation/generator.py): grounded generation · Answers only from retrieved content or returns the not-found fallback. · `src/rag/generation/generator.py`

### Data & External Services

- [PostgreSQL](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/db/database.py): user database · `src/db/database.py`
- [Qdrant company_documents](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/rag/ingestion/qdrant_store.py): vector store · Stores 384-dimensional embeddings and department metadata. · `src/rag/ingestion/qdrant_store.py`
- **OpenAI**: LLM provider · Provides chat generation and embeddings.
- **Langfuse**: observability · Supplies prompts and tracing.
- [Runtime configuration](https://github.com/ritiksontakke/multi-model-rag/blob/main/src/core/config.py): configuration · Centralizes environment integration. · `src/core/config.py`

## Connections

- 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
