# karthiksshow/rag architecture

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

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

## Overview

This is a compact RAG demonstration: it loads text, splits it into chunks, embeds and indexes them, retrieves relevant context for a question, then asks a local text-generation pipeline to produce an answer. The script explicitly names `data/About_Ai.txt`, but the tree contains `About AI.txt`; the excerpts do not establish that the listed file is the one loaded. All runtime stages are implemented in the single script, so their paths are shared.

Main entry points: [`RAG_BasicDemo.py`](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py) (RAG chain), [`About AI.txt`](https://github.com/karthiksshow/rag/blob/main/About%20AI.txt) (Text source)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_corpus["Corpus preparation"]
  node_source["Text source<br/>[About AI.txt]"]
  node_loader["Text loader<br/>[RAG_BasicDemo.py]"]
  node_splitter["Chunk splitter<br/>[RAG_BasicDemo.py]"]
  node_embedder["Embedding model<br/>[RAG_BasicDemo.py]"]
end

subgraph group_rag["Retrieval and answering"]
  node_index[("FAISS index<br/>[RAG_BasicDemo.py]")]
  node_retriever["Retriever<br/>[RAG_BasicDemo.py]"]
  node_chain["RAG chain<br/>[RAG_BasicDemo.py]"]
  node_generator["Text generator<br/>[RAG_BasicDemo.py]"]
  node_answer["Answer<br/>[RAG_BasicDemo.py]"]
end

node_user(("Questioner"))

node_loader -->|"splits documents"| node_splitter
node_splitter -->|"indexes chunks"| node_index
node_embedder -->|"embeds chunks"| node_index
node_chain -->|"retrieves context"| node_retriever
node_retriever -->|"searches"| node_index
node_chain -->|"invokes"| node_generator
node_user -->|"asks"| node_chain
node_chain -->|"returns"| node_answer
node_source -.->|"intended input"| node_loader

click node_source "https://github.com/karthiksshow/rag/blob/main/About%20AI.txt"
click node_loader "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_splitter "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_embedder "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_index "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_retriever "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_chain "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_generator "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py"
click node_answer "https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.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_source,node_loader,node_splitter,node_embedder toneBlue
class node_index,node_retriever,node_chain,node_generator,node_answer toneAmber
class node_user toneIndigo
```

## Components

### Corpus preparation

- [Text source](https://github.com/karthiksshow/rag/blob/main/About%20AI.txt): `About AI.txt`
- [Text loader](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [Chunk splitter](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [Embedding model](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`

### Retrieval and answering

- [FAISS index](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [Retriever](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [RAG chain](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [Text generator](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`
- [Answer](https://github.com/karthiksshow/rag/blob/main/RAG_BasicDemo.py): `RAG_BasicDemo.py`

### Other components

- **Questioner**

## Connections

- Text loader → Chunk splitter: splits documents (evidence: `RAG_BasicDemo.py`)
- Chunk splitter → FAISS index: indexes chunks (evidence: `RAG_BasicDemo.py`)
- Embedding model → FAISS index: embeds chunks (evidence: `RAG_BasicDemo.py`)
- RAG chain → Retriever: retrieves context (evidence: `RAG_BasicDemo.py`)
- Retriever → FAISS index: searches (evidence: `RAG_BasicDemo.py`)
- RAG chain → Text generator: invokes (evidence: `RAG_BasicDemo.py`)
- Questioner → RAG chain: asks (evidence: `RAG_BasicDemo.py`)
- RAG chain → Answer: returns (evidence: `RAG_BasicDemo.py`)
- Text source → Text loader: intended input
