# sreevathsans/chatpdf architecture

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

- Interactive diagram: https://gitdiagram.com/sreevathsans/chatpdf
- Repository: https://github.com/sreevathsans/chatpdf

## Overview

ChatPDF is a local PDF question-answering application. Users upload a PDF through Streamlit; the app extracts, chunks, embeds, and indexes its text. For a question, the app invokes the high-level chat pipeline, which retrieves relevant chunks, builds a context-bound prompt, and requests an answer from a local Ollama server. The graph distinguishes document ingestion from question answering and includes embedding, retrieval, and persistent storage layers. Relationships are based on the shown source excerpts and README; storage paths are named in the vector-store implementation, but the stored binary contents were not inspected.

Main entry points: [`app.py`](https://github.com/sreevathsans/chatpdf/blob/main/app.py) (Streamlit app), [`vector_store.py`](https://github.com/sreevathsans/chatpdf/blob/main/vector_store.py) (FAISS vector store), [`rag.py`](https://github.com/sreevathsans/chatpdf/blob/main/rag.py) (RAG retrieval), [`rag_pipeline.py`](https://github.com/sreevathsans/chatpdf/blob/main/rag_pipeline.py) (Chat pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_pdf_files["Uploaded PDFs"]
  node_extractor["PDF extraction<br/>[extractor.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_embedding_generation["Chunk embeddings<br/>[embeddings.py]"]
end

subgraph group_retrieval["Retrieval and storage"]
  node_embedding_model["SentenceTransformer model<br/>[embeddings.py]"]
  node_vector_store["FAISS vector store<br/>[vector_store.py]"]
  node_faiss_index[("FAISS index file<br/>[faiss_index.bin]")]
  node_chunk_metadata[("Chunk metadata file<br/>[metadata.pkl]")]
  node_rag["RAG retrieval<br/>[rag.py]"]
end

subgraph group_answering["Answer generation"]
  node_chat_pipeline["Chat pipeline<br/>[rag_pipeline.py]"]
  node_prompt_builder["Context prompt<br/>[rag_pipeline.py]"]
  node_llm_client["Ollama client<br/>[llm.py]"]
end

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

node_user(("PDF user"))
node_ollama{{"Ollama server"}}

node_user -->|"uses"| node_app
node_app -->|"saves upload"| node_pdf_files
node_app -->|"extracts text"| node_extractor
node_extractor -.-> node_chunker
node_app -->|"creates chunks"| node_chunker
node_app -->|"embeds chunks"| node_embedding_generation
node_embedding_generation -->|"encodes chunks"| node_embedding_model
node_app -->|"builds and saves"| node_vector_store
node_vector_store -->|"writes and loads"| node_faiss_index
node_vector_store -->|"writes and loads"| node_chunk_metadata
node_user -->|"asks question"| node_app
node_app -->|"asks"| node_chat_pipeline
node_chat_pipeline -->|"retrieves chunks"| node_rag
node_rag -->|"embeds query"| node_embedding_model
node_rag -->|"searches vectors"| node_vector_store
node_chat_pipeline -->|"builds context prompt"| node_prompt_builder
node_prompt_builder -->|"provides prompt"| node_llm_client
node_llm_client -->|"sends generation request"| node_ollama

click node_app "https://github.com/sreevathsans/chatpdf/blob/main/app.py"
click node_pdf_files "https://github.com/sreevathsans/chatpdf/tree/main/data"
click node_extractor "https://github.com/sreevathsans/chatpdf/blob/main/extractor.py"
click node_chunker "https://github.com/sreevathsans/chatpdf/blob/main/chunker.py"
click node_embedding_model "https://github.com/sreevathsans/chatpdf/blob/main/embeddings.py"
click node_embedding_generation "https://github.com/sreevathsans/chatpdf/blob/main/embeddings.py"
click node_vector_store "https://github.com/sreevathsans/chatpdf/blob/main/vector_store.py"
click node_faiss_index "https://github.com/sreevathsans/chatpdf/blob/main/db/faiss_index.bin"
click node_chunk_metadata "https://github.com/sreevathsans/chatpdf/blob/main/db/metadata.pkl"
click node_chat_pipeline "https://github.com/sreevathsans/chatpdf/blob/main/rag_pipeline.py"
click node_rag "https://github.com/sreevathsans/chatpdf/blob/main/rag.py"
click node_prompt_builder "https://github.com/sreevathsans/chatpdf/blob/main/rag_pipeline.py"
click node_llm_client "https://github.com/sreevathsans/chatpdf/blob/main/llm.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_pdf_files,node_extractor,node_chunker,node_embedding_generation,node_user toneBlue
class node_embedding_model,node_vector_store,node_faiss_index,node_chunk_metadata,node_rag toneAmber
class node_chat_pipeline,node_prompt_builder,node_llm_client,node_ollama toneMint
class node_app toneRose
```

## Components

### Document ingestion

- [Uploaded PDFs](https://github.com/sreevathsans/chatpdf/tree/main/data): `data`
- [PDF extraction](https://github.com/sreevathsans/chatpdf/blob/main/extractor.py): `extractor.py`
- [Text chunking](https://github.com/sreevathsans/chatpdf/blob/main/chunker.py): `chunker.py`
- [Chunk embeddings](https://github.com/sreevathsans/chatpdf/blob/main/embeddings.py): `embeddings.py`

### Retrieval and storage

- [SentenceTransformer model](https://github.com/sreevathsans/chatpdf/blob/main/embeddings.py): `embeddings.py`
- [FAISS vector store](https://github.com/sreevathsans/chatpdf/blob/main/vector_store.py): `vector_store.py`
- [FAISS index file](https://github.com/sreevathsans/chatpdf/blob/main/db/faiss_index.bin): `db/faiss_index.bin`
- [Chunk metadata file](https://github.com/sreevathsans/chatpdf/blob/main/db/metadata.pkl): `db/metadata.pkl`
- [RAG retrieval](https://github.com/sreevathsans/chatpdf/blob/main/rag.py): `rag.py`

### Answer generation

- [Chat pipeline](https://github.com/sreevathsans/chatpdf/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [Context prompt](https://github.com/sreevathsans/chatpdf/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [Ollama client](https://github.com/sreevathsans/chatpdf/blob/main/llm.py): `llm.py`

### User interface

- [Streamlit app](https://github.com/sreevathsans/chatpdf/blob/main/app.py): `app.py`

### Other components

- **PDF user**
- **Ollama server**

## Connections

- PDF user → Streamlit app: uses (evidence: `README.md`)
- Streamlit app → Uploaded PDFs: saves upload (evidence: `app.py`)
- Streamlit app → PDF extraction: extracts text (evidence: `app.py`)
- PDF extraction → Text chunking
- Streamlit app → Text chunking: creates chunks (evidence: `app.py`)
- Streamlit app → Chunk embeddings: embeds chunks (evidence: `app.py`)
- Chunk embeddings → SentenceTransformer model: encodes chunks (evidence: `embeddings.py`)
- Streamlit app → FAISS vector store: builds and saves (evidence: `app.py`)
- FAISS vector store → FAISS index file: writes and loads (evidence: `vector_store.py`)
- FAISS vector store → Chunk metadata file: writes and loads (evidence: `vector_store.py`)
- PDF user → Streamlit app: asks question (evidence: `README.md`)
- Streamlit app → Chat pipeline: asks (evidence: `app.py`)
- Chat pipeline → RAG retrieval: retrieves chunks (evidence: `rag_pipeline.py`)
- RAG retrieval → SentenceTransformer model: embeds query (evidence: `rag.py`)
- RAG retrieval → FAISS vector store: searches vectors (evidence: `rag.py`)
- Chat pipeline → Context prompt: builds context prompt (evidence: `rag_pipeline.py`)
- Context prompt → Ollama client: provides prompt (evidence: `rag_pipeline.py`)
- Ollama client → Ollama server: sends generation request (evidence: `llm.py`)
