# iamhharish/llm-rag-system architecture

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

- Interactive diagram: https://gitdiagram.com/iamhharish/llm-rag-system
- Repository: https://github.com/iamhharish/llm-rag-system

## Overview

This is a command-line hybrid RAG question-answering system. A user’s question enters `pipeline.py`, which retrieves and reranks local document passages, searches the web, checks whether the combined context is relevant, and generates an answer using mark-sensitive instructions. It then adds source attribution and logs the interaction. The README also describes document uploads, academic formatting, and an ask-back response when evidence is insufficient. The sampled code supports TXT, PDF, and DOCX loading; external model and search behavior is represented at a high level.

Main entry points: [`pipeline.py`](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py) (RAG pipeline), [`retriever.py`](https://github.com/iamhharish/llm-rag-system/blob/main/retriever.py) (Vector retrieval), [`online_retrieval.py`](https://github.com/iamhharish/llm-rag-system/blob/main/online_retrieval.py) (Web retrieval), [`data_loader.py`](https://github.com/iamhharish/llm-rag-system/blob/main/data_loader.py) (Document loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Question orchestration"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_relevance_guard["Context relevance<br/>[pipeline.py]"]
end

subgraph group_offline["Offline documents"]
  node_document_folder["Document folder"]
  node_loader["Document loader<br/>[data_loader.py]"]
  node_chunker["Text chunking<br/>[chunking.py]"]
  node_embedder["Embedding model"]
  node_retriever["Vector retrieval<br/>[retriever.py]"]
  node_faiss_index[("FAISS index<br/>[retriever.py]")]
end

subgraph group_online["Online retrieval"]
  node_online_retrieval["Web retrieval"]
  node_search_service["Search service"]
  node_web_pages["Web pages"]
end

subgraph group_answer_state["Answers and history"]
  node_answer_policy["Academic answer policy<br/>[pipeline.py]"]
  node_llm["Language model"]
  node_attribution["Source attribution<br/>[pipeline.py]"]
  node_interaction_log[("Interaction log<br/>[pipeline.py]")]
end

node_user(("Questioner"))

node_user -->|"asks"| node_pipeline
node_pipeline -->|"reads files"| node_document_folder
node_pipeline -->|"loads documents"| node_loader
node_loader -->|"returns text"| node_pipeline
node_pipeline -->|"creates chunks"| node_chunker
node_pipeline -->|"encodes chunks"| node_embedder
node_pipeline -->|"builds index"| node_retriever
node_retriever -->|"writes vectors"| node_faiss_index
node_pipeline -->|"retrieves chunks"| node_retriever
node_retriever -->|"encodes query"| node_embedder
node_retriever -->|"searches vectors"| node_faiss_index
node_retriever -->|"returns reranked chunks"| node_pipeline
node_pipeline -->|"requests web data"| node_online_retrieval
node_online_retrieval -->|"searches web"| node_search_service
node_online_retrieval -->|"fetches pages"| node_web_pages
node_online_retrieval -->|"returns passages"| node_pipeline
node_pipeline -->|"checks context"| node_relevance_guard
node_pipeline -->|"selects answer style"| node_answer_policy
node_pipeline -->|"generates answer"| node_llm
node_pipeline -->|"assigns source"| node_attribution
node_pipeline -->|"logs interaction"| node_interaction_log
node_pipeline -->|"returns answer"| node_user

click node_pipeline "https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py"
click node_loader "https://github.com/iamhharish/llm-rag-system/blob/main/data_loader.py"
click node_chunker "https://github.com/iamhharish/llm-rag-system/blob/main/chunking.py"
click node_retriever "https://github.com/iamhharish/llm-rag-system/blob/main/retriever.py"
click node_faiss_index "https://github.com/iamhharish/llm-rag-system/blob/main/retriever.py"
click node_online_retrieval "https://github.com/iamhharish/llm-rag-system/blob/main/online_retrieval.py"
click node_relevance_guard "https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py"
click node_answer_policy "https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py"
click node_attribution "https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py"
click node_interaction_log "https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.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_pipeline,node_relevance_guard toneBlue
class node_document_folder,node_loader,node_chunker,node_embedder,node_retriever,node_faiss_index toneAmber
class node_online_retrieval,node_search_service,node_web_pages toneMint
class node_answer_policy,node_llm,node_attribution,node_interaction_log toneRose
class node_user toneIndigo
```

## Components

### Question orchestration

- [RAG pipeline](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py): `pipeline.py`
- [Context relevance](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py): `pipeline.py`

### Offline documents

- **Document folder**
- [Document loader](https://github.com/iamhharish/llm-rag-system/blob/main/data_loader.py): `data_loader.py`
- [Text chunking](https://github.com/iamhharish/llm-rag-system/blob/main/chunking.py): `chunking.py`
- **Embedding model**
- [Vector retrieval](https://github.com/iamhharish/llm-rag-system/blob/main/retriever.py): `retriever.py`
- [FAISS index](https://github.com/iamhharish/llm-rag-system/blob/main/retriever.py): `retriever.py`

### Online retrieval

- [Web retrieval](https://github.com/iamhharish/llm-rag-system/blob/main/online_retrieval.py): `online_retrieval.py`
- **Search service**
- **Web pages**

### Answers and history

- [Academic answer policy](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py): `pipeline.py`
- **Language model**
- [Source attribution](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py): `pipeline.py`
- [Interaction log](https://github.com/iamhharish/llm-rag-system/blob/main/pipeline.py): `pipeline.py`

### Other components

- **Questioner**

## Connections

- Questioner → RAG pipeline: asks
- RAG pipeline → Document folder: reads files
- RAG pipeline → Document loader: loads documents
- Document loader → RAG pipeline: returns text
- RAG pipeline → Text chunking: creates chunks
- RAG pipeline → Embedding model: encodes chunks
- RAG pipeline → Vector retrieval: builds index
- Vector retrieval → FAISS index: writes vectors
- RAG pipeline → Vector retrieval: retrieves chunks
- Vector retrieval → Embedding model: encodes query
- Vector retrieval → FAISS index: searches vectors
- Vector retrieval → RAG pipeline: returns reranked chunks
- RAG pipeline → Web retrieval: requests web data
- Web retrieval → Search service: searches web
- Web retrieval → Web pages: fetches pages
- Web retrieval → RAG pipeline: returns passages
- RAG pipeline → Context relevance: checks context
- RAG pipeline → Academic answer policy: selects answer style
- RAG pipeline → Language model: generates answer
- RAG pipeline → Source attribution: assigns source
- RAG pipeline → Interaction log: logs interaction
- RAG pipeline → Questioner: returns answer
