# ujk768/rag-pipeline-backend architecture

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

- Interactive diagram: https://gitdiagram.com/ujk768/rag-pipeline-backend
- Repository: https://github.com/ujk768/rag-pipeline-backend

## Overview

This is a local PDF RAG API. Users upload a PDF, monitor background ingestion, then query it for grounded answers with page citations; they can also inspect pruning results or reset stored data. The graph preserves ingestion, retrieval, generation, pruning, and operational endpoints. The README documents the query pipeline, while the sampled `main.py` excerpts show database setup, ingestion details, pruning, and API behavior; unsampled query internals are represented only where the README supports them.

Main entry points: [`main.py`](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py) (FastAPI endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Operations"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_status["Processing status<br/>[main.py]"]
  node_reset["Reset data<br/>[main.py]"]
end

subgraph group_ingest["PDF Ingestion"]
  node_pdf["PDF extraction<br/>[main.py]"]
  node_sentence["Sentence chunking<br/>[main.py]"]
  node_embedding["Document embeddings<br/>[main.py]"]
  node_store[("Chunk vector store<br/>[main.py]")]
end

subgraph group_rag["Retrieval and Answers"]
  node_query_embedding["Query embedding<br/>[main.py]"]
  node_search["Similarity search<br/>[main.py]"]
  node_generation["Local LLM generation<br/>[main.py]"]
  node_answer["Cited answer<br/>[main.py]"]
end

subgraph group_prune["Chunk Pruning"]
  node_pruning["Pruning strategies<br/>[main.py]"]
  node_prune_report["Pruning report<br/>[main.py]"]
end

node_user(("User"))
node_postgres[("PostgreSQL pgvector")]

node_user -->|"uploads or queries"| node_api
node_api -->|"starts background ingestion"| node_pdf
node_pdf -->|"extracts and chunks"| node_sentence
node_sentence -->|"embeds chunks"| node_embedding
node_embedding -->|"optionally prunes"| node_pruning
node_pruning -->|"stores kept chunks"| node_store
node_embedding -->|"stores all chunks"| node_store
node_store -->|"persists vectors"| node_postgres
node_api -->|"serves progress"| node_status
node_api -->|"serves report"| node_prune_report
node_pruning -->|"builds statistics"| node_prune_report
node_api -->|"handles query"| node_query_embedding
node_query_embedding -->|"provides query vector"| node_search
node_search -->|"retrieves top chunks"| node_store
node_search -->|"supplies context"| node_generation
node_generation -->|"generates grounded answer"| node_answer
node_api -->|"handles reset"| node_reset
node_reset -->|"deletes chunks"| node_store

click node_api "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_status "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_reset "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_pdf "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_sentence "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_embedding "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_pruning "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_prune_report "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_store "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_query_embedding "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_search "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_generation "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py"
click node_answer "https://github.com/ujk768/rag-pipeline-backend/blob/master/main.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_status,node_reset,node_user toneBlue
class node_pdf,node_sentence,node_embedding,node_store,node_postgres toneAmber
class node_query_embedding,node_search,node_generation,node_answer toneMint
class node_pruning,node_prune_report toneRose
```

## Components

### API and Operations

- [FastAPI endpoints](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Processing status](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Reset data](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`

### PDF Ingestion

- [PDF extraction](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Sentence chunking](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Document embeddings](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Chunk vector store](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`

### Retrieval and Answers

- [Query embedding](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Similarity search](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Local LLM generation](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Cited answer](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`

### Chunk Pruning

- [Pruning strategies](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`
- [Pruning report](https://github.com/ujk768/rag-pipeline-backend/blob/master/main.py): `main.py`

### Other components

- **User**
- **PostgreSQL pgvector**

## Connections

- User → FastAPI endpoints: uploads or queries (evidence: `README.md`)
- FastAPI endpoints → PDF extraction: starts background ingestion (evidence: `main.py`)
- PDF extraction → Sentence chunking: extracts and chunks (evidence: `README.md`)
- Sentence chunking → Document embeddings: embeds chunks (evidence: `README.md`)
- Document embeddings → Pruning strategies: optionally prunes (evidence: `main.py`)
- Pruning strategies → Chunk vector store: stores kept chunks (evidence: `README.md`)
- Document embeddings → Chunk vector store: stores all chunks (evidence: `README.md`)
- Chunk vector store → PostgreSQL pgvector: persists vectors (evidence: `main.py`)
- FastAPI endpoints → Processing status: serves progress (evidence: `main.py`)
- FastAPI endpoints → Pruning report: serves report (evidence: `main.py`)
- Pruning strategies → Pruning report: builds statistics (evidence: `main.py`)
- FastAPI endpoints → Query embedding: handles query (evidence: `README.md`)
- Query embedding → Similarity search: provides query vector (evidence: `README.md`)
- Similarity search → Chunk vector store: retrieves top chunks (evidence: `README.md`)
- Similarity search → Local LLM generation: supplies context (evidence: `README.md`)
- Local LLM generation → Cited answer: generates grounded answer (evidence: `README.md`)
- FastAPI endpoints → Reset data: handles reset (evidence: `main.py`)
- Reset data → Chunk vector store: deletes chunks (evidence: `main.py`)
