# srivenkateshmani/local-rag-system architecture

> Architecture diagram of the GitHub repository srivenkateshmani/local-rag-system, 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/srivenkateshmani/local-rag-system
- Repository: https://github.com/srivenkateshmani/local-rag-system

## Overview

This is a local hybrid RAG application: users upload a PDF and ask questions; the app extracts and chunks the document, embeds and indexes its content, then combines semantic and BM25 search results before generating an answer with a local model. The graph emphasizes the Streamlit workflow and its separate pipeline stages. The README documents the OpenSearch and Ollama services and model; source excerpts show the app’s calls and the retrieval and generation implementations. The sample-script entry point and logging helper are omitted as secondary to the user workflow.

Main entry points: [`app.py`](https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py) (Streamlit App), [`src/ingestion.py`](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/ingestion.py) (Document Indexing), [`src/opensearch_client.py`](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/opensearch_client.py) (OpenSearch Client), [`src/retrieval.py`](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py) (Semantic Search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_app["Streamlit App<br/>[app.py]"]
  node_upload["PDF Upload<br/>[app.py]"]
  node_answer["Answer Display<br/>[app.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_extract["Text Extraction<br/>[document_loader.py]"]
  node_chunk["Word Chunking<br/>[document_loader.py]"]
  node_embed["Text Embeddings<br/>[embeddings.py]"]
  node_indexer["Document Indexing<br/>[ingestion.py]"]
  node_os_client["OpenSearch Client"]
end

subgraph group_retrieval["Hybrid Retrieval"]
  node_opensearch[("OpenSearch")]
  node_semantic["Semantic Search<br/>[retrieval.py]"]
  node_bm25["BM25 Search<br/>[retrieval.py]"]
  node_fusion["Rank Fusion<br/>[retrieval.py]"]
end

subgraph group_generation["Answer Generation"]
  node_prompt["Prompt Generation<br/>[generation.py]"]
  node_ollama["Ollama"]
  node_llama["Llama 3.2"]
end

node_user(("User"))

node_user -->|"uploads and asks"| node_app
node_app -->|"accepts PDF"| node_upload
node_app -->|"loads PDF"| node_extract
node_app -->|"chunks text"| node_chunk
node_app -->|"embeds chunks and query"| node_embed
node_app -->|"creates client and index"| node_os_client
node_app -->|"indexes documents"| node_indexer
node_indexer -->|"writes documents"| node_opensearch
node_os_client -->|"connects and creates index"| node_opensearch
node_app -->|"requests vector search"| node_semantic
node_app -->|"requests keyword search"| node_bm25
node_semantic -->|"searches vectors"| node_opensearch
node_bm25 -->|"searches text"| node_opensearch
node_app -->|"fuses search results"| node_fusion
node_app -->|"generates answer"| node_prompt
node_prompt -->|"sends prompt"| node_ollama
node_ollama -->|"runs model"| node_llama
node_app -->|"displays answer"| node_answer
node_answer -->|"returns answer"| node_user

click node_app "https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py"
click node_upload "https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py"
click node_extract "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/document_loader.py"
click node_chunk "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/document_loader.py"
click node_embed "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/embeddings.py"
click node_indexer "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/ingestion.py"
click node_os_client "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/opensearch_client.py"
click node_semantic "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py"
click node_bm25 "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py"
click node_fusion "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py"
click node_prompt "https://github.com/srivenkateshmani/local-rag-system/blob/main/src/generation.py"
click node_answer "https://github.com/srivenkateshmani/local-rag-system/blob/main/app.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_app,node_upload,node_answer,node_user toneBlue
class node_extract,node_chunk,node_embed,node_indexer,node_os_client toneAmber
class node_opensearch,node_semantic,node_bm25,node_fusion toneMint
class node_prompt,node_ollama,node_llama toneRose
```

## Components

### User Interface

- [Streamlit App](https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py): `app.py`
- [PDF Upload](https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py): `app.py`
- [Answer Display](https://github.com/srivenkateshmani/local-rag-system/blob/main/app.py): `app.py`

### Document Ingestion

- [Text Extraction](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/document_loader.py): `src/document_loader.py`
- [Word Chunking](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/document_loader.py): `src/document_loader.py`
- [Text Embeddings](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/embeddings.py): `src/embeddings.py`
- [Document Indexing](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/ingestion.py): `src/ingestion.py`
- [OpenSearch Client](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/opensearch_client.py): `src/opensearch_client.py`

### Hybrid Retrieval

- **OpenSearch**
- [Semantic Search](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py): `src/retrieval.py`
- [BM25 Search](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py): `src/retrieval.py`
- [Rank Fusion](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/retrieval.py): `src/retrieval.py`

### Answer Generation

- [Prompt Generation](https://github.com/srivenkateshmani/local-rag-system/blob/main/src/generation.py): `src/generation.py`
- **Ollama**
- **Llama 3.2**

### Other components

- **User**

## Connections

- User → Streamlit App: uploads and asks (evidence: `app.py`)
- Streamlit App → PDF Upload: accepts PDF (evidence: `app.py`)
- Streamlit App → Text Extraction: loads PDF (evidence: `app.py`)
- Streamlit App → Word Chunking: chunks text (evidence: `app.py`)
- Streamlit App → Text Embeddings: embeds chunks and query (evidence: `app.py`)
- Streamlit App → OpenSearch Client: creates client and index (evidence: `app.py`)
- Streamlit App → Document Indexing: indexes documents (evidence: `app.py`)
- Document Indexing → OpenSearch: writes documents (evidence: `src/ingestion.py`)
- OpenSearch Client → OpenSearch: connects and creates index (evidence: `src/opensearch_client.py`)
- Streamlit App → Semantic Search: requests vector search (evidence: `app.py`)
- Streamlit App → BM25 Search: requests keyword search (evidence: `app.py`)
- Semantic Search → OpenSearch: searches vectors (evidence: `src/retrieval.py`)
- BM25 Search → OpenSearch: searches text (evidence: `src/retrieval.py`)
- Streamlit App → Rank Fusion: fuses search results (evidence: `app.py`)
- Streamlit App → Prompt Generation: generates answer (evidence: `app.py`)
- Prompt Generation → Ollama: sends prompt (evidence: `src/generation.py`)
- Ollama → Llama 3.2: runs model (evidence: `README.md`)
- Streamlit App → Answer Display: displays answer (evidence: `app.py`)
- Answer Display → User: returns answer (evidence: `app.py`)
