# itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform architecture

> Architecture diagram of the GitHub repository itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform
- Repository: https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform

## Overview

Enterprise Knowledge Base is a multi-tenant document ingestion and grounded question-answering service. Companies establish tenant accounts; employees authenticate, upload internal documents, and query their tenant’s corpus for answers with source attribution. The documented ingestion stages extract, chunk, contextualize, embed and index content, with optional entity-graph storage. Query-time retrieval combines reformulated queries, hybrid vector/lexical search and optional GraphRAG before reranking, relevance filtering and generation. The README also describes RAGAS evaluation. Sampled excerpts confirm core retrieval and storage behavior; some API-to-service wiring and evaluation details are unsampled.

Main entry points: [`backend/app/services/ingestion.py`](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/ingestion.py) (Ingestion pipeline), [`backend/app/rag/multi_query.py`](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/multi_query.py) (Query expansion and fusion), [`backend/app/api/auth.py`](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/auth.py) (Authentication), [`backend/app/main.py`](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/main.py) (FastAPI app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Tenant access"]
  node_api["FastAPI app<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_tenant_user["Tenant and user records"]
end

subgraph group_ingestion["Document ingestion"]
  node_documents_api["Document API<br/>[documents.py]"]
  node_storage_service["File storage<br/>[storage.py]"]
  node_ingestion_service["Ingestion pipeline<br/>[ingestion.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_contextualizer["Chunk contextualization<br/>[contextualizer.py]"]
  node_embedder["Dense embeddings<br/>[embedder.py]"]
  node_sparse["Sparse encoding<br/>[sparse.py]"]
  node_graph_extractor["Graph extraction<br/>[graph_extractor.py]"]
end

subgraph group_query["Answer retrieval"]
  node_chats_api["Chat API<br/>[chats.py]"]
  node_generation_service["Answer generation<br/>[generation.py]"]
  node_retrieval_service["Retrieval orchestration<br/>[retrieval.py]"]
  node_multi_query["Query expansion and fusion<br/>[multi_query.py]"]
  node_retriever["Hybrid retrieval<br/>[retriever.py]"]
  node_reranker["Result reranking<br/>[reranker.py]"]
  node_generator["Grounded response<br/>[generator.py]"]
end

subgraph group_state["Platform state"]
  node_postgres[("PostgreSQL")]
  node_qdrant[("Qdrant index")]
  node_neo4j[("Neo4j graph")]
  node_local_files[("Tenant document files")]
end

subgraph group_evaluation["Quality evaluation"]
  node_eval_api["Evaluation API<br/>[eval.py]"]
  node_eval_runner["RAGAS evaluation runner<br/>[run_eval.py]"]
  node_golden_data["Golden dataset"]
  node_eval_record["Evaluation run records<br/>[eval_run.py]"]
end

node_company(("Company admin"))
node_employee(("Employee"))
node_nim{{"NVIDIA NIM"}}

node_company -->|"signs up"| node_auth
node_employee -->|"authenticates"| node_auth
node_api -->|"registers routes"| node_auth
node_api -->|"registers routes"| node_documents_api
node_api -->|"registers routes"| node_chats_api
node_api -->|"registers routes"| node_eval_api
node_auth -->|"creates and reads"| node_tenant_user
node_auth -->|"persists accounts"| node_postgres
node_employee -->|"uploads documents"| node_documents_api
node_documents_api -->|"stores files"| node_storage_service
node_storage_service -->|"writes files"| node_local_files
node_documents_api -->|"schedules ingestion"| node_ingestion_service
node_ingestion_service -->|"reads files"| node_storage_service
node_ingestion_service -->|"chunks text"| node_chunker
node_ingestion_service -->|"adds context"| node_contextualizer
node_ingestion_service -->|"embeds chunks"| node_embedder
node_ingestion_service -->|"encodes chunks"| node_sparse
node_ingestion_service -->|"upserts vectors"| node_qdrant
node_ingestion_service -.->|"extracts entities"| node_graph_extractor
node_graph_extractor -.->|"requests extraction"| node_nim
node_ingestion_service -.->|"stores graph"| node_neo4j
node_ingestion_service -->|"updates status"| node_postgres
node_employee -->|"asks questions"| node_chats_api
node_chats_api -->|"requests answer"| node_generation_service
node_generation_service -->|"requests context"| node_retrieval_service
node_retrieval_service -->|"retrieves candidates"| node_multi_query
node_multi_query -->|"generates variants"| node_nim
node_multi_query -->|"searches variants"| node_retriever
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"encodes query"| node_sparse
node_retriever -->|"searches tenant index"| node_qdrant
node_multi_query -.->|"traverses entities"| node_neo4j
node_multi_query -.->|"fetches graph chunks"| node_qdrant
node_retrieval_service -->|"reranks candidates"| node_reranker
node_generation_service -->|"generates response"| node_generator
node_generator -->|"requests completion"| node_nim
node_chats_api -->|"stores chat records"| node_postgres
node_employee -->|"requests evaluation"| node_eval_api
node_eval_runner -->|"loads questions"| node_golden_data
node_eval_runner -->|"runs retrieval"| node_multi_query
node_eval_runner -->|"reranks results"| node_reranker
node_eval_runner -->|"stores metrics"| node_postgres
node_eval_api -->|"manages runs"| node_eval_record
node_eval_record -->|"persists results"| node_postgres

click node_api "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/main.py"
click node_auth "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/auth.py"
click node_tenant_user "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/tree/main/backend/app/models"
click node_documents_api "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/documents.py"
click node_storage_service "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/storage.py"
click node_ingestion_service "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/ingestion.py"
click node_chunker "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/chunker.py"
click node_contextualizer "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/contextualizer.py"
click node_embedder "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/embedder.py"
click node_sparse "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/sparse.py"
click node_graph_extractor "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/graph_extractor.py"
click node_chats_api "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/chats.py"
click node_generation_service "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/generation.py"
click node_retrieval_service "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/retrieval.py"
click node_multi_query "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/multi_query.py"
click node_retriever "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/retriever.py"
click node_reranker "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/reranker.py"
click node_generator "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/generator.py"
click node_eval_api "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/eval.py"
click node_eval_runner "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/eval/run_eval.py"
click node_golden_data "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/eval/golden_dataset.json"
click node_eval_record "https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/models/eval_run.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_api,node_auth,node_tenant_user toneBlue
class node_documents_api,node_storage_service,node_ingestion_service,node_chunker,node_contextualizer,node_embedder,node_sparse,node_graph_extractor toneAmber
class node_chats_api,node_generation_service,node_retrieval_service,node_multi_query,node_retriever,node_reranker,node_generator toneMint
class node_postgres,node_qdrant,node_neo4j,node_local_files toneRose
class node_eval_api,node_eval_runner,node_golden_data,node_eval_record,node_company,node_employee,node_nim toneIndigo
```

## Components

### Tenant access

- [FastAPI app](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Tenant and user records](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/tree/main/backend/app/models): `backend/app/models`

### Document ingestion

- [Document API](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/documents.py): `backend/app/api/documents.py`
- [File storage](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- [Ingestion pipeline](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/ingestion.py): `backend/app/services/ingestion.py`
- [Text chunking](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/chunker.py): `backend/app/rag/chunker.py`
- [Chunk contextualization](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/contextualizer.py): `backend/app/rag/contextualizer.py`
- [Dense embeddings](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/embedder.py): `backend/app/rag/embedder.py`
- [Sparse encoding](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/sparse.py): `backend/app/rag/sparse.py`
- [Graph extraction](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/graph_extractor.py): `backend/app/rag/graph_extractor.py`

### Answer retrieval

- [Chat API](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/chats.py): `backend/app/api/chats.py`
- [Answer generation](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/generation.py): `backend/app/services/generation.py`
- [Retrieval orchestration](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/services/retrieval.py): `backend/app/services/retrieval.py`
- [Query expansion and fusion](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/multi_query.py): `backend/app/rag/multi_query.py`
- [Hybrid retrieval](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/retriever.py): `backend/app/rag/retriever.py`
- [Result reranking](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/reranker.py): `backend/app/rag/reranker.py`
- [Grounded response](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/rag/generator.py): `backend/app/rag/generator.py`

### Platform state

- **PostgreSQL**
- **Qdrant index**
- **Neo4j graph**
- **Tenant document files**

### Quality evaluation

- [Evaluation API](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/api/eval.py): `backend/app/api/eval.py`
- [RAGAS evaluation runner](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/eval/run_eval.py): `eval/run_eval.py`
- [Golden dataset](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/eval/golden_dataset.json): `eval/golden_dataset.json`
- [Evaluation run records](https://github.com/itachi5747/multi-tenant-enterprise-knowledge-base-rag-platform/blob/main/backend/app/models/eval_run.py): `backend/app/models/eval_run.py`

### Other components

- **Company admin**
- **Employee**
- **NVIDIA NIM**

## Connections

- Company admin → Authentication: signs up
- Employee → Authentication: authenticates
- FastAPI app → Authentication: registers routes
- FastAPI app → Document API: registers routes
- FastAPI app → Chat API: registers routes
- FastAPI app → Evaluation API: registers routes
- Authentication → Tenant and user records: creates and reads
- Authentication → PostgreSQL: persists accounts
- Employee → Document API: uploads documents
- Document API → File storage: stores files
- File storage → Tenant document files: writes files
- Document API → Ingestion pipeline: schedules ingestion
- Ingestion pipeline → File storage: reads files
- Ingestion pipeline → Text chunking: chunks text
- Ingestion pipeline → Chunk contextualization: adds context
- Ingestion pipeline → Dense embeddings: embeds chunks
- Ingestion pipeline → Sparse encoding: encodes chunks
- Ingestion pipeline → Qdrant index: upserts vectors
- Ingestion pipeline → Graph extraction: extracts entities
- Graph extraction → NVIDIA NIM: requests extraction
- Ingestion pipeline → Neo4j graph: stores graph
- Ingestion pipeline → PostgreSQL: updates status
- Employee → Chat API: asks questions
- Chat API → Answer generation: requests answer
- Answer generation → Retrieval orchestration: requests context
- Retrieval orchestration → Query expansion and fusion: retrieves candidates
- Query expansion and fusion → NVIDIA NIM: generates variants
- Query expansion and fusion → Hybrid retrieval: searches variants
- Hybrid retrieval → Dense embeddings: embeds query
- Hybrid retrieval → Sparse encoding: encodes query
- Hybrid retrieval → Qdrant index: searches tenant index
- Query expansion and fusion → Neo4j graph: traverses entities
- Query expansion and fusion → Qdrant index: fetches graph chunks
- Retrieval orchestration → Result reranking: reranks candidates
- Answer generation → Grounded response: generates response
- Grounded response → NVIDIA NIM: requests completion
- Chat API → PostgreSQL: stores chat records
- Employee → Evaluation API: requests evaluation
- RAGAS evaluation runner → Golden dataset: loads questions
- RAGAS evaluation runner → Query expansion and fusion: runs retrieval
- RAGAS evaluation runner → Result reranking: reranks results
- RAGAS evaluation runner → PostgreSQL: stores metrics
- Evaluation API → Evaluation run records: manages runs
- Evaluation run records → PostgreSQL: persists results
