# vishwanath-06/offline_rag architecture

> Architecture diagram of the GitHub repository vishwanath-06/offline_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/vishwanath-06/offline_rag
- Repository: https://github.com/vishwanath-06/offline_rag

## Overview

This is an offline document-question-answering app: users add PDFs or text/Markdown files, ingest them into a local Chroma vector database, then ask questions through a browser interface and receive answers with source snippets. Ingestion loads and chunks documents before embedding and storage; the API retrieves relevant chunks and uses a local Ollama model to generate answers. Model caching prepares local dependencies, while diagnostics check offline readiness. The main runtime and ingestion sources were sampled; the browser-to-API connection is documented only indirectly, so that edge is marked unverified.

Main entry points: [`ingest.py`](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py) (Ingestion Runner), [`main.py`](https://github.com/vishwanath-06/offline_rag/blob/main/main.py) (Query API), [`interface.html`](https://github.com/vishwanath-06/offline_rag/blob/main/interface.html) (Browser Interface), [`cache_models.py`](https://github.com/vishwanath-06/offline_rag/blob/main/cache_models.py) (Model Caching)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document Ingestion"]
  node_ingest["Ingestion Runner<br/>[ingest.py]"]
  node_document_loaders["Document Loaders<br/>[ingest.py]"]
  node_chunking["Chunking<br/>[ingest.py]"]
  node_ingest_embeddings["Ingest Embeddings<br/>[ingest.py]"]
end

subgraph group_runtime["Question Answering"]
  node_vector_db[("Chroma Database<br/>[ingest.py]")]
  node_browser_ui["Browser Interface<br/>[interface.html]"]
  node_api["Query API<br/>[main.py]"]
  node_query_embeddings["Query Embeddings<br/>[main.py]"]
  node_retriever["Similarity Retriever<br/>[main.py]"]
  node_prompt_chain["Prompt Chain<br/>[main.py]"]
  node_ollama["Ollama Model"]
end

subgraph group_offline["Offline Readiness"]
  node_model_cache["Model Caching<br/>[cache_models.py]"]
  node_cache_check["Cache Verification<br/>[verify_cache.py]"]
  node_offline_diagnostics["Offline Diagnostics<br/>[offline_test.py]"]
end

node_user(("Document User"))

node_user -->|"asks questions"| node_browser_ui
node_user -->|"provides documents"| node_ingest
node_ingest -->|"loads files"| node_document_loaders
node_ingest -->|"splits documents"| node_chunking
node_ingest -->|"initializes embeddings"| node_ingest_embeddings
node_ingest -->|"writes chunks"| node_vector_db
node_browser_ui -.->|"submits query"| node_api
node_api -->|"initializes model"| node_query_embeddings
node_api -->|"retrieves context"| node_retriever
node_retriever -->|"searches vectors"| node_vector_db
node_api -->|"generates answer"| node_prompt_chain
node_prompt_chain -->|"invokes model"| node_ollama
node_api -.->|"returns answer"| node_browser_ui
node_model_cache -->|"checks or pulls"| node_ollama
node_model_cache -->|"caches model"| node_query_embeddings
node_cache_check -->|"checks cache"| node_query_embeddings

click node_ingest "https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py"
click node_document_loaders "https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py"
click node_chunking "https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py"
click node_ingest_embeddings "https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py"
click node_vector_db "https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py"
click node_browser_ui "https://github.com/vishwanath-06/offline_rag/blob/main/interface.html"
click node_api "https://github.com/vishwanath-06/offline_rag/blob/main/main.py"
click node_query_embeddings "https://github.com/vishwanath-06/offline_rag/blob/main/main.py"
click node_retriever "https://github.com/vishwanath-06/offline_rag/blob/main/main.py"
click node_prompt_chain "https://github.com/vishwanath-06/offline_rag/blob/main/main.py"
click node_model_cache "https://github.com/vishwanath-06/offline_rag/blob/main/cache_models.py"
click node_cache_check "https://github.com/vishwanath-06/offline_rag/blob/main/verify_cache.py"
click node_offline_diagnostics "https://github.com/vishwanath-06/offline_rag/blob/main/offline_test.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_document_loaders,node_chunking,node_ingest_embeddings,node_user toneBlue
class node_vector_db,node_browser_ui,node_api,node_query_embeddings,node_retriever,node_prompt_chain,node_ollama toneAmber
class node_model_cache,node_cache_check,node_offline_diagnostics toneMint
```

## Components

### Document Ingestion

- [Ingestion Runner](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py): `ingest.py`
- [Document Loaders](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py): `ingest.py`
- [Chunking](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py): `ingest.py`
- [Ingest Embeddings](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py): `ingest.py`

### Question Answering

- [Chroma Database](https://github.com/vishwanath-06/offline_rag/blob/main/ingest.py): `ingest.py`
- [Browser Interface](https://github.com/vishwanath-06/offline_rag/blob/main/interface.html): `interface.html`
- [Query API](https://github.com/vishwanath-06/offline_rag/blob/main/main.py): `main.py`
- [Query Embeddings](https://github.com/vishwanath-06/offline_rag/blob/main/main.py): `main.py`
- [Similarity Retriever](https://github.com/vishwanath-06/offline_rag/blob/main/main.py): `main.py`
- [Prompt Chain](https://github.com/vishwanath-06/offline_rag/blob/main/main.py): `main.py`
- **Ollama Model**

### Offline Readiness

- [Model Caching](https://github.com/vishwanath-06/offline_rag/blob/main/cache_models.py): `cache_models.py`
- [Cache Verification](https://github.com/vishwanath-06/offline_rag/blob/main/verify_cache.py): `verify_cache.py`
- [Offline Diagnostics](https://github.com/vishwanath-06/offline_rag/blob/main/offline_test.py): `offline_test.py`

### Other components

- **Document User**

## Connections

- Document User → Browser Interface: asks questions (evidence: `README.md`)
- Document User → Ingestion Runner: provides documents (evidence: `README.md`)
- Ingestion Runner → Document Loaders: loads files (evidence: `ingest.py`)
- Ingestion Runner → Chunking: splits documents (evidence: `ingest.py`)
- Ingestion Runner → Ingest Embeddings: initializes embeddings (evidence: `ingest.py`)
- Ingestion Runner → Chroma Database: writes chunks (evidence: `ingest.py`)
- Browser Interface → Query API: submits query
- Query API → Query Embeddings: initializes model (evidence: `main.py`)
- Query API → Similarity Retriever: retrieves context (evidence: `main.py`)
- Similarity Retriever → Chroma Database: searches vectors (evidence: `main.py`)
- Query API → Prompt Chain: generates answer (evidence: `main.py`)
- Prompt Chain → Ollama Model: invokes model (evidence: `main.py`)
- Query API → Browser Interface: returns answer
- Model Caching → Ollama Model: checks or pulls (evidence: `cache_models.py`)
- Model Caching → Query Embeddings: caches model (evidence: `cache_models.py`)
- Cache Verification → Query Embeddings: checks cache (evidence: `verify_cache.py`)
