# shreya2338/epa-consultant-agent architecture

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

- Interactive diagram: https://gitdiagram.com/shreya2338/epa-consultant-agent
- Repository: https://github.com/shreya2338/epa-consultant-agent
- Video tour (about a minute): https://gitdiagram.com/shreya2338/epa-consultant-agent/video

## Overview

EPA Consultant Agent is a browser-based RAG question-answering system for EPA permit documents. Users can ask for grounded answers with citations and retrieved evidence, inspect raw matching excerpts, or browse and open extracted tables. The documented preparation path extracts PDF content and tables, creates heading-based chunks, and adds table content; retrieval combines keyword, semantic, and diversity search before reranking. The excerpts show the frontend/API and retrieval wiring, but not all table-serving and document-preparation connections, so those links are omitted where unverified.

Main entry points: [`retrieval/retrieval_langchain.py`](https://github.com/shreya2338/epa-consultant-agent/blob/main/retrieval/retrieval_langchain.py) (Hybrid retrieval and reranking), [`api.py`](https://github.com/shreya2338/epa-consultant-agent/blob/main/api.py) (FastAPI endpoints), [`data/heading-chunks-w-title.json`](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/heading-chunks-w-title.json) (Heading and table chunks), [`2026-pgp.pdf`](https://github.com/shreya2338/epa-consultant-agent/blob/main/2026-pgp.pdf) (Permit PDF)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_webui["Chat and table UI<br/>[script.js]"]
end

subgraph group_service["API and answers"]
  node_api["FastAPI endpoints<br/>[api.py]"]
  node_answer["Grounded answer generation<br/>[api.py]"]
  node_settings["Runtime settings<br/>[config.py]"]
end

subgraph group_retrieval["Search and ranking"]
  node_retrieval_engine["Hybrid retrieval and reranking"]
  node_faiss[("FAISS document index")]
end

subgraph group_documents["Document preparation"]
  node_chunkdata["Heading and table chunks"]
  node_heading_chunks["Heading-based chunking"]
  node_char_chunks["Character chunking<br/>[chunk_by_char.py]"]
  node_pdf_processor["PDF and table extraction"]
  node_table_augment["Table-to-chunk conversion"]
  node_table_data["Processed table data"]
end

node_user(("Browser user"))
node_openai{{"OpenAI services"}}
node_pdf["Permit PDF<br/>[2026-pgp.pdf]"]

node_user -->|"asks or browses"| node_webui
node_webui -->|"sends requests"| node_api
node_api -->|"retrieves passages"| node_retrieval_engine
node_api -->|"requests answer"| node_answer
node_answer -->|"generates answer"| node_openai
node_retrieval_engine -->|"reads settings"| node_settings
node_retrieval_engine -->|"searches index"| node_faiss
node_retrieval_engine -->|"loads chunks"| node_chunkdata
node_retrieval_engine -->|"embeds queries"| node_openai
node_heading_chunks -->|"loads pages"| node_pdf
node_heading_chunks -->|"writes chunks"| node_chunkdata
node_char_chunks -->|"loads pages"| node_pdf
node_pdf_processor -->|"processes PDF"| node_pdf
node_table_augment -->|"loads tables"| node_table_data
node_table_augment -->|"extends chunks"| node_chunkdata

click node_webui "https://github.com/shreya2338/epa-consultant-agent/blob/main/frontend/script.js"
click node_api "https://github.com/shreya2338/epa-consultant-agent/blob/main/api.py"
click node_answer "https://github.com/shreya2338/epa-consultant-agent/blob/main/api.py"
click node_settings "https://github.com/shreya2338/epa-consultant-agent/blob/main/config.py"
click node_retrieval_engine "https://github.com/shreya2338/epa-consultant-agent/blob/main/retrieval/retrieval_langchain.py"
click node_faiss "https://github.com/shreya2338/epa-consultant-agent/blob/main/official_faiss_store_with_tables.faiss"
click node_chunkdata "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/heading-chunks-w-title.json"
click node_pdf "https://github.com/shreya2338/epa-consultant-agent/blob/main/2026-pgp.pdf"
click node_heading_chunks "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/chunk_by_heading.py"
click node_char_chunks "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/chunk_by_char.py"
click node_pdf_processor "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/document_processor.py"
click node_table_augment "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/prepare_table_data.py"
click node_table_data "https://github.com/shreya2338/epa-consultant-agent/blob/main/data/processed_document.json"

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_webui,node_user toneBlue
class node_api,node_answer,node_settings toneAmber
class node_retrieval_engine,node_faiss toneMint
class node_chunkdata,node_heading_chunks,node_char_chunks,node_pdf_processor,node_table_augment,node_table_data toneRose
class node_openai toneIndigo
class node_pdf toneTeal
```

## Components

### User interface

- [Chat and table UI](https://github.com/shreya2338/epa-consultant-agent/blob/main/frontend/script.js): `frontend/script.js`

### API and answers

- [FastAPI endpoints](https://github.com/shreya2338/epa-consultant-agent/blob/main/api.py): `api.py`
- [Grounded answer generation](https://github.com/shreya2338/epa-consultant-agent/blob/main/api.py): `api.py`
- [Runtime settings](https://github.com/shreya2338/epa-consultant-agent/blob/main/config.py): `config.py`

### Search and ranking

- [Hybrid retrieval and reranking](https://github.com/shreya2338/epa-consultant-agent/blob/main/retrieval/retrieval_langchain.py): `retrieval/retrieval_langchain.py`
- [FAISS document index](https://github.com/shreya2338/epa-consultant-agent/blob/main/official_faiss_store_with_tables.faiss): `official_faiss_store_with_tables.faiss`

### Document preparation

- [Heading and table chunks](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/heading-chunks-w-title.json): `data/heading-chunks-w-title.json`
- [Heading-based chunking](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/chunk_by_heading.py): `data/chunk_by_heading.py`
- [Character chunking](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/chunk_by_char.py): `data/chunk_by_char.py`
- [PDF and table extraction](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/document_processor.py): `data/document_processor.py`
- [Table-to-chunk conversion](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/prepare_table_data.py): `data/prepare_table_data.py`
- [Processed table data](https://github.com/shreya2338/epa-consultant-agent/blob/main/data/processed_document.json): `data/processed_document.json`

### Other components

- **Browser user**
- **OpenAI services**
- [Permit PDF](https://github.com/shreya2338/epa-consultant-agent/blob/main/2026-pgp.pdf): `2026-pgp.pdf`

## Connections

- Browser user → Chat and table UI: asks or browses (evidence: `frontend/script.js`)
- Chat and table UI → FastAPI endpoints: sends requests (evidence: `frontend/script.js`)
- FastAPI endpoints → Hybrid retrieval and reranking: retrieves passages (evidence: `api.py`)
- FastAPI endpoints → Grounded answer generation: requests answer (evidence: `api.py`)
- Grounded answer generation → OpenAI services: generates answer (evidence: `api.py`)
- Hybrid retrieval and reranking → Runtime settings: reads settings (evidence: `retrieval/retrieval_langchain.py`)
- Hybrid retrieval and reranking → FAISS document index: searches index (evidence: `retrieval/retrieval_langchain.py`)
- Hybrid retrieval and reranking → Heading and table chunks: loads chunks (evidence: `retrieval/retrieval_langchain.py`)
- Hybrid retrieval and reranking → OpenAI services: embeds queries (evidence: `retrieval/retrieval_langchain.py`)
- Heading-based chunking → Permit PDF: loads pages (evidence: `data/chunk_by_heading.py`)
- Heading-based chunking → Heading and table chunks: writes chunks (evidence: `data/chunk_by_heading.py`)
- Character chunking → Permit PDF: loads pages (evidence: `data/chunk_by_char.py`)
- PDF and table extraction → Permit PDF: processes PDF (evidence: `data/document_processor.py`)
- Table-to-chunk conversion → Processed table data: loads tables (evidence: `data/prepare_table_data.py`)
- Table-to-chunk conversion → Heading and table chunks: extends chunks (evidence: `data/prepare_table_data.py`)
