# alokssingh/pdf_question_answering_rag_with_pymupdf4llm architecture

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

- Interactive diagram: https://gitdiagram.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm
- Repository: https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm

## Overview

#### Purpose and actual entry points
This is a Python document-ingestion and retrieval/QA prototype centered on PDFs, web content, and an Ollama-backed RAG workflow. The README describes a broader pipeline, but the checked-in executable surface is script-oriented; no `main.py`, `data/`, or `scripts/` directory is present. Likely primary orchestration/QA entry point: `QA_without_runnable_ollama.py`.

#### Acquisition boundary
Documents can enter from remote PDF URLs, general web pages, or Google-discovered links:
- `pdf_downloader.py`
- `doc_downloader.py`
- `google_search.py`

These scripts form the external-network boundary and produce locally usable document artifacts/content for downstream extraction.

#### Web text ingestion
HTML/web-page content is fetched and converted into text and metadata before it can be indexed or queried:
- `text_downloader.py`
- `text_scrape.py`

This is parallel to PDF ingestion rather than a web application layer. It likely depends on changing third-party page structures and search results.

#### PDF extraction and layout handling
PDFs are transformed into structured text, with explicit handling for multi-column layouts:
- `pdf_information_extraction.py`
- `multi_column.py`

The stated extraction runtime is `pymupdf4llm`; README also claims bounding-box-based OCR/layout extraction. This stage is the key normalization boundary between binary source files and retrieval-ready text.

#### Retrieval-augmented QA
Question answering is represented by:
- `QA_without_runnable_ollama.py`

Per the README, the intended flow is: extracted text → embeddings → nearest-neighbor retrieval → retrieved context supplied to Ollama for response generation. The filename indicates this script may support QA logic without requiring a runnable local Ollama service, so Ollama availability should be treated as an optional/runtime-dependent boundary.

#### Vector-store and model infrastructure
The intended retrieval infrastructure is ChromaDB or FAISS, with Ollama as the local LLM service. These are material external runtimes/dependencies, although dedicated vector-store scripts described in the README are absent from the tree. Dependency declarations are centralized in `requirements.txt`.

#### Data flow and repository gaps
Expected end-to-end control flow is:
1. Discover/download PDFs or scrape web text.
2. Extract and normalize text, including multi-column PDFs.
3. Chunk/embed and persist vectors in ChromaDB or FAISS.
4. Retrieve relevant chunks for a user query.
5. Generate an answer through Ollama or a non-runnable fallback path.

`DCM_singapore_data.xlsx` is a checked-in data artifact that may be an alternate source or evaluation corpus, but it is not documented as part of the RAG pipeline. The README’s listed `main.py` and vector/retrieval scripts do not exist in this snapshot; integration is therefore distributed across the available scripts rather than a confirmed single CLI.

Main entry points: [`QA_without_runnable_ollama.py`](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/QA_without_runnable_ollama.py) (QA orchestration), [`pdf_information_extraction.py`](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/pdf_information_extraction.py) (PDF text extraction), [`doc_downloader.py`](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/doc_downloader.py) (Document downloader), [`requirements.txt`](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/requirements.txt) (Dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquire["Acquisition"]
  node_remote_pdfs["Remote PDF sources<br/>external source"]
  node_web_pages["Web pages<br/>external source"]
  node_google{{"Google search<br/>external service"}}
  node_pdf_downloader["PDF downloader<br/>Python script<br/>[pdf_downloader.py]"]
  node_doc_downloader["Document downloader<br/>Python script<br/>[doc_downloader.py]"]
  node_google_search["Google link discovery<br/>Python script<br/>[google_search.py]"]
end

subgraph group_normalize["Text Normalization"]
  node_text_downloader["Web text fetcher<br/>Python script<br/>[text_downloader.py]"]
  node_text_scrape["HTML text scraper<br/>Python script<br/>[text_scrape.py]"]
  node_pdf_extraction["PDF text extraction<br/>Python script"]
  node_multi_column["Multi-column layout<br/>Python module<br/>[multi_column.py]"]
  node_normalized_text["Normalized text<br/>intermediate content"]
end

subgraph group_qa["RAG QA"]
  node_qa_script["QA orchestration<br/>Python script"]
  node_vector_store[("ChromaDB or FAISS<br/>vector store")]
  node_ollama{{"Ollama<br/>local LLM runtime"}}
  node_fallback["Non-runnable fallback<br/>QA path"]
end

node_xlsx["Spreadsheet artifact<br/>data artifact"]
node_requirements["Dependencies<br/>dependency manifest<br/>[requirements.txt]"]

node_remote_pdfs -->|"downloads"| node_pdf_downloader
node_remote_pdfs -->|"downloads"| node_doc_downloader
node_google -->|"search results"| node_google_search
node_google_search -->|"discovered links"| node_doc_downloader
node_web_pages -->|"fetches"| node_text_downloader
node_text_downloader -->|"HTML content"| node_text_scrape
node_text_scrape -->|"text and metadata"| node_normalized_text
node_pdf_downloader -->|"PDF artifacts"| node_pdf_extraction
node_doc_downloader -->|"PDF artifacts"| node_pdf_extraction
node_multi_column -->|"layout handling"| node_pdf_extraction
node_pdf_extraction -->|"structured text"| node_normalized_text
node_normalized_text -->|"chunks and embeds"| node_qa_script
node_qa_script -->|"persists and retrieves vectors"| node_vector_store
node_vector_store -->|"relevant chunks"| node_qa_script
node_qa_script -->|"retrieved context"| node_ollama
node_qa_script -.->|"when runtime unavailable"| node_fallback
node_requirements -.->|"declares dependencies"| node_pdf_extraction
node_requirements -.->|"declares dependencies"| node_qa_script

click node_pdf_downloader "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/pdf_downloader.py"
click node_doc_downloader "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/doc_downloader.py"
click node_google_search "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/google_search.py"
click node_text_downloader "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/text_downloader.py"
click node_text_scrape "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/text_scrape.py"
click node_pdf_extraction "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/pdf_information_extraction.py"
click node_multi_column "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/multi_column.py"
click node_qa_script "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/QA_without_runnable_ollama.py"
click node_xlsx "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/DCM_singapore_data.xlsx"
click node_requirements "https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/requirements.txt"

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_remote_pdfs,node_web_pages,node_google,node_pdf_downloader,node_doc_downloader,node_google_search toneBlue
class node_text_downloader,node_text_scrape,node_pdf_extraction,node_multi_column,node_normalized_text toneAmber
class node_qa_script,node_vector_store,node_ollama,node_fallback toneMint
class node_xlsx,node_requirements toneNeutral
```

## Components

### Acquisition

Network-facing document discovery and download scripts.

- **Remote PDF sources**: external source
- **Web pages**: external source
- **Google search**: external service · Search-result structures are an external dependency.
- [PDF downloader](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/pdf_downloader.py): Python script · `pdf_downloader.py`
- [Document downloader](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/doc_downloader.py): Python script · `doc_downloader.py`
- [Google link discovery](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/google_search.py): Python script · `google_search.py`

### Text Normalization

PDF layout extraction and web-text conversion.

- [Web text fetcher](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/text_downloader.py): Python script · `text_downloader.py`
- [HTML text scraper](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/text_scrape.py): Python script · Converts pages into text and metadata. · `text_scrape.py`
- [PDF text extraction](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/pdf_information_extraction.py): Python script · Normalization boundary from PDF binaries to structured text. · `pdf_information_extraction.py`
- [Multi-column layout](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/multi_column.py): Python module · Handles multi-column PDF layout. · `multi_column.py`
- **Normalized text**: intermediate content · Extraction-ready corpus for chunking and embedding.

### RAG QA

Distributed retrieval and answer-generation workflow.

- [QA orchestration](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/QA_without_runnable_ollama.py): Python script · Likely primary retrieval and QA entry point. · `QA_without_runnable_ollama.py`
- **ChromaDB or FAISS**: vector store · Intended embedding persistence and nearest-neighbor retrieval runtime.
- **Ollama**: local LLM runtime · Optional runtime-dependent answer generation boundary.
- **Non-runnable fallback**: QA path · Supports QA logic when Ollama is unavailable.

### Other components

- [Spreadsheet artifact](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/DCM_singapore_data.xlsx): data artifact · Possible alternate source or evaluation corpus; not documented in the pipeline. · `DCM_singapore_data.xlsx`
- [Dependencies](https://github.com/alokssingh/pdf_question_answering_rag_with_pymupdf4llm/blob/main/requirements.txt): dependency manifest · Centralized Python dependency declarations. · `requirements.txt`

## Connections

- Remote PDF sources → PDF downloader: downloads
- Remote PDF sources → Document downloader: downloads
- Google search → Google link discovery: search results
- Google link discovery → Document downloader: discovered links
- Web pages → Web text fetcher: fetches
- Web text fetcher → HTML text scraper: HTML content
- HTML text scraper → Normalized text: text and metadata
- PDF downloader → PDF text extraction: PDF artifacts
- Document downloader → PDF text extraction: PDF artifacts
- Multi-column layout → PDF text extraction: layout handling
- PDF text extraction → Normalized text: structured text
- Normalized text → QA orchestration: chunks and embeds
- QA orchestration → ChromaDB or FAISS: persists and retrieves vectors
- ChromaDB or FAISS → QA orchestration: relevant chunks
- QA orchestration → Ollama: retrieved context
- QA orchestration → Non-runnable fallback: when runtime unavailable
- Dependencies → PDF text extraction: declares dependencies
- Dependencies → QA orchestration: declares dependencies
