# zalaavinash/rag-from-scratch-python architecture

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

- Interactive diagram: https://gitdiagram.com/zalaavinash/rag-from-scratch-python
- Repository: https://github.com/zalaavinash/rag-from-scratch-python

## Overview

RAG From Scratch is a local PDF question-answering application. The user invokes the CLI to ingest a PDF or ask a question; the pipeline coordinates extraction, chunking, embedding, persistent storage and retrieval, then generates an answer grounded in retrieved passages and returns source hits for display. Its main internal layer is the RAGPipeline orchestrator. The README documents the local Ollama and persistent ChromaDB design. Edges reflect the shown pipeline calls, CLI wiring and backend requests; unsampled implementation details are not inferred.

Main entry points: [`src/rag/pipeline.py`](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/pipeline.py) (RAG pipeline), [`src/rag/cli.py`](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/cli.py) (CLI commands), [`src/rag/store.py`](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/store.py) (Vector store wrapper), [`src/rag/embedder.py`](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/embedder.py) (Text embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interface"]
  node_cli["CLI commands<br/>[cli.py]"]
end

subgraph group_processing["RAG processing"]
  node_pipeline["RAG pipeline<br/>[pipeline.py]"]
  node_pdf["PDF extraction<br/>[loaders.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
end

subgraph group_backends["Local backends"]
  node_embedder["Text embeddings<br/>[embedder.py]"]
  node_llm["Answer generation<br/>[llm.py]"]
end

subgraph group_persistence["Vector persistence"]
  node_store["Vector store wrapper<br/>[store.py]"]
  node_chroma[("Persistent ChromaDB")]
end

node_user(("User"))
node_ollama["Local Ollama"]

node_user -->|"runs commands"| node_cli
node_cli -->|"invokes ingest or ask"| node_pipeline
node_cli -->|"configures persistence"| node_store
node_pipeline -->|"loads PDF"| node_pdf
node_pipeline -->|"chunks text"| node_chunker
node_pipeline -->|"embeds chunks or question"| node_embedder
node_pipeline -->|"adds or searches vectors"| node_store
node_pipeline -->|"requests completion"| node_llm
node_embedder -->|"requests embeddings"| node_ollama
node_llm -->|"requests chat"| node_ollama
node_store -->|"persists and queries"| node_chroma
node_pipeline -->|"returns answer and sources"| node_cli

click node_cli "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/cli.py"
click node_pipeline "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/pipeline.py"
click node_pdf "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/loaders.py"
click node_chunker "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/chunker.py"
click node_embedder "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/embedder.py"
click node_store "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/store.py"
click node_llm "https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/llm.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_cli,node_user toneBlue
class node_pipeline,node_pdf,node_chunker toneAmber
class node_embedder,node_llm toneMint
class node_store,node_chroma toneRose
class node_ollama toneIndigo
```

## Components

### User interface

- [CLI commands](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/cli.py): `src/rag/cli.py`

### RAG processing

- [RAG pipeline](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/pipeline.py): `src/rag/pipeline.py`
- [PDF extraction](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/loaders.py): `src/rag/loaders.py`
- [Text chunking](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/chunker.py): `src/rag/chunker.py`

### Local backends

- [Text embeddings](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/embedder.py): `src/rag/embedder.py`
- [Answer generation](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/llm.py): `src/rag/llm.py`

### Vector persistence

- [Vector store wrapper](https://github.com/zalaavinash/rag-from-scratch-python/blob/main/src/rag/store.py): `src/rag/store.py`
- **Persistent ChromaDB**

### Other components

- **User**
- **Local Ollama**

## Connections

- User → CLI commands: runs commands (evidence: `README.md`)
- CLI commands → RAG pipeline: invokes ingest or ask (evidence: `src/rag/cli.py`)
- CLI commands → Vector store wrapper: configures persistence (evidence: `src/rag/cli.py`)
- RAG pipeline → PDF extraction: loads PDF (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Text chunking: chunks text (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Text embeddings: embeds chunks or question (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Vector store wrapper: adds or searches vectors (evidence: `src/rag/pipeline.py`)
- RAG pipeline → Answer generation: requests completion (evidence: `src/rag/pipeline.py`)
- Text embeddings → Local Ollama: requests embeddings (evidence: `src/rag/embedder.py`)
- Answer generation → Local Ollama: requests chat (evidence: `src/rag/llm.py`)
- Vector store wrapper → Persistent ChromaDB: persists and queries (evidence: `src/rag/store.py`)
- RAG pipeline → CLI commands: returns answer and sources (evidence: `src/rag/cli.py`)
