# jamwithai/beginner-local-rag-system architecture

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

- Interactive diagram: https://gitdiagram.com/jamwithai/beginner-local-rag-system
- Repository: https://github.com/jamwithai/beginner-local-rag-system

## Overview

1. **Overall shape**
   - This repo is a **local Retrieval-Augmented Generation (RAG) application** built around a **Streamlit UI**, a **document ingestion/indexing pipeline**, and an **OpenSearch-backed retrieval layer**.
   - The design goal is privacy: documents stay local, embeddings are computed locally, and search/retrieval happens against a self-managed OpenSearch instance.

2. **User-facing application layer**
   - The app entrypoint is `Welcome.py`, with the main UI split into Streamlit pages under `pages/`.
   - `pages/1_🤖_Chatbot.py` is the query interface for asking questions over indexed documents.
   - `pages/2_📄_Upload_Documents.py` is the document submission interface that feeds the ingestion pipeline.
   - This split implies a two-step user flow: **upload/index first, then ask questions**.

3. **Document ingestion subsystem**
   - `src/ingestion.py` is the core pipeline for bringing files into the system.
   - `uploaded_files/` is the local staging area for source documents, and the sample PDFs there indicate the app expects user-provided files to be stored on disk before processing.
   - The ingestion flow likely extracts text, prepares chunks/records, builds embeddings, and writes searchable documents into OpenSearch.

4. **OCR and text extraction boundary**
   - `src/ocr.py` is a dedicated boundary for handling scanned or image-based documents.
   - This separates raw file handling from text normalization, which matters because the system must support both digitally generated PDFs and documents requiring OCR.
   - In architecture terms, OCR sits between file input and downstream indexing.

5. **Embedding generation**
   - `src/embeddings.py` handles vector creation using a local embedding model.
   - The `embedding_model/` directory and its README suggest the model is stored or configured locally rather than fetched dynamically at runtime.
   - Embeddings are central to the semantic portion of retrieval and are produced during ingestion, then reused at query time for matching.

6. **OpenSearch as the indexing and retrieval backend**
   - `src/opensearch.py` encapsulates connectivity and operations against OpenSearch.
   - `src/index_config.json` likely defines the index mapping/settings needed for hybrid search, including text fields and vector fields.
   - OpenSearch is the main persistence and retrieval layer, storing both document metadata/text and embedding vectors for hybrid search.

7. **Question answering / chat subsystem**
   - `src/chat.py` is the orchestration layer for the chatbot experience.
   - The likely flow is: user question → retrieval from OpenSearch → construction of a grounded prompt/context → response generation by an LLM.
   - This module is the main RAG composition boundary, where search results become prompt context for generation.

8. **Shared configuration and utilities**
   - `src/constants.py` centralizes settings such as model names, index names, and OpenSearch connection details.
   - `src/utils.py` is the shared support layer for reusable helpers across ingestion, retrieval, and UI.
   - This keeps environment-specific decisions out of the higher-level app logic.

9. **Project data and local artifacts**
   - `logs/` and `app.log` show the application records runtime behavior locally, which is useful for debugging ingestion/search issues.
   - `images/` contains UI/media assets used by the README and likely the Streamlit app branding.
   - `notebooks/` contains exploratory and instructional notebooks that document the setup and the end-to-end pipeline, but they are not the production runtime path.

10. **Runtime and deployment model**
   - The repo is organized for **local execution** via Streamlit plus a locally accessible OpenSearch instance.
   - Dependencies are managed through `requirements.txt` and `pyproject.toml`, with `mypy.ini` indicating static typing checks are part of the engineering workflow.
   - The architecture assumes the developer/user has local access to models, documents, and search infrastructure, reinforcing the offline/private nature of the system.

11. **End-to-end data flow**
   - **Upload path:** user uploads document → file lands in local storage → OCR/text extraction → chunking/normalization → embeddings generation → OpenSearch indexing.
   - **Chat path:** user asks a question → query is embedded/processed → hybrid search against OpenSearch → top passages are assembled as context → LLM generates an answer.
   - The critical architectural boundary is OpenSearch, which separates offline document preparation from interactive retrieval and response generation.

12. **What matters most for a diagram**
   - Show three major boxes: **Streamlit UI**, **Local processing pipeline**, and **OpenSearch index**.
   - Inside the processing pipeline, distinguish **OCR/text extraction**, **embedding generation**, and **ingestion/indexing**.
   - On the query side, show **retrieval + prompt assembly + LLM response** in `src/chat.py`, with OpenSearch providing the retrieved context.

Main entry points: [`src/ingestion.py`](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/ingestion.py) (Ingestion), [`src/chat.py`](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/chat.py) (RAG chat), [`src/opensearch.py`](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/opensearch.py) (OpenSearch client), [`Welcome.py`](https://github.com/jamwithai/beginner-local-rag-system/blob/main/Welcome.py) (Home)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit UI"]
  node_user(("User<br/>actor"))
  node_welcome["Home<br/>streamlit entrypoint<br/>[Welcome.py]"]
  node_upload_page["Upload docs<br/>streamlit page"]
  node_chat_page["Chatbot<br/>streamlit page<br/>[1_🤖_Chatbot.py]"]
end

subgraph group_pipeline["Local pipeline"]
  node_uploaded_files[("Upload store<br/>local staging")]
  node_ingestion["Ingestion<br/>pipeline<br/>[ingestion.py]"]
  node_ocr["OCR<br/>text extraction<br/>[ocr.py]"]
  node_embeddings["Embeddings<br/>vectorization<br/>[embeddings.py]"]
end

subgraph group_retrieval["Search and chat"]
  node_opensearch_client["OpenSearch client<br/>search adapter<br/>[opensearch.py]"]
  node_chat["RAG chat<br/>orchestration<br/>[chat.py]"]
  node_opensearch[("OpenSearch<br/>index backend")]
end

subgraph group_support["Support files"]
  node_index_config["Index config<br/>mapping config<br/>[index_config.json]"]
  node_constants["Constants<br/>config<br/>[constants.py]"]
  node_utils["Utils<br/>helpers<br/>[utils.py]"]
  node_model_assets["Local model<br/>model asset<br/>[README.md]"]
  node_logs["Logs<br/>runtime artifact<br/>[app.log]"]
  node_notebooks["Notebooks<br/>exploration"]
end

node_user -->|"opens"| node_welcome
node_welcome -->|"routes to"| node_upload_page
node_welcome -->|"routes to"| node_chat_page
node_user -->|"uploads"| node_upload_page
node_user -->|"asks"| node_chat_page
node_upload_page -->|"stores"| node_uploaded_files
node_uploaded_files -->|"feeds"| node_ingestion
node_ingestion -->|"extracts text"| node_ocr
node_ingestion -->|"vectorizes"| node_embeddings
node_ingestion -->|"indexes via"| node_opensearch_client
node_ocr -->|"normalized text"| node_ingestion
node_embeddings -->|"writes vectors"| node_opensearch_client
node_opensearch_client -->|"connects to"| node_opensearch
node_chat_page -->|"invokes"| node_chat
node_chat -->|"embeds query"| node_embeddings
node_chat -->|"retrieves from"| node_opensearch_client
node_chat -->|"queries"| node_opensearch
node_chat -->|"reads settings"| node_constants
node_ingestion -->|"reads settings"| node_constants
node_opensearch_client -->|"applies schema"| node_index_config
node_embeddings -->|"loads model"| node_model_assets
node_ingestion -.->|"uses"| node_utils
node_chat -.->|"uses"| node_utils
node_welcome -.->|"writes"| node_logs
node_upload_page -.->|"writes"| node_logs
node_chat_page -.->|"writes"| node_logs
node_notebooks -.->|"demonstrates"| node_ingestion
node_notebooks -.->|"demonstrates"| node_chat

click node_welcome "https://github.com/jamwithai/beginner-local-rag-system/blob/main/Welcome.py"
click node_upload_page "https://github.com/jamwithai/beginner-local-rag-system/blob/main/pages/2_📄_Upload_Documents.py"
click node_chat_page "https://github.com/jamwithai/beginner-local-rag-system/blob/main/pages/1_🤖_Chatbot.py"
click node_uploaded_files "https://github.com/jamwithai/beginner-local-rag-system/tree/main/uploaded_files"
click node_ingestion "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/ingestion.py"
click node_ocr "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/ocr.py"
click node_embeddings "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/embeddings.py"
click node_opensearch_client "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/opensearch.py"
click node_chat "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/chat.py"
click node_index_config "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/index_config.json"
click node_constants "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/constants.py"
click node_utils "https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/utils.py"
click node_model_assets "https://github.com/jamwithai/beginner-local-rag-system/blob/main/embedding_model/README.md"
click node_logs "https://github.com/jamwithai/beginner-local-rag-system/blob/main/logs/app.log"
click node_notebooks "https://github.com/jamwithai/beginner-local-rag-system/blob/main/notebooks/03_Hybrid_Search_and_Retrieval.ipynb"

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_user,node_welcome,node_upload_page,node_chat_page toneBlue
class node_uploaded_files,node_ingestion,node_ocr,node_embeddings toneAmber
class node_opensearch_client,node_chat,node_opensearch toneMint
class node_index_config,node_constants,node_utils,node_model_assets,node_logs,node_notebooks toneRose
```

## Components

### Streamlit UI

User-facing entrypoints and page flow

- **User**: actor · Person uploading documents and asking questions
- [Home](https://github.com/jamwithai/beginner-local-rag-system/blob/main/Welcome.py): streamlit entrypoint · Main app entrypoint · `Welcome.py`
- [Upload docs](https://github.com/jamwithai/beginner-local-rag-system/blob/main/pages/2_📄_Upload_Documents.py): streamlit page · Document submission interface · `pages/2_📄_Upload_Documents.py`
- [Chatbot](https://github.com/jamwithai/beginner-local-rag-system/blob/main/pages/1_🤖_Chatbot.py): streamlit page · Question-answering interface · `pages/1_🤖_Chatbot.py`

### Local pipeline

Document ingestion, extraction, and embedding

- [Upload store](https://github.com/jamwithai/beginner-local-rag-system/tree/main/uploaded_files): local staging · On-disk location for source documents · `uploaded_files`
- [Ingestion](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/ingestion.py): pipeline · Core document processing and indexing flow · `src/ingestion.py`
- [OCR](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/ocr.py): text extraction · Handles scanned or image-based documents · `src/ocr.py`
- [Embeddings](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/embeddings.py): vectorization · Builds local embeddings for documents and queries · `src/embeddings.py`

### Search and chat

OpenSearch-backed retrieval and answer generation

- [OpenSearch client](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/opensearch.py): search adapter · Connects application code to OpenSearch · `src/opensearch.py`
- [RAG chat](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/chat.py): orchestration · Retrieval, context assembly, and response flow · `src/chat.py`
- **OpenSearch**: index backend · Stores indexed text, metadata, and vectors

### Support files

Local assets, config, and artifacts

- [Index config](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/index_config.json): mapping config · Index settings and field definitions · `src/index_config.json`
- [Constants](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/constants.py): config · Shared model, index, and connection settings · `src/constants.py`
- [Utils](https://github.com/jamwithai/beginner-local-rag-system/blob/main/src/utils.py): helpers · Reusable support functions · `src/utils.py`
- [Local model](https://github.com/jamwithai/beginner-local-rag-system/blob/main/embedding_model/README.md): model asset · Locally stored embedding model artifacts · `embedding_model/README.md`
- [Logs](https://github.com/jamwithai/beginner-local-rag-system/blob/main/logs/app.log): runtime artifact · Local application logs · `logs/app.log`
- [Notebooks](https://github.com/jamwithai/beginner-local-rag-system/blob/main/notebooks/03_Hybrid_Search_and_Retrieval.ipynb): exploration · Setup and walkthrough notebooks · `notebooks/03_Hybrid_Search_and_Retrieval.ipynb`

## Connections

- User → Home: opens · Starts the app
- Home → Upload docs: routes to · Document upload flow
- Home → Chatbot: routes to · Question answering flow
- User → Upload docs: uploads · Submits documents for indexing
- User → Chatbot: asks · Submits questions over indexed content
- Upload docs → Upload store: stores · Writes source files to local staging
- Upload store → Ingestion: feeds · Documents are processed for indexing
- Ingestion → OCR: extracts text · Uses OCR when needed
- Ingestion → Embeddings: vectorizes · Generates document embeddings
- Ingestion → OpenSearch client: indexes via · Writes documents and vectors
- OCR → Ingestion: normalized text · Returns extracted text to the pipeline
- Embeddings → OpenSearch client: writes vectors · Supplies embedding payloads for indexing
- OpenSearch client → OpenSearch: connects to · Search and indexing backend
- Chatbot → RAG chat: invokes · Runs chatbot orchestration
- RAG chat → Embeddings: embeds query · Creates query vectors for retrieval
- RAG chat → OpenSearch client: retrieves from · Fetches ranked passages from search
- RAG chat → OpenSearch: queries · Uses indexed content as retrieval source
- RAG chat → Constants: reads settings · Uses shared runtime configuration
- Ingestion → Constants: reads settings · Uses shared runtime configuration
- OpenSearch client → Index config: applies schema · Uses index mapping and field config
- Embeddings → Local model: loads model · Uses local embedding artifacts
- Ingestion → Utils: uses · Shared helper functions
- RAG chat → Utils: uses · Shared helper functions
- Home → Logs: writes · Runtime logging
- Upload docs → Logs: writes · Runtime logging
- Chatbot → Logs: writes · Runtime logging
- Notebooks → Ingestion: demonstrates · Explores ingestion pipeline
- Notebooks → RAG chat: demonstrates · Explores retrieval and chat flow
