# sonali1554/envint-hybrid-rag architecture

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

- Interactive diagram: https://gitdiagram.com/sonali1554/envint-hybrid-rag
- Repository: https://github.com/sonali1554/envint-hybrid-rag

## Overview

Envint is a compliance question-answering and retrieval benchmark. A user submits a question and retrieval tier through the API; the retrieval engine loads policy chunks, searches and ranks them, then the answer layer applies evidence refusal, injection defense, and temporal-conflict handling before returning a cited response. The README also documents benchmarking, robustness checks, and request observability. Edges reflect shown source calls or README-described behavior; unsampled evaluation internals are represented without guessed connections.

Main entry points: [`app/retrieval/engine.py`](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/engine.py) (Retrieval engine), [`app/main.py`](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/main.py) (HTTP API), [`app/llm/client.py`](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/llm/client.py) (Answer generation), [`app/schema.py`](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/schema.py) (Chunk and API schemas)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and observability"]
  node_api["HTTP API<br/>[main.py]"]
  node_ui["Browser UI<br/>[index.html]"]
  node_middleware["Request metrics<br/>[middleware.py]"]
end

subgraph group_retrieval["Corpus and retrieval"]
  node_corpus["Policy corpus<br/>[corpus.json]"]
  node_ingest["Corpus loader<br/>[ingest.py]"]
  node_engine["Retrieval engine<br/>[engine.py]"]
  node_vector["Vector search<br/>[vector.py]"]
  node_qdrant[("Qdrant index")]
  node_bm25["BM25 search<br/>[bm25.py]"]
  node_rrf["RRF fusion<br/>[rrf.py]"]
  node_reranker["Cross-encoder reranker<br/>[rerank.py]"]
end

subgraph group_answering["Grounded answering"]
  node_answer["Answer generation<br/>[client.py]"]
  node_guardrails["Answer guardrails<br/>[guardrails.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_benchmark["Tier benchmark<br/>[benchmark.py]"]
  node_robustness["LLM robustness<br/>[llm_robustness.py]"]
  node_evalmetrics["Retrieval metrics<br/>[metrics.py]"]
  node_cost["Compute cost estimate<br/>[cost.py]"]
end

subgraph group_foundation["Shared foundations"]
  node_embeddings["Embedding backends<br/>[embeddings.py]"]
  node_schema["Chunk and API schemas<br/>[schema.py]"]
  node_config["Application settings<br/>[config.py]"]
end

node_user(("Questioner"))
node_ollama["Local Ollama"]

node_user -->|"submits question"| node_api
node_api -->|"serves page"| node_ui
node_api -->|"requests retrieval"| node_engine
node_api -->|"requests answer"| node_answer
node_api -->|"registers middleware"| node_middleware
node_api -->|"validates payloads"| node_schema
node_api -->|"reads settings"| node_config
node_engine -->|"loads corpus"| node_ingest
node_ingest -->|"reads records"| node_corpus
node_ingest -->|"validates chunks"| node_schema
node_engine -->|"indexes and searches"| node_vector
node_engine -->|"indexes and searches"| node_bm25
node_engine -->|"fuses ranked hits"| node_rrf
node_engine -->|"reranks candidates"| node_reranker
node_vector -->|"reads and writes"| node_qdrant
node_vector -->|"encodes text"| node_embeddings
node_vector -->|"uses chunk model"| node_schema
node_engine -->|"returns ranked chunks"| node_schema
node_answer -->|"checks evidence"| node_guardrails
node_answer -.->|"generates answer"| node_ollama
node_answer -->|"uses result models"| node_schema
node_benchmark -->|"benchmarks tiers"| node_engine
node_robustness -->|"exercises retrieval"| node_engine
node_robustness -->|"exercises answering"| node_answer
node_robustness -->|"exercises safety"| node_guardrails
node_benchmark -.->|"scores results"| node_evalmetrics
node_benchmark -.->|"estimates compute cost"| node_cost
node_engine -->|"reads settings"| node_config
node_embeddings -->|"selects backend"| node_config

click node_api "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/main.py"
click node_ui "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/static/index.html"
click node_middleware "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/obs/middleware.py"
click node_corpus "https://github.com/sonali1554/envint-hybrid-rag/blob/main/data/corpus/corpus.json"
click node_ingest "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/ingest.py"
click node_engine "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/engine.py"
click node_vector "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/vector.py"
click node_bm25 "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/bm25.py"
click node_rrf "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/rrf.py"
click node_reranker "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/rerank.py"
click node_answer "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/llm/client.py"
click node_guardrails "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/llm/guardrails.py"
click node_benchmark "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/benchmark.py"
click node_robustness "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/llm_robustness.py"
click node_evalmetrics "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/metrics.py"
click node_cost "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/cost.py"
click node_embeddings "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/embeddings.py"
click node_schema "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/schema.py"
click node_config "https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/config.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_api,node_ui,node_middleware toneBlue
class node_corpus,node_ingest,node_engine,node_vector,node_qdrant,node_bm25,node_rrf,node_reranker toneAmber
class node_answer,node_guardrails toneMint
class node_benchmark,node_robustness,node_evalmetrics,node_cost toneRose
class node_embeddings,node_schema,node_config,node_user,node_ollama toneIndigo
```

## Components

### API and observability

- [HTTP API](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/main.py): `app/main.py`
- [Browser UI](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/static/index.html): `app/static/index.html`
- [Request metrics](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/obs/middleware.py): `app/obs/middleware.py`

### Corpus and retrieval

- [Policy corpus](https://github.com/sonali1554/envint-hybrid-rag/blob/main/data/corpus/corpus.json): `data/corpus/corpus.json`
- [Corpus loader](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/ingest.py): `app/ingest.py`
- [Retrieval engine](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/engine.py): `app/retrieval/engine.py`
- [Vector search](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/vector.py): `app/retrieval/vector.py`
- **Qdrant index**
- [BM25 search](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/bm25.py): `app/retrieval/bm25.py`
- [RRF fusion](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/rrf.py): `app/retrieval/rrf.py`
- [Cross-encoder reranker](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/retrieval/rerank.py): `app/retrieval/rerank.py`

### Grounded answering

- [Answer generation](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/llm/client.py): `app/llm/client.py`
- [Answer guardrails](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/llm/guardrails.py): `app/llm/guardrails.py`

### Evaluation

- [Tier benchmark](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/benchmark.py): `app/eval/benchmark.py`
- [LLM robustness](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/llm_robustness.py): `app/eval/llm_robustness.py`
- [Retrieval metrics](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/metrics.py): `app/eval/metrics.py`
- [Compute cost estimate](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/eval/cost.py): `app/eval/cost.py`

### Shared foundations

- [Embedding backends](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/embeddings.py): `app/embeddings.py`
- [Chunk and API schemas](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/schema.py): `app/schema.py`
- [Application settings](https://github.com/sonali1554/envint-hybrid-rag/blob/main/app/config.py): `app/config.py`

### Other components

- **Questioner**
- **Local Ollama**

## Connections

- Questioner → HTTP API: submits question (evidence: `app/main.py`)
- HTTP API → Browser UI: serves page (evidence: `app/main.py`)
- HTTP API → Retrieval engine: requests retrieval (evidence: `app/main.py`)
- HTTP API → Answer generation: requests answer (evidence: `app/main.py`)
- HTTP API → Request metrics: registers middleware (evidence: `app/main.py`)
- HTTP API → Chunk and API schemas: validates payloads (evidence: `app/main.py`)
- HTTP API → Application settings: reads settings (evidence: `app/main.py`)
- Retrieval engine → Corpus loader: loads corpus (evidence: `app/retrieval/engine.py`)
- Corpus loader → Policy corpus: reads records (evidence: `app/ingest.py`)
- Corpus loader → Chunk and API schemas: validates chunks (evidence: `app/ingest.py`)
- Retrieval engine → Vector search: indexes and searches (evidence: `app/retrieval/engine.py`)
- Retrieval engine → BM25 search: indexes and searches (evidence: `app/retrieval/engine.py`)
- Retrieval engine → RRF fusion: fuses ranked hits (evidence: `app/retrieval/engine.py`)
- Retrieval engine → Cross-encoder reranker: reranks candidates (evidence: `app/retrieval/engine.py`)
- Vector search → Qdrant index: reads and writes (evidence: `app/retrieval/vector.py`)
- Vector search → Embedding backends: encodes text (evidence: `app/retrieval/vector.py`)
- Vector search → Chunk and API schemas: uses chunk model (evidence: `app/retrieval/vector.py`)
- Retrieval engine → Chunk and API schemas: returns ranked chunks (evidence: `app/retrieval/engine.py`)
- Answer generation → Answer guardrails: checks evidence (evidence: `app/llm/client.py`)
- Answer generation → Local Ollama: generates answer (evidence: `app/llm/client.py`)
- Answer generation → Chunk and API schemas: uses result models (evidence: `app/llm/client.py`)
- Tier benchmark → Retrieval engine: benchmarks tiers (evidence: `README.md`)
- LLM robustness → Retrieval engine: exercises retrieval (evidence: `app/eval/llm_robustness.py`)
- LLM robustness → Answer generation: exercises answering (evidence: `app/eval/llm_robustness.py`)
- LLM robustness → Answer guardrails: exercises safety (evidence: `app/eval/llm_robustness.py`)
- Tier benchmark → Retrieval metrics: scores results
- Tier benchmark → Compute cost estimate: estimates compute cost
- Retrieval engine → Application settings: reads settings (evidence: `app/retrieval/engine.py`)
- Embedding backends → Application settings: selects backend (evidence: `app/embeddings.py`)
