# sgundala/rag-101 architecture

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

- Interactive diagram: https://gitdiagram.com/sgundala/rag-101
- Repository: https://github.com/sgundala/rag-101

## Overview

RAG 101 builds a document index offline, then answers questions online using that persisted index. Ingest loads supported files, cleans and chunks their text, embeds the chunks, and stores vectors with source metadata. For each question, retrieval embeds the query and searches the same store; augmentation adds retrieved context and citation labels to a grounded prompt, which generation sends to a configurable LLM. The graph shows the local index and optional pgvector backend. Relationships follow the README and excerpted calls; unsampled details are omitted.

Main entry points: [`ingest.py`](https://github.com/sgundala/rag-101/blob/main/ingest.py) (Ingest runner), [`ask.py`](https://github.com/sgundala/rag-101/blob/main/ask.py) (Ask runner), [`step5_store.py`](https://github.com/sgundala/rag-101/blob/main/step5_store.py) (Store interface), [`config.py`](https://github.com/sgundala/rag-101/blob/main/config.py) (Pipeline settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Offline ingestion"]
  node_ingest["Ingest runner<br/>[ingest.py]"]
  node_loader["File loader<br/>[step1_load.py]"]
  node_cleaner["Text cleaning<br/>[step2_clean.py]"]
  node_chunker["Token chunking<br/>[step3_chunk.py]"]
end

subgraph group_retrieval["Online retrieval"]
  node_ask["Ask runner<br/>[ask.py]"]
  node_retriever["Chunk retrieval<br/>[step6_search.py]"]
end

subgraph group_answering["Grounded answering"]
  node_augmenter["Prompt grounding<br/>[step7_augment.py]"]
  node_generator["Answer generation<br/>[step8_generate.py]"]
end

subgraph group_infrastructure["Models and storage"]
  node_embedder["Text embedder<br/>[step4_embed.py]"]
  node_store_api["Store interface<br/>[step5_store.py]"]
  node_index[("Vector index<br/>[step5_store.py]")]
  node_config["Pipeline settings<br/>[config.py]"]
end

node_documents["Source documents"]
node_postgres[("Postgres pgvector")]
node_question(("Question asker"))
node_llm{{"LLM provider"}}

node_documents -->|"provides files"| node_ingest
node_ingest -->|"loads documents"| node_loader
node_loader -->|"returns text for"| node_cleaner
node_ingest -->|"cleans text"| node_cleaner
node_ingest -->|"chunks cleaned text"| node_chunker
node_chunker -->|"uses tokenizer"| node_embedder
node_ingest -->|"embeds chunks"| node_embedder
node_ingest -->|"saves chunks"| node_store_api
node_store_api -->|"writes and searches"| node_index
node_store_api -.->|"uses when selected"| node_postgres
node_question -->|"asks question"| node_ask
node_ask -->|"retrieves chunks"| node_retriever
node_retriever -->|"embeds question"| node_embedder
node_retriever -->|"searches index"| node_store_api
node_ask -->|"builds prompt"| node_augmenter
node_ask -->|"generates answer"| node_generator
node_generator -->|"sends prompt"| node_llm
node_ingest -->|"reads settings"| node_config
node_ask -->|"reads settings"| node_config
node_embedder -->|"reads model settings"| node_config
node_store_api -->|"reads backend settings"| node_config
node_generator -->|"reads provider settings"| node_config

click node_ingest "https://github.com/sgundala/rag-101/blob/main/ingest.py"
click node_loader "https://github.com/sgundala/rag-101/blob/main/step1_load.py"
click node_cleaner "https://github.com/sgundala/rag-101/blob/main/step2_clean.py"
click node_chunker "https://github.com/sgundala/rag-101/blob/main/step3_chunk.py"
click node_embedder "https://github.com/sgundala/rag-101/blob/main/step4_embed.py"
click node_store_api "https://github.com/sgundala/rag-101/blob/main/step5_store.py"
click node_index "https://github.com/sgundala/rag-101/blob/main/step5_store.py"
click node_ask "https://github.com/sgundala/rag-101/blob/main/ask.py"
click node_retriever "https://github.com/sgundala/rag-101/blob/main/step6_search.py"
click node_augmenter "https://github.com/sgundala/rag-101/blob/main/step7_augment.py"
click node_generator "https://github.com/sgundala/rag-101/blob/main/step8_generate.py"
click node_config "https://github.com/sgundala/rag-101/blob/main/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_ingest,node_loader,node_cleaner,node_chunker toneBlue
class node_ask,node_retriever,node_postgres toneAmber
class node_augmenter,node_generator toneMint
class node_embedder,node_store_api,node_index,node_config toneRose
class node_documents,node_question,node_llm toneIndigo
```

## Components

### Offline ingestion

- [Ingest runner](https://github.com/sgundala/rag-101/blob/main/ingest.py): `ingest.py`
- [File loader](https://github.com/sgundala/rag-101/blob/main/step1_load.py): `step1_load.py`
- [Text cleaning](https://github.com/sgundala/rag-101/blob/main/step2_clean.py): `step2_clean.py`
- [Token chunking](https://github.com/sgundala/rag-101/blob/main/step3_chunk.py): `step3_chunk.py`

### Online retrieval

- [Ask runner](https://github.com/sgundala/rag-101/blob/main/ask.py): `ask.py`
- [Chunk retrieval](https://github.com/sgundala/rag-101/blob/main/step6_search.py): `step6_search.py`

### Grounded answering

- [Prompt grounding](https://github.com/sgundala/rag-101/blob/main/step7_augment.py): `step7_augment.py`
- [Answer generation](https://github.com/sgundala/rag-101/blob/main/step8_generate.py): `step8_generate.py`

### Models and storage

- [Text embedder](https://github.com/sgundala/rag-101/blob/main/step4_embed.py): `step4_embed.py`
- [Store interface](https://github.com/sgundala/rag-101/blob/main/step5_store.py): `step5_store.py`
- [Vector index](https://github.com/sgundala/rag-101/blob/main/step5_store.py): `step5_store.py`
- [Pipeline settings](https://github.com/sgundala/rag-101/blob/main/config.py): `config.py`

### Other components

- **Source documents**
- **Postgres pgvector**
- **Question asker**
- **LLM provider**

## Connections

- Source documents → Ingest runner: provides files (evidence: `README.md`)
- Ingest runner → File loader: loads documents (evidence: `ingest.py`)
- File loader → Text cleaning: returns text for (evidence: `ingest.py`)
- Ingest runner → Text cleaning: cleans text (evidence: `ingest.py`)
- Ingest runner → Token chunking: chunks cleaned text (evidence: `ingest.py`)
- Token chunking → Text embedder: uses tokenizer (evidence: `step3_chunk.py`)
- Ingest runner → Text embedder: embeds chunks (evidence: `ingest.py`)
- Ingest runner → Store interface: saves chunks (evidence: `ingest.py`)
- Store interface → Vector index: writes and searches (evidence: `step5_store.py`)
- Store interface → Postgres pgvector: uses when selected (evidence: `step5_store.py`)
- Question asker → Ask runner: asks question (evidence: `README.md`)
- Ask runner → Chunk retrieval: retrieves chunks (evidence: `ask.py`)
- Chunk retrieval → Text embedder: embeds question (evidence: `step6_search.py`)
- Chunk retrieval → Store interface: searches index (evidence: `step6_search.py`)
- Ask runner → Prompt grounding: builds prompt (evidence: `ask.py`)
- Ask runner → Answer generation: generates answer (evidence: `ask.py`)
- Answer generation → LLM provider: sends prompt (evidence: `step8_generate.py`)
- Ingest runner → Pipeline settings: reads settings (evidence: `ingest.py`)
- Ask runner → Pipeline settings: reads settings (evidence: `ask.py`)
- Text embedder → Pipeline settings: reads model settings (evidence: `step4_embed.py`)
- Store interface → Pipeline settings: reads backend settings (evidence: `step5_store.py`)
- Answer generation → Pipeline settings: reads provider settings (evidence: `step8_generate.py`)
