# sytrox918/m-rag architecture

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

- Interactive diagram: https://gitdiagram.com/sytrox918/m-rag
- Repository: https://github.com/sytrox918/m-rag

## Overview

This is an educational multimodal RAG tutor: users ingest PDFs, PowerPoints, or YouTube videos, then ask grounded questions or explore prerequisite learning paths. Ingestion extracts text and visual assets, enriches content with vision and learning metadata, embeds it, and persists it for hybrid retrieval. The tutor rewrites follow-ups, retrieves and reranks evidence, checks grounding, generates structured answers, and validates citations. The README also documents GPU inference and interactive knowledge-graph visualization. Some subsystem links rely on README descriptions or index references; unsampled implementation details are not inferred.

Main entry points: [`services/ingestion_service.py`](https://github.com/sytrox918/m-rag/blob/main/services/ingestion_service.py) (Ingestion Orchestrator), [`rag/chain.py`](https://github.com/sytrox918/m-rag/blob/main/rag/chain.py) (RAG Chain), [`rag/retriever.py`](https://github.com/sytrox918/m-rag/blob/main/rag/retriever.py) (Hybrid Retriever), [`app.py`](https://github.com/sytrox918/m-rag/blob/main/app.py) (Streamlit Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User Interfaces"]
  node_streamlit["Streamlit Dashboard<br/>[app.py]"]
  node_api["API Entry<br/>[main.py]"]
end

subgraph group_ingestion["Content Ingestion"]
  node_ingest["Ingestion Orchestrator"]
  node_pdf["PDF Parser<br/>[parser.py]"]
  node_pptx["PowerPoint Parser<br/>[parser.py]"]
  node_video["Video Parser<br/>[parser.py]"]
  node_units["Content Units<br/>[content_units.py]"]
end

subgraph group_enrichment["Content Enrichment"]
  node_vlm["Vision Processing<br/>[vlm_service.py]"]
  node_metadata["Topic Metadata"]
  node_embed["Embedding Service"]
end

subgraph group_learning["Tutor And Learning Graph"]
  node_graph["Prerequisite Graph<br/>[graph_service.py]"]
  node_answer_service["Answer Service<br/>[answer_service.py]"]
  node_chain["RAG Chain<br/>[chain.py]"]
  node_grounding["Grounding Check<br/>[grounding.py]"]
  node_citations["Citation Validation<br/>[citations.py]"]
end

subgraph group_data["Retrieval And Storage"]
  node_retriever["Hybrid Retriever<br/>[retriever.py]"]
  node_dense["Dense Retrieval<br/>[dense.py]"]
  node_sparse["Sparse Retrieval<br/>[sparse.py]"]
  node_fusion["Rank Fusion<br/>[fusion.py]"]
  node_reranker["Cross-Encoder Reranker"]
  node_store["Vector Store<br/>[vector_store.py]"]
  node_postgres[("Postgres Database<br/>[postgres.py]")]
end

node_learner(("Learner"))
node_llm["Answer Model"]
node_vision_api["Gemini Vision"]

node_learner -->|"uses"| node_streamlit
node_learner -.->|"requests"| node_api
node_streamlit -->|"submits media"| node_ingest
node_streamlit -->|"asks questions"| node_answer_service
node_streamlit -->|"requests learning path"| node_graph
node_api -->|"routes ingestion"| node_ingest
node_api -->|"routes questions"| node_answer_service
node_api -->|"routes graph requests"| node_graph
node_ingest -->|"parses PDFs"| node_pdf
node_ingest -->|"parses slides"| node_pptx
node_ingest -->|"parses videos"| node_video
node_pdf -->|"creates units"| node_units
node_pptx -->|"creates units"| node_units
node_video -->|"creates units"| node_units
node_ingest -->|"describes assets"| node_vlm
node_ingest -->|"enriches units"| node_metadata
node_ingest -->|"embeds text"| node_embed
node_ingest -->|"saves units"| node_store
node_vlm -.->|"analyzes visuals"| node_vision_api
node_store -->|"writes records"| node_postgres
node_graph -->|"reads units"| node_postgres
node_answer_service -->|"runs answers"| node_chain
node_chain -->|"retrieves evidence"| node_retriever
node_retriever -->|"runs dense search"| node_dense
node_retriever -->|"runs sparse search"| node_sparse
node_retriever -->|"fuses results"| node_fusion
node_retriever -->|"reranks candidates"| node_reranker
node_dense -->|"embeds query"| node_embed
node_dense -->|"searches vectors"| node_postgres
node_sparse -->|"searches text"| node_postgres
node_chain -->|"checks evidence"| node_grounding
node_chain -.->|"generates answer"| node_llm
node_chain -->|"validates claims"| node_citations

click node_streamlit "https://github.com/sytrox918/m-rag/blob/main/app.py"
click node_api "https://github.com/sytrox918/m-rag/blob/main/api/main.py"
click node_ingest "https://github.com/sytrox918/m-rag/blob/main/services/ingestion_service.py"
click node_pdf "https://github.com/sytrox918/m-rag/blob/main/ingestion/pdf/parser.py"
click node_pptx "https://github.com/sytrox918/m-rag/blob/main/ingestion/pptx/parser.py"
click node_video "https://github.com/sytrox918/m-rag/blob/main/ingestion/video/parser.py"
click node_units "https://github.com/sytrox918/m-rag/blob/main/ingestion/common/content_units.py"
click node_vlm "https://github.com/sytrox918/m-rag/blob/main/services/vlm_service.py"
click node_metadata "https://github.com/sytrox918/m-rag/blob/main/services/metadata_service.py"
click node_embed "https://github.com/sytrox918/m-rag/blob/main/services/embedding_service.py"
click node_graph "https://github.com/sytrox918/m-rag/blob/main/services/graph_service.py"
click node_answer_service "https://github.com/sytrox918/m-rag/blob/main/services/answer_service.py"
click node_chain "https://github.com/sytrox918/m-rag/blob/main/rag/chain.py"
click node_grounding "https://github.com/sytrox918/m-rag/blob/main/rag/grounding.py"
click node_citations "https://github.com/sytrox918/m-rag/blob/main/rag/citations.py"
click node_retriever "https://github.com/sytrox918/m-rag/blob/main/rag/retriever.py"
click node_dense "https://github.com/sytrox918/m-rag/blob/main/retrieval/dense.py"
click node_sparse "https://github.com/sytrox918/m-rag/blob/main/retrieval/sparse.py"
click node_fusion "https://github.com/sytrox918/m-rag/blob/main/retrieval/fusion.py"
click node_reranker "https://github.com/sytrox918/m-rag/blob/main/services/reranker_service.py"
click node_store "https://github.com/sytrox918/m-rag/blob/main/storage/vector_store.py"
click node_postgres "https://github.com/sytrox918/m-rag/blob/main/storage/postgres.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_streamlit,node_api toneBlue
class node_ingest,node_pdf,node_pptx,node_video,node_units toneAmber
class node_vlm,node_metadata,node_embed toneMint
class node_graph,node_answer_service,node_chain,node_grounding,node_citations toneRose
class node_retriever,node_dense,node_sparse,node_fusion,node_reranker,node_store,node_postgres,node_learner,node_llm,node_vision_api toneIndigo
```

## Components

### User Interfaces

- [Streamlit Dashboard](https://github.com/sytrox918/m-rag/blob/main/app.py): `app.py`
- [API Entry](https://github.com/sytrox918/m-rag/blob/main/api/main.py): `api/main.py`

### Content Ingestion

- [Ingestion Orchestrator](https://github.com/sytrox918/m-rag/blob/main/services/ingestion_service.py): `services/ingestion_service.py`
- [PDF Parser](https://github.com/sytrox918/m-rag/blob/main/ingestion/pdf/parser.py): `ingestion/pdf/parser.py`
- [PowerPoint Parser](https://github.com/sytrox918/m-rag/blob/main/ingestion/pptx/parser.py): `ingestion/pptx/parser.py`
- [Video Parser](https://github.com/sytrox918/m-rag/blob/main/ingestion/video/parser.py): `ingestion/video/parser.py`
- [Content Units](https://github.com/sytrox918/m-rag/blob/main/ingestion/common/content_units.py): `ingestion/common/content_units.py`

### Content Enrichment

- [Vision Processing](https://github.com/sytrox918/m-rag/blob/main/services/vlm_service.py): `services/vlm_service.py`
- [Topic Metadata](https://github.com/sytrox918/m-rag/blob/main/services/metadata_service.py): `services/metadata_service.py`
- [Embedding Service](https://github.com/sytrox918/m-rag/blob/main/services/embedding_service.py): `services/embedding_service.py`

### Tutor And Learning Graph

- [Prerequisite Graph](https://github.com/sytrox918/m-rag/blob/main/services/graph_service.py): `services/graph_service.py`
- [Answer Service](https://github.com/sytrox918/m-rag/blob/main/services/answer_service.py): `services/answer_service.py`
- [RAG Chain](https://github.com/sytrox918/m-rag/blob/main/rag/chain.py): `rag/chain.py`
- [Grounding Check](https://github.com/sytrox918/m-rag/blob/main/rag/grounding.py): `rag/grounding.py`
- [Citation Validation](https://github.com/sytrox918/m-rag/blob/main/rag/citations.py): `rag/citations.py`

### Retrieval And Storage

- [Hybrid Retriever](https://github.com/sytrox918/m-rag/blob/main/rag/retriever.py): `rag/retriever.py`
- [Dense Retrieval](https://github.com/sytrox918/m-rag/blob/main/retrieval/dense.py): `retrieval/dense.py`
- [Sparse Retrieval](https://github.com/sytrox918/m-rag/blob/main/retrieval/sparse.py): `retrieval/sparse.py`
- [Rank Fusion](https://github.com/sytrox918/m-rag/blob/main/retrieval/fusion.py): `retrieval/fusion.py`
- [Cross-Encoder Reranker](https://github.com/sytrox918/m-rag/blob/main/services/reranker_service.py): `services/reranker_service.py`
- [Vector Store](https://github.com/sytrox918/m-rag/blob/main/storage/vector_store.py): `storage/vector_store.py`
- [Postgres Database](https://github.com/sytrox918/m-rag/blob/main/storage/postgres.py): `storage/postgres.py`

### Other components

- **Learner**
- **Answer Model**
- **Gemini Vision**

## Connections

- Learner → Streamlit Dashboard: uses (evidence: `README.md`)
- Learner → API Entry: requests
- Streamlit Dashboard → Ingestion Orchestrator: submits media (evidence: `app.py`)
- Streamlit Dashboard → Answer Service: asks questions (evidence: `app.py`)
- Streamlit Dashboard → Prerequisite Graph: requests learning path (evidence: `app.py`)
- API Entry → Ingestion Orchestrator: routes ingestion (evidence: `api/main.py`)
- API Entry → Answer Service: routes questions (evidence: `api/main.py`)
- API Entry → Prerequisite Graph: routes graph requests (evidence: `api/main.py`)
- Ingestion Orchestrator → PDF Parser: parses PDFs (evidence: `services/ingestion_service.py`)
- Ingestion Orchestrator → PowerPoint Parser: parses slides (evidence: `services/ingestion_service.py`)
- Ingestion Orchestrator → Video Parser: parses videos (evidence: `services/ingestion_service.py`)
- PDF Parser → Content Units: creates units (evidence: `ingestion/pdf/parser.py`)
- PowerPoint Parser → Content Units: creates units (evidence: `ingestion/pptx/parser.py`)
- Video Parser → Content Units: creates units (evidence: `ingestion/video/parser.py`)
- Ingestion Orchestrator → Vision Processing: describes assets (evidence: `services/ingestion_service.py`)
- Ingestion Orchestrator → Topic Metadata: enriches units (evidence: `services/ingestion_service.py`)
- Ingestion Orchestrator → Embedding Service: embeds text (evidence: `services/ingestion_service.py`)
- Ingestion Orchestrator → Vector Store: saves units (evidence: `services/ingestion_service.py`)
- Vision Processing → Gemini Vision: analyzes visuals (evidence: `README.md`)
- Vector Store → Postgres Database: writes records (evidence: `storage/vector_store.py`)
- Prerequisite Graph → Postgres Database: reads units (evidence: `services/graph_service.py`)
- Answer Service → RAG Chain: runs answers (evidence: `services/answer_service.py`)
- RAG Chain → Hybrid Retriever: retrieves evidence (evidence: `rag/chain.py`)
- Hybrid Retriever → Dense Retrieval: runs dense search (evidence: `rag/retriever.py`)
- Hybrid Retriever → Sparse Retrieval: runs sparse search (evidence: `rag/retriever.py`)
- Hybrid Retriever → Rank Fusion: fuses results (evidence: `rag/retriever.py`)
- Hybrid Retriever → Cross-Encoder Reranker: reranks candidates (evidence: `rag/retriever.py`)
- Dense Retrieval → Embedding Service: embeds query (evidence: `retrieval/dense.py`)
- Dense Retrieval → Postgres Database: searches vectors (evidence: `retrieval/dense.py`)
- Sparse Retrieval → Postgres Database: searches text (evidence: `retrieval/sparse.py`)
- RAG Chain → Grounding Check: checks evidence (evidence: `rag/chain.py`)
- RAG Chain → Answer Model: generates answer
- RAG Chain → Citation Validation: validates claims (evidence: `rag/chain.py`)
