# preethu13/insurance-rag-system architecture

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

- Interactive diagram: https://gitdiagram.com/preethu13/insurance-rag-system
- Repository: https://github.com/preethu13/insurance-rag-system

## Overview

This repository is an insurance-document RAG question-answering product, with both a documented CLI flow and a web/API interface backed by a Phase 2 multi-agent pipeline. The documented document path is PDF OCR and extraction, clause-aware indexing, hybrid retrieval, then grounded answers; the API routes queries into the orchestrator. Phase 2’s workflow sequence names query understanding, retrieval, verification, reasoning, risk, and contradiction stages. Observability is a separate internal capability. Some implementation details are unsampled, so uncertain internal dispatch links are marked dashed.

Main entry points: [`phase2/orchestrator/orchestrator.py`](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/orchestrator.py) (Agent orchestrator), [`phase2/orchestrator/workflow_engine.py`](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/workflow_engine.py) (Workflow sequence), [`backend/app/routers/query.py`](https://github.com/preethu13/insurance-rag-system/blob/main/backend/app/routers/query.py) (Query endpoint), [`app.py`](https://github.com/preethu13/insurance-rag-system/blob/main/app.py) (CLI query interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document preparation"]
  node_ingest_script["OCR extraction<br/>[ingest.py]"]
  node_extracted["Extracted JSON"]
  node_index_script["Clause indexing<br/>[index.py]"]
  node_vector_store[("ChromaDB")]
  node_keyword_store[("BM25 index")]
end

subgraph group_interface["User interfaces"]
  node_dashboard["Query dashboard<br/>[QueryDashboard.tsx]"]
  node_api_client["Frontend API client<br/>[apiClient.ts]"]
  node_query_api["Query endpoint<br/>[query.py]"]
  node_cli["CLI query interface<br/>[app.py]"]
end

subgraph group_pipeline["Answer pipeline"]
  node_orchestrator["Agent orchestrator<br/>[orchestrator.py]"]
  node_workflow["Workflow sequence<br/>[workflow_engine.py]"]
  node_query_agent["Query understanding<br/>[query_agent.py]"]
  node_query_processing["Query processing"]
end

subgraph group_analysis["Evidence analysis"]
  node_retrieval_agent["Evidence retrieval<br/>[retrieval_agent.py]"]
  node_retrieval_service["Hybrid retrieval"]
  node_verification["Evidence verification"]
  node_reasoning["Policy reasoning<br/>[reasoning_agent.py]"]
  node_risk["Risk assessment<br/>[risk_agent.py]"]
  node_contradiction["Contradiction analysis"]
  node_response["Response builder"]
end

subgraph group_observability["Observability"]
  node_obs_facade["Observability facade<br/>[facade.py]"]
  node_obs_sqlite[("SQLite telemetry store<br/>[sqlite_storage.py]")]
  node_obs_json[("JSONL telemetry store<br/>[json_storage.py]")]
end

node_user(("Question asker"))
node_pdfs["Policy PDFs"]

node_pdfs -->|"extracts text"| node_ingest_script
node_ingest_script -->|"writes JSON"| node_extracted
node_extracted -->|"chunks documents"| node_index_script
node_index_script -->|"builds vector index"| node_vector_store
node_index_script -->|"builds keyword index"| node_keyword_store
node_user -->|"asks question"| node_dashboard
node_dashboard -->|"submits query"| node_api_client
node_api_client -.->|"sends API request"| node_query_api
node_user -->|"asks question"| node_cli
node_cli -->|"retrieves evidence"| node_vector_store
node_cli -->|"retrieves evidence"| node_keyword_store
node_cli -->|"returns grounded answer"| node_user
node_query_api -->|"orchestrates query"| node_orchestrator
node_orchestrator -.->|"gets execution sequence"| node_workflow
node_workflow -->|"names stage"| node_query_agent
node_workflow -->|"names stage"| node_retrieval_agent
node_workflow -->|"names stage"| node_verification
node_workflow -->|"names stage"| node_reasoning
node_workflow -->|"names stage"| node_risk
node_workflow -->|"names stage"| node_contradiction
node_query_agent -->|"processes query"| node_query_processing
node_orchestrator -.->|"dispatches query"| node_query_agent
node_orchestrator -.->|"dispatches stage"| node_retrieval_agent
node_orchestrator -.->|"dispatches stage"| node_verification
node_orchestrator -.->|"dispatches stage"| node_reasoning
node_orchestrator -.->|"dispatches stage"| node_risk
node_orchestrator -.->|"dispatches stage"| node_contradiction
node_retrieval_agent -.->|"uses retrieval service"| node_retrieval_service
node_retrieval_service -.->|"searches vectors"| node_vector_store
node_retrieval_service -.->|"searches keywords"| node_keyword_store
node_orchestrator -.->|"builds final response"| node_response
node_query_api -->|"reads reasoning result"| node_reasoning
node_query_api -.->|"returns response"| node_user
node_obs_facade -.->|"stores telemetry"| node_obs_sqlite
node_obs_facade -.->|"stores telemetry"| node_obs_json

click node_ingest_script "https://github.com/preethu13/insurance-rag-system/blob/main/ingest.py"
click node_index_script "https://github.com/preethu13/insurance-rag-system/blob/main/index.py"
click node_dashboard "https://github.com/preethu13/insurance-rag-system/blob/main/frontend/src/components/QueryDashboard.tsx"
click node_api_client "https://github.com/preethu13/insurance-rag-system/blob/main/frontend/src/services/apiClient.ts"
click node_query_api "https://github.com/preethu13/insurance-rag-system/blob/main/backend/app/routers/query.py"
click node_cli "https://github.com/preethu13/insurance-rag-system/blob/main/app.py"
click node_orchestrator "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/orchestrator.py"
click node_workflow "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/workflow_engine.py"
click node_query_agent "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/query_agent.py"
click node_query_processing "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/services/query_processing_service.py"
click node_retrieval_agent "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/retrieval_agent.py"
click node_retrieval_service "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/services/retrieval_service.py"
click node_verification "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/verification_agent.py"
click node_reasoning "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/reasoning_agent.py"
click node_risk "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/risk_agent.py"
click node_contradiction "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/contradiction_agent.py"
click node_response "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/response_builder.py"
click node_obs_facade "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/facade.py"
click node_obs_sqlite "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/storage/sqlite_storage.py"
click node_obs_json "https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/storage/json_storage.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_ingest_script,node_extracted,node_index_script,node_vector_store,node_keyword_store toneBlue
class node_dashboard,node_api_client,node_query_api,node_cli toneAmber
class node_orchestrator,node_workflow,node_query_agent,node_query_processing toneMint
class node_retrieval_agent,node_retrieval_service,node_verification,node_reasoning,node_risk,node_contradiction,node_response toneRose
class node_obs_facade,node_obs_sqlite,node_obs_json,node_user,node_pdfs toneIndigo
```

## Components

### Document preparation

- [OCR extraction](https://github.com/preethu13/insurance-rag-system/blob/main/ingest.py): `ingest.py`
- **Extracted JSON**
- [Clause indexing](https://github.com/preethu13/insurance-rag-system/blob/main/index.py): `index.py`
- **ChromaDB**
- **BM25 index**

### User interfaces

- [Query dashboard](https://github.com/preethu13/insurance-rag-system/blob/main/frontend/src/components/QueryDashboard.tsx): `frontend/src/components/QueryDashboard.tsx`
- [Frontend API client](https://github.com/preethu13/insurance-rag-system/blob/main/frontend/src/services/apiClient.ts): `frontend/src/services/apiClient.ts`
- [Query endpoint](https://github.com/preethu13/insurance-rag-system/blob/main/backend/app/routers/query.py): `backend/app/routers/query.py`
- [CLI query interface](https://github.com/preethu13/insurance-rag-system/blob/main/app.py): `app.py`

### Answer pipeline

- [Agent orchestrator](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/orchestrator.py): `phase2/orchestrator/orchestrator.py`
- [Workflow sequence](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/orchestrator/workflow_engine.py): `phase2/orchestrator/workflow_engine.py`
- [Query understanding](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/query_agent.py): `phase2/agents/query_agent.py`
- [Query processing](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/services/query_processing_service.py): `phase2/services/query_processing_service.py`

### Evidence analysis

- [Evidence retrieval](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/retrieval_agent.py): `phase2/agents/retrieval_agent.py`
- [Hybrid retrieval](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/services/retrieval_service.py): `phase2/services/retrieval_service.py`
- [Evidence verification](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/verification_agent.py): `phase2/agents/verification_agent.py`
- [Policy reasoning](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/reasoning_agent.py): `phase2/agents/reasoning_agent.py`
- [Risk assessment](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/risk_agent.py): `phase2/agents/risk_agent.py`
- [Contradiction analysis](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/contradiction_agent.py): `phase2/agents/contradiction_agent.py`
- [Response builder](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/agents/response_builder.py): `phase2/agents/response_builder.py`

### Observability

- [Observability facade](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/facade.py): `phase2/observability/facade.py`
- [SQLite telemetry store](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/storage/sqlite_storage.py): `phase2/observability/storage/sqlite_storage.py`
- [JSONL telemetry store](https://github.com/preethu13/insurance-rag-system/blob/main/phase2/observability/storage/json_storage.py): `phase2/observability/storage/json_storage.py`

### Other components

- **Question asker**
- **Policy PDFs**

## Connections

- Policy PDFs → OCR extraction: extracts text (evidence: `README.md`)
- OCR extraction → Extracted JSON: writes JSON (evidence: `README.md`)
- Extracted JSON → Clause indexing: chunks documents (evidence: `README.md`)
- Clause indexing → ChromaDB: builds vector index (evidence: `README.md`)
- Clause indexing → BM25 index: builds keyword index (evidence: `README.md`)
- Question asker → Query dashboard: asks question (evidence: `frontend/src/components/QueryDashboard.tsx`)
- Query dashboard → Frontend API client: submits query (evidence: `frontend/src/components/QueryDashboard.tsx`)
- Frontend API client → Query endpoint: sends API request
- Question asker → CLI query interface: asks question (evidence: `README.md`)
- CLI query interface → ChromaDB: retrieves evidence (evidence: `README.md`)
- CLI query interface → BM25 index: retrieves evidence (evidence: `README.md`)
- CLI query interface → Question asker: returns grounded answer (evidence: `README.md`)
- Query endpoint → Agent orchestrator: orchestrates query (evidence: `backend/app/routers/query.py`)
- Agent orchestrator → Workflow sequence: gets execution sequence
- Workflow sequence → Query understanding: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Workflow sequence → Evidence retrieval: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Workflow sequence → Evidence verification: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Workflow sequence → Policy reasoning: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Workflow sequence → Risk assessment: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Workflow sequence → Contradiction analysis: names stage (evidence: `phase2/orchestrator/workflow_engine.py`)
- Query understanding → Query processing: processes query (evidence: `phase2/agents/query_agent.py`)
- Agent orchestrator → Query understanding: dispatches query
- Agent orchestrator → Evidence retrieval: dispatches stage
- Agent orchestrator → Evidence verification: dispatches stage
- Agent orchestrator → Policy reasoning: dispatches stage
- Agent orchestrator → Risk assessment: dispatches stage
- Agent orchestrator → Contradiction analysis: dispatches stage
- Evidence retrieval → Hybrid retrieval: uses retrieval service
- Hybrid retrieval → ChromaDB: searches vectors
- Hybrid retrieval → BM25 index: searches keywords
- Agent orchestrator → Response builder: builds final response
- Query endpoint → Policy reasoning: reads reasoning result (evidence: `backend/app/routers/query.py`)
- Query endpoint → Question asker: returns response
- Observability facade → SQLite telemetry store: stores telemetry
- Observability facade → JSONL telemetry store: stores telemetry
