# zabdeilmercado/mini-rag architecture

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

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

## Overview

Mini-RAG ingests UTF-8 text, chunks it, creates local Ollama embeddings, and stores a reusable disk cache or PostgreSQL records. Users then select a source, embed a question, retrieve the top passages through NumPy or pgvector, and generate an answer with Ollama. The CLI and browser interface enter through different orchestrators; the browser also supports upload and passage inspection. Edges reflect shown calls, imports, and browser requests; README-documented capabilities supplement the excerpts, while unsampled implementation details are not inferred.

Main entry points: [`workflows.py`](https://github.com/zabdeilmercado/mini-rag/blob/main/workflows.py) (Workflow coordinator), [`web_server.py`](https://github.com/zabdeilmercado/mini-rag/blob/main/web_server.py) (Local HTTP server), [`main.py`](https://github.com/zabdeilmercado/mini-rag/blob/main/main.py) (CLI entry), [`postgres_store.py`](https://github.com/zabdeilmercado/mini-rag/blob/main/postgres_store.py) (Postgres store and search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI entry<br/>[main.py]"]
  node_browser["Browser UI<br/>[app.js]"]
  node_http_server["Local HTTP server<br/>[web_server.py]"]
end

subgraph group_orchestration["Workflow coordination"]
  node_workflow["Workflow coordinator<br/>[workflows.py]"]
  node_settings["Shared settings<br/>[config.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_text_processing["Read and chunk text<br/>[ingest.py]"]
  node_document_embeddings["Document embeddings<br/>[ingest.py]"]
end

subgraph group_retrieval["Retrieval and answers"]
  node_question_search["Question embedding and NumPy ranking<br/>[retrieve.py]"]
  node_answer_generation["Context answer generation<br/>[generate.py]"]
end

subgraph group_persistence["Persistence"]
  node_disk_cache[("Disk cache<br/>[storage.py]")]
  node_postgres_store[("Postgres store and search<br/>[postgres_store.py]")]
end

node_cli_user(("CLI user"))
node_browser_user(("Browser user"))
node_ollama["Ollama service"]
node_postgres[("PostgreSQL with pgvector")]

node_cli_user -->|"runs commands"| node_cli
node_cli -->|"prepares ingestion or search"| node_workflow
node_cli -->|"requests answer"| node_answer_generation
node_browser_user -->|"uploads and asks"| node_browser
node_browser -->|"requests API"| node_http_server
node_http_server -->|"serves assets"| node_browser
node_http_server -->|"ingests or prepares search"| node_workflow
node_http_server -->|"lists sources"| node_postgres_store
node_http_server -->|"generates answer"| node_answer_generation
node_workflow -->|"loads and chunks"| node_text_processing
node_workflow -->|"creates embeddings"| node_document_embeddings
node_workflow -->|"loads or saves cache"| node_disk_cache
node_workflow -->|"stores or finds source"| node_postgres_store
node_workflow -->|"builds NumPy search"| node_question_search
node_text_processing -->|"provides chunks"| node_document_embeddings
node_document_embeddings -->|"requests embeddings"| node_ollama
node_question_search -->|"embeds question"| node_ollama
node_question_search -.->|"not used"| node_postgres_store
node_postgres_store -->|"reads and writes"| node_postgres
node_http_server -->|"retrieves passages"| node_workflow
node_cli -->|"searches stored source"| node_workflow
node_answer_generation -->|"requests chat"| node_ollama

click node_cli "https://github.com/zabdeilmercado/mini-rag/blob/main/main.py"
click node_browser "https://github.com/zabdeilmercado/mini-rag/blob/main/web/app.js"
click node_http_server "https://github.com/zabdeilmercado/mini-rag/blob/main/web_server.py"
click node_workflow "https://github.com/zabdeilmercado/mini-rag/blob/main/workflows.py"
click node_settings "https://github.com/zabdeilmercado/mini-rag/blob/main/config.py"
click node_text_processing "https://github.com/zabdeilmercado/mini-rag/blob/main/ingest.py"
click node_document_embeddings "https://github.com/zabdeilmercado/mini-rag/blob/main/ingest.py"
click node_disk_cache "https://github.com/zabdeilmercado/mini-rag/blob/main/storage.py"
click node_postgres_store "https://github.com/zabdeilmercado/mini-rag/blob/main/postgres_store.py"
click node_question_search "https://github.com/zabdeilmercado/mini-rag/blob/main/retrieve.py"
click node_answer_generation "https://github.com/zabdeilmercado/mini-rag/blob/main/generate.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_browser,node_http_server,node_cli_user,node_browser_user toneBlue
class node_workflow,node_settings,node_postgres toneAmber
class node_text_processing,node_document_embeddings toneMint
class node_question_search,node_answer_generation toneRose
class node_disk_cache,node_postgres_store,node_ollama toneIndigo
```

## Components

### User interfaces

- [CLI entry](https://github.com/zabdeilmercado/mini-rag/blob/main/main.py): `main.py`
- [Browser UI](https://github.com/zabdeilmercado/mini-rag/blob/main/web/app.js): `web/app.js`
- [Local HTTP server](https://github.com/zabdeilmercado/mini-rag/blob/main/web_server.py): `web_server.py`

### Workflow coordination

- [Workflow coordinator](https://github.com/zabdeilmercado/mini-rag/blob/main/workflows.py): `workflows.py`
- [Shared settings](https://github.com/zabdeilmercado/mini-rag/blob/main/config.py): `config.py`

### Document ingestion

- [Read and chunk text](https://github.com/zabdeilmercado/mini-rag/blob/main/ingest.py): `ingest.py`
- [Document embeddings](https://github.com/zabdeilmercado/mini-rag/blob/main/ingest.py): `ingest.py`

### Retrieval and answers

- [Question embedding and NumPy ranking](https://github.com/zabdeilmercado/mini-rag/blob/main/retrieve.py): `retrieve.py`
- [Context answer generation](https://github.com/zabdeilmercado/mini-rag/blob/main/generate.py): `generate.py`

### Persistence

- [Disk cache](https://github.com/zabdeilmercado/mini-rag/blob/main/storage.py): `storage.py`
- [Postgres store and search](https://github.com/zabdeilmercado/mini-rag/blob/main/postgres_store.py): `postgres_store.py`

### Other components

- **CLI user**
- **Browser user**
- **Ollama service**
- **PostgreSQL with pgvector**

## Connections

- CLI user → CLI entry: runs commands (evidence: `README.md`)
- CLI entry → Workflow coordinator: prepares ingestion or search (evidence: `main.py`)
- CLI entry → Context answer generation: requests answer (evidence: `main.py`)
- Browser user → Browser UI: uploads and asks (evidence: `README.md`)
- Browser UI → Local HTTP server: requests API (evidence: `web/app.js`)
- Local HTTP server → Browser UI: serves assets (evidence: `web_server.py`)
- Local HTTP server → Workflow coordinator: ingests or prepares search (evidence: `web_server.py`)
- Local HTTP server → Postgres store and search: lists sources (evidence: `web_server.py`)
- Local HTTP server → Context answer generation: generates answer (evidence: `web_server.py`)
- Workflow coordinator → Read and chunk text: loads and chunks (evidence: `workflows.py`)
- Workflow coordinator → Document embeddings: creates embeddings (evidence: `workflows.py`)
- Workflow coordinator → Disk cache: loads or saves cache (evidence: `workflows.py`)
- Workflow coordinator → Postgres store and search: stores or finds source (evidence: `workflows.py`)
- Workflow coordinator → Question embedding and NumPy ranking: builds NumPy search (evidence: `workflows.py`)
- Read and chunk text → Document embeddings: provides chunks (evidence: `workflows.py`)
- Document embeddings → Ollama service: requests embeddings (evidence: `ingest.py`)
- Question embedding and NumPy ranking → Ollama service: embeds question (evidence: `retrieve.py`)
- Question embedding and NumPy ranking → Postgres store and search: not used
- Postgres store and search → PostgreSQL with pgvector: reads and writes (evidence: `postgres_store.py`)
- Local HTTP server → Workflow coordinator: retrieves passages (evidence: `web_server.py`)
- CLI entry → Workflow coordinator: searches stored source (evidence: `main.py`)
- Context answer generation → Ollama service: requests chat (evidence: `generate.py`)
