# riesyaf/policy-agentic-rag architecture

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

- Interactive diagram: https://gitdiagram.com/riesyaf/policy-agentic-rag
- Repository: https://github.com/riesyaf/policy-agentic-rag

## Overview

The product is a Streamlit chat assistant that routes questions to QBE policy or general-insurance retrieval, then returns a grounded, cited answer. Its supporting data workflow extracts PDFs through separate hierarchical-policy and general-document pipelines, then indexes the resulting chunks in ChromaDB. The graph preserves both paths and the runtime’s routing, retrieval, citation construction, and answer generation. Relationships follow the excerpts and README; generated chunk files are pipeline intermediates, not present in the supplied tree.

Main entry points: [`src/agent.py`](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py) (Intent Router), [`src/rag_engine.py`](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py) (QBE Retrieval), [`src/indexing.py`](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/indexing.py) (Chunk Indexer), [`data`](https://github.com/riesyaf/policy-agentic-rag/tree/main/data) (PDF Collection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Chat and Routing"]
  node_ui["Chat UI<br/>[app.py]"]
  node_router["Intent Router<br/>[agent.py]"]
  node_qbe_tool["QBE Search Tool<br/>[agent.py]"]
  node_general_tool["General Search Tool<br/>[agent.py]"]
end

subgraph group_prep["Document Preparation"]
  node_qbe_pdfs["QBE Policy PDFs"]
  node_general_pdf["Industry Standards PDF"]
  node_policy_ingest["Policy Parser<br/>[ingestion.py]"]
  node_general_ingest["General Text Splitter<br/>[ingestion.py]"]
  node_indexer["Chunk Indexer<br/>[indexing.py]"]
  node_pdf_input["PDF Collection"]
end

subgraph group_rag["Retrieval and Answers"]
  node_qbe_rag["QBE Retrieval<br/>[rag_engine.py]"]
  node_general_rag["General Retrieval<br/>[rag_engine.py]"]
  node_citation_prompt["Citation Prompt Builder<br/>[rag_engine.py]"]
  node_answer_model["Answer Generation<br/>[rag_engine.py]"]
end

subgraph group_services["Data and Model Services"]
  node_vector_db[("ChromaDB")]
  node_routing_model["Routing LLM<br/>[agent.py]"]
  node_ollama["Ollama Service"]
end

node_user(("Questioner"))

node_user -->|"asks"| node_ui
node_ui -->|"streams to"| node_router
node_router -->|"routes with"| node_routing_model
node_routing_model -.->|"queries"| node_ollama
node_router -->|"dispatches"| node_qbe_tool
node_router -->|"dispatches"| node_general_tool
node_qbe_tool -->|"calls"| node_qbe_rag
node_general_tool -->|"calls"| node_general_rag
node_qbe_rag -->|"queries"| node_vector_db
node_general_rag -->|"queries"| node_vector_db
node_qbe_rag -->|"formats context"| node_citation_prompt
node_general_rag -->|"formats context"| node_citation_prompt
node_citation_prompt -->|"supplies prompt"| node_answer_model
node_answer_model -->|"generates with"| node_ollama
node_pdf_input -->|"provides PDFs"| node_policy_ingest
node_pdf_input -->|"provides PDFs"| node_general_ingest
node_policy_ingest -->|"indexes chunks"| node_indexer
node_general_ingest -->|"indexes chunks"| node_indexer
node_indexer -->|"upserts chunks"| node_vector_db

click node_ui "https://github.com/riesyaf/policy-agentic-rag/blob/main/app.py"
click node_router "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py"
click node_qbe_tool "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py"
click node_general_tool "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py"
click node_qbe_pdfs "https://github.com/riesyaf/policy-agentic-rag/tree/main/data/qbe"
click node_general_pdf "https://github.com/riesyaf/policy-agentic-rag/blob/main/data/general/10.sn-general-2008_eng_2017update.pdf"
click node_policy_ingest "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/ingestion.py"
click node_general_ingest "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/ingestion.py"
click node_indexer "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/indexing.py"
click node_qbe_rag "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py"
click node_general_rag "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py"
click node_citation_prompt "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py"
click node_answer_model "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py"
click node_routing_model "https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py"
click node_pdf_input "https://github.com/riesyaf/policy-agentic-rag/tree/main/data"

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_ui,node_router,node_qbe_tool,node_general_tool toneBlue
class node_qbe_pdfs,node_general_pdf,node_policy_ingest,node_general_ingest,node_indexer,node_pdf_input toneAmber
class node_qbe_rag,node_general_rag,node_citation_prompt,node_answer_model toneMint
class node_vector_db,node_routing_model,node_ollama toneRose
class node_user toneIndigo
```

## Components

### Chat and Routing

- [Chat UI](https://github.com/riesyaf/policy-agentic-rag/blob/main/app.py): `app.py`
- [Intent Router](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py): `src/agent.py`
- [QBE Search Tool](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py): `src/agent.py`
- [General Search Tool](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py): `src/agent.py`

### Document Preparation

- [QBE Policy PDFs](https://github.com/riesyaf/policy-agentic-rag/tree/main/data/qbe): `data/qbe`
- [Industry Standards PDF](https://github.com/riesyaf/policy-agentic-rag/blob/main/data/general/10.sn-general-2008_eng_2017update.pdf): `data/general/10.sn-general-2008_eng_2017update.pdf`
- [Policy Parser](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/ingestion.py): `src/ingestion.py`
- [General Text Splitter](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/ingestion.py): `src/ingestion.py`
- [Chunk Indexer](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/indexing.py): `src/indexing.py`
- [PDF Collection](https://github.com/riesyaf/policy-agentic-rag/tree/main/data): `data`

### Retrieval and Answers

- [QBE Retrieval](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py): `src/rag_engine.py`
- [General Retrieval](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py): `src/rag_engine.py`
- [Citation Prompt Builder](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py): `src/rag_engine.py`
- [Answer Generation](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/rag_engine.py): `src/rag_engine.py`

### Data and Model Services

- **ChromaDB**
- [Routing LLM](https://github.com/riesyaf/policy-agentic-rag/blob/main/src/agent.py): `src/agent.py`
- **Ollama Service**

### Other components

- **Questioner**

## Connections

- Questioner → Chat UI: asks (evidence: `app.py`)
- Chat UI → Intent Router: streams to (evidence: `app.py`)
- Intent Router → Routing LLM: routes with (evidence: `src/agent.py`)
- Routing LLM → Ollama Service: queries
- Intent Router → QBE Search Tool: dispatches (evidence: `src/agent.py`)
- Intent Router → General Search Tool: dispatches (evidence: `src/agent.py`)
- QBE Search Tool → QBE Retrieval: calls (evidence: `src/agent.py`)
- General Search Tool → General Retrieval: calls (evidence: `src/agent.py`)
- QBE Retrieval → ChromaDB: queries (evidence: `src/rag_engine.py`)
- General Retrieval → ChromaDB: queries (evidence: `src/rag_engine.py`)
- QBE Retrieval → Citation Prompt Builder: formats context (evidence: `src/rag_engine.py`)
- General Retrieval → Citation Prompt Builder: formats context (evidence: `src/rag_engine.py`)
- Citation Prompt Builder → Answer Generation: supplies prompt (evidence: `src/rag_engine.py`)
- Answer Generation → Ollama Service: generates with (evidence: `src/rag_engine.py`)
- PDF Collection → Policy Parser: provides PDFs (evidence: `README.md`)
- PDF Collection → General Text Splitter: provides PDFs (evidence: `README.md`)
- Policy Parser → Chunk Indexer: indexes chunks (evidence: `README.md`)
- General Text Splitter → Chunk Indexer: indexes chunks (evidence: `README.md`)
- Chunk Indexer → ChromaDB: upserts chunks (evidence: `src/indexing.py`)
