# batrabhavye/ai-document-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/batrabhavye/ai-document-assistant
- Repository: https://github.com/batrabhavye/ai-document-assistant

## Overview

This is a local, PDF-focused RAG assistant. The main user workflow runs from Streamlit upload through PDF extraction and chunking, hybrid indexing, fused retrieval, and citation-grounded Ollama answers. A separate evaluation script measures faithfulness and answer relevancy with RAGAS and records results. The README documents these capabilities; implementation detail is available for the app, retrieval engine, and evaluation script, but no separate source files for the individual retrieval stages exist.

Main entry points: [`app.py`](https://github.com/batrabhavye/ai-document-assistant/blob/main/app.py) (Streamlit assistant), [`evaluate.py`](https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluate.py) (RAGAS evaluation), [`utils.py`](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py) (RRF search), [`evaluation_results.csv`](https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluation_results.csv) (Evaluation results)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_streamlit["Streamlit assistant<br/>[app.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_pdf["PDF extraction<br/>[utils.py]"]
  node_chunking["Semantic chunking<br/>[utils.py]"]
end

subgraph group_retrieval["Hybrid retrieval"]
  node_faiss[("FAISS index<br/>[utils.py]")]
  node_bm25[("BM25 index<br/>[utils.py]")]
  node_fusion["RRF search<br/>[utils.py]"]
end

subgraph group_quality["Answer quality"]
  node_evaluation["RAGAS evaluation<br/>[evaluate.py]"]
  node_metrics["Evaluation results"]
end

node_user(("User"))
node_ollama["Local Ollama models"]

node_user -->|"uploads and asks"| node_streamlit
node_streamlit -->|"processes PDF"| node_pdf
node_pdf -->|"extracts and splits"| node_chunking
node_streamlit -->|"builds index"| node_faiss
node_streamlit -->|"builds index"| node_bm25
node_faiss -->|"ranks semantically"| node_fusion
node_bm25 -->|"ranks keywords"| node_fusion
node_streamlit -->|"requests retrieval"| node_fusion
node_fusion -->|"returns chunks"| node_streamlit
node_streamlit -->|"generates grounded answer"| node_ollama
node_evaluation -->|"loads test document"| node_pdf
node_evaluation -->|"builds index"| node_faiss
node_evaluation -->|"builds index"| node_bm25
node_evaluation -->|"retrieves context"| node_fusion
node_evaluation -->|"generates test answers"| node_ollama
node_evaluation -->|"writes scores"| node_metrics

click node_streamlit "https://github.com/batrabhavye/ai-document-assistant/blob/main/app.py"
click node_pdf "https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py"
click node_chunking "https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py"
click node_faiss "https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py"
click node_bm25 "https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py"
click node_fusion "https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py"
click node_evaluation "https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluate.py"
click node_metrics "https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluation_results.csv"

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_streamlit,node_user toneBlue
class node_pdf,node_chunking toneAmber
class node_faiss,node_bm25,node_fusion toneMint
class node_evaluation,node_metrics toneRose
class node_ollama toneIndigo
```

## Components

### User interface

- [Streamlit assistant](https://github.com/batrabhavye/ai-document-assistant/blob/main/app.py): `app.py`

### Document ingestion

- [PDF extraction](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py): `utils.py`
- [Semantic chunking](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py): `utils.py`

### Hybrid retrieval

- [FAISS index](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py): `utils.py`
- [BM25 index](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py): `utils.py`
- [RRF search](https://github.com/batrabhavye/ai-document-assistant/blob/main/utils.py): `utils.py`

### Answer quality

- [RAGAS evaluation](https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluate.py): `evaluate.py`
- [Evaluation results](https://github.com/batrabhavye/ai-document-assistant/blob/main/evaluation_results.csv): `evaluation_results.csv`

### Other components

- **User**
- **Local Ollama models**

## Connections

- User → Streamlit assistant: uploads and asks (evidence: `app.py`)
- Streamlit assistant → PDF extraction: processes PDF (evidence: `app.py`)
- PDF extraction → Semantic chunking: extracts and splits (evidence: `utils.py`)
- Streamlit assistant → FAISS index: builds index (evidence: `app.py`)
- Streamlit assistant → BM25 index: builds index (evidence: `app.py`)
- FAISS index → RRF search: ranks semantically (evidence: `utils.py`)
- BM25 index → RRF search: ranks keywords (evidence: `utils.py`)
- Streamlit assistant → RRF search: requests retrieval (evidence: `app.py`)
- RRF search → Streamlit assistant: returns chunks (evidence: `utils.py`)
- Streamlit assistant → Local Ollama models: generates grounded answer (evidence: `app.py`)
- RAGAS evaluation → PDF extraction: loads test document (evidence: `evaluate.py`)
- RAGAS evaluation → FAISS index: builds index (evidence: `evaluate.py`)
- RAGAS evaluation → BM25 index: builds index (evidence: `evaluate.py`)
- RAGAS evaluation → RRF search: retrieves context (evidence: `evaluate.py`)
- RAGAS evaluation → Local Ollama models: generates test answers (evidence: `evaluate.py`)
- RAGAS evaluation → Evaluation results: writes scores (evidence: `evaluate.py`)
