# ehsanghaderian/rag-langchain-huggingface architecture

> Architecture diagram of the GitHub repository ehsanghaderian/rag-langchain-huggingface, 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/ehsanghaderian/rag-langchain-huggingface
- Repository: https://github.com/ehsanghaderian/rag-langchain-huggingface

## Overview

This is a compact, script-driven RAG application: it loads local text, chunks and embeds it into a local Chroma store, retrieves passages for a question, builds context, and asks a hosted Hugging Face model for an answer. The main workflow is visible in rag.py; the README documents broader evaluation and scoring possibilities, but the sampled script does not implement a separate evaluation stage. External services and integrations are shown only where the source or README identifies them.

Main entry points: [`rag.py`](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py) (RAG Script), [`Book.txt`](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/Book.txt) (Book Text)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document Ingestion"]
  node_loader["Document Loader<br/>[rag.py]"]
  node_chunker["Text Chunker<br/>[rag.py]"]
  node_embedder{{"Embedding API"}}
end

subgraph group_retrieval["Search and Context"]
  node_runner["RAG Script<br/>[rag.py]"]
  node_store[("Chroma Store<br/>[rag.py]")]
  node_search["Similarity Search<br/>[rag.py]"]
  node_context["Context Builder<br/>[rag.py]"]
end

subgraph group_generation["Answer Generation"]
  node_prompt["Prompt Builder<br/>[rag.py]"]
  node_llm{{"Hosted Qwen LLM"}}
  node_answer["Generated Answer<br/>[rag.py]"]
end

node_user(("Questioner"))
node_book["Book Text<br/>[Book.txt]"]

node_user -->|"asks"| node_runner
node_book -->|"loads text"| node_loader
node_runner -->|"calls"| node_loader
node_runner -->|"chunks documents"| node_chunker
node_runner -->|"creates store"| node_store
node_chunker -->|"stores chunks"| node_store
node_embedder -->|"embeds chunks"| node_store
node_runner -->|"searches query"| node_search
node_search -->|"queries vectors"| node_store
node_runner -->|"selects passages"| node_context
node_search -->|"returns passages"| node_context
node_runner -->|"combines query"| node_prompt
node_context -->|"adds context"| node_prompt
node_prompt -->|"sends prompt"| node_llm
node_runner -->|"invokes model"| node_llm
node_llm -->|"generates text"| node_answer

click node_book "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/Book.txt"
click node_runner "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_loader "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_chunker "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_store "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_search "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_context "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_prompt "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py"
click node_answer "https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.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_loader,node_chunker,node_embedder toneBlue
class node_runner,node_store,node_search,node_context toneAmber
class node_prompt,node_llm,node_answer toneMint
class node_user toneIndigo
class node_book toneTeal
```

## Components

### Document Ingestion

- [Document Loader](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- [Text Chunker](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- **Embedding API**

### Search and Context

- [RAG Script](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- [Chroma Store](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- [Similarity Search](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- [Context Builder](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`

### Answer Generation

- [Prompt Builder](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`
- **Hosted Qwen LLM**
- [Generated Answer](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/rag.py): `rag.py`

### Other components

- **Questioner**
- [Book Text](https://github.com/ehsanghaderian/rag-langchain-huggingface/blob/main/Book.txt): `Book.txt`

## Connections

- Questioner → RAG Script: asks (evidence: `rag.py`)
- Book Text → Document Loader: loads text (evidence: `rag.py`)
- RAG Script → Document Loader: calls (evidence: `rag.py`)
- RAG Script → Text Chunker: chunks documents (evidence: `rag.py`)
- RAG Script → Chroma Store: creates store (evidence: `rag.py`)
- Text Chunker → Chroma Store: stores chunks (evidence: `rag.py`)
- Embedding API → Chroma Store: embeds chunks (evidence: `rag.py`)
- RAG Script → Similarity Search: searches query (evidence: `rag.py`)
- Similarity Search → Chroma Store: queries vectors (evidence: `rag.py`)
- RAG Script → Context Builder: selects passages (evidence: `rag.py`)
- Similarity Search → Context Builder: returns passages (evidence: `rag.py`)
- RAG Script → Prompt Builder: combines query (evidence: `rag.py`)
- Context Builder → Prompt Builder: adds context (evidence: `rag.py`)
- Prompt Builder → Hosted Qwen LLM: sends prompt (evidence: `rag.py`)
- RAG Script → Hosted Qwen LLM: invokes model (evidence: `rag.py`)
- Hosted Qwen LLM → Generated Answer: generates text (evidence: `rag.py`)
