# kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2 architecture

> Architecture diagram of the GitHub repository kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2
- Repository: https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2

## Overview

This repository is a PDF/TXT retrieval-augmented question-answering service. A client uploads documents through FastAPI; the shared FileProcessor loads them, semantically chunks the text, and builds an in-memory FAISS index. For questions, it searches the index, re-ranks candidates, and passes the selected context to a grounded QA chain backed by Ollama. Upload files persist on disk, but the index is process-local and lost on restart. The README documents this workflow; the graph’s implementation relationships are evidenced by app.py.

Main entry points: [`app.py`](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py) (FileProcessor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and uploads"]
  node_api["FastAPI routes<br/>[app.py]"]
  node_uploads[("Uploaded files<br/>[app.py]")]
end

subgraph group_ingestion["Document ingestion"]
  node_processor["FileProcessor<br/>[app.py]"]
  node_loaders["PDF/TXT loaders<br/>[app.py]"]
  node_chunker["Semantic chunker<br/>[app.py]"]
  node_embeddings["BGE embeddings<br/>[app.py]"]
end

subgraph group_retrieval["Search and ranking"]
  node_faiss[("FAISS index<br/>[app.py]")]
  node_search["Similarity search<br/>[app.py]"]
  node_reranker["CrossEncoder reranker<br/>[app.py]"]
end

subgraph group_answering["Grounded answering"]
  node_qa["QA chain<br/>[app.py]"]
  node_prompt["Grounding prompt<br/>[app.py]"]
  node_ollama["Ollama LLM"]
end

node_client(("API client"))

node_client -->|"uploads or asks"| node_api
node_api -->|"writes files"| node_uploads
node_api -->|"processes files"| node_processor
node_uploads -->|"provides paths"| node_processor
node_processor -->|"loads text"| node_loaders
node_processor -->|"chunks text"| node_chunker
node_chunker -->|"segments with"| node_embeddings
node_processor -->|"builds index"| node_faiss
node_faiss -->|"embeds documents"| node_embeddings
node_api -->|"answers question"| node_processor
node_processor -->|"searches index"| node_search
node_processor -->|"searches"| node_faiss
node_processor -->|"scores candidates"| node_reranker
node_processor -->|"submits top chunks"| node_qa
node_qa -->|"uses template"| node_prompt
node_qa -->|"generates answer"| node_ollama
node_api -->|"returns response"| node_client

click node_api "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_uploads "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_processor "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_loaders "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_chunker "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_embeddings "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_faiss "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_search "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_reranker "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_qa "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py"
click node_prompt "https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/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_api,node_uploads,node_client toneBlue
class node_processor,node_loaders,node_chunker,node_embeddings toneAmber
class node_faiss,node_search,node_reranker toneMint
class node_qa,node_prompt,node_ollama toneRose
```

## Components

### API and uploads

- [FastAPI routes](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [Uploaded files](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`

### Document ingestion

- [FileProcessor](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [PDF/TXT loaders](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [Semantic chunker](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [BGE embeddings](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`

### Search and ranking

- [FAISS index](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [Similarity search](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [CrossEncoder reranker](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`

### Grounded answering

- [QA chain](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- [Grounding prompt](https://github.com/kvamshiformlops/multi-pdf-rag-chatbot-using-ollama-and-llama3.2/blob/main/app.py): `app.py`
- **Ollama LLM**

### Other components

- **API client**

## Connections

- API client → FastAPI routes: uploads or asks (evidence: `README.md`)
- FastAPI routes → Uploaded files: writes files (evidence: `app.py`)
- FastAPI routes → FileProcessor: processes files (evidence: `app.py`)
- Uploaded files → FileProcessor: provides paths (evidence: `app.py`)
- FileProcessor → PDF/TXT loaders: loads text (evidence: `app.py`)
- FileProcessor → Semantic chunker: chunks text (evidence: `app.py`)
- Semantic chunker → BGE embeddings: segments with (evidence: `app.py`)
- FileProcessor → FAISS index: builds index (evidence: `app.py`)
- FAISS index → BGE embeddings: embeds documents (evidence: `app.py`)
- FastAPI routes → FileProcessor: answers question (evidence: `app.py`)
- FileProcessor → Similarity search: searches index (evidence: `app.py`)
- FileProcessor → FAISS index: searches (evidence: `app.py`)
- FileProcessor → CrossEncoder reranker: scores candidates (evidence: `app.py`)
- FileProcessor → QA chain: submits top chunks (evidence: `app.py`)
- QA chain → Grounding prompt: uses template (evidence: `app.py`)
- QA chain → Ollama LLM: generates answer (evidence: `app.py`)
- FastAPI routes → API client: returns response (evidence: `app.py`)
