# ajanm007/jevrag architecture

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

- Interactive diagram: https://gitdiagram.com/ajanm007/jevrag
- Repository: https://github.com/ajanm007/jevrag

## Overview

JevRAG is a decision and calibration layer for RAG systems. Its documented end-to-end path makes chunking decisions during ingestion, filters retrieved context, loops on evidence sufficiency, generates an answer, then checks grounding; cache trust provides a separate short-circuit. The graph also includes the swappable decision backends and calibration, cost, and conformal-risk evaluation capabilities. Pipeline-to-stage links are supported by the pipeline excerpt and README; some evaluation and optional integration details are documented or indexed rather than fully sampled.

Main entry points: [`jevrag/decision.py`](https://github.com/ajanm007/jevrag/blob/master/jevrag/decision.py) (Decision interface), [`jevrag/primitives/sufficiency.py`](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/sufficiency.py) (Evidence sufficiency), [`jevrag/primitives/answer_abstain.py`](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/answer_abstain.py) (Answer abstain), [`jevrag/primitives/cache_trust.py`](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/cache_trust.py) (Cache trust)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rag_flow["RAG workflow"]
  node_document(("Document ingestion"))
  node_index[("Search index")]
  node_query(("User query"))
  node_retrieval["Retrieval"]
  node_generator["Answer generation"]
  node_answer["Grounded answer"]
  node_cache[("Cache lookup")]
  node_no_answer["Suppressed answer"]
end

subgraph group_decisions["Decision primitives"]
  node_chunking["Chunk boundary<br/>[chunk_boundary.py]"]
  node_context["Context selection"]
  node_sufficiency["Evidence sufficiency<br/>[sufficiency.py]"]
  node_abstain["Answer abstain<br/>[answer_abstain.py]"]
  node_cache_trust["Cache trust<br/>[cache_trust.py]"]
end

subgraph group_backends["Decision backends"]
  node_decision["Decision interface<br/>[decision.py]"]
  node_jev_backend["Jev backend<br/>[decision.py]"]
  node_logprob["Logprob backend"]
  node_shadow["Shadow backend<br/>[shadow.py]"]
end

subgraph group_evaluation["Evaluation and calibration"]
  node_calibration["Confidence calibration<br/>[calibration.py]"]
  node_cost["Cost accounting<br/>[cost.py]"]
  node_crc["CRC thresholds<br/>[crc.py]"]
  node_selective["Risk coverage<br/>[selective.py]"]
  node_bridge["Vendor bridge<br/>[_rag_gate.py]"]
  node_vendor_crc["Vendored CRC<br/>[crc.py]"]
  node_evaluator["Answer evaluator<br/>[evaluator.py]"]
end

node_jev_service["Jev service"]

node_document -->|"submits text"| node_chunking
node_chunking -->|"split or merge"| node_index
node_query -->|"requests evidence"| node_retrieval
node_index -->|"supplies passages"| node_retrieval
node_retrieval -->|"filters passages"| node_context
node_context -->|"provides context"| node_sufficiency
node_sufficiency -->|"requests another round"| node_retrieval
node_sufficiency -->|"permits generation"| node_generator
node_generator -->|"checks answer"| node_abstain
node_abstain -->|"returns grounded"| node_answer
node_abstain -->|"suppresses ungrounded"| node_no_answer
node_query -->|"checks cache"| node_cache
node_cache -->|"assesses entry"| node_cache_trust
node_cache_trust -->|"serves if safe"| node_answer
node_cache_trust -->|"falls back if unsafe"| node_retrieval
node_chunking -->|"asks"| node_decision
node_context -->|"asks"| node_decision
node_sufficiency -->|"asks"| node_decision
node_abstain -->|"asks"| node_decision
node_cache_trust -->|"asks"| node_decision
node_jev_backend -->|"calls"| node_jev_service
node_logprob -->|"implements"| node_decision
node_shadow -->|"wraps"| node_decision
node_calibration -->|"uses risk metrics"| node_selective
node_crc -->|"loads CRC core"| node_bridge
node_bridge -->|"exposes"| node_vendor_crc
node_bridge -->|"exposes"| node_selective
node_bridge -->|"exposes"| node_evaluator

click node_chunking "https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/chunk_boundary.py"
click node_context "https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/context_selection.py"
click node_sufficiency "https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/sufficiency.py"
click node_abstain "https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/answer_abstain.py"
click node_cache_trust "https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/cache_trust.py"
click node_decision "https://github.com/ajanm007/jevrag/blob/master/jevrag/decision.py"
click node_jev_backend "https://github.com/ajanm007/jevrag/blob/master/jevrag/decision.py"
click node_logprob "https://github.com/ajanm007/jevrag/blob/master/jevrag/backends/logprob_decision.py"
click node_shadow "https://github.com/ajanm007/jevrag/blob/master/jevrag/backends/shadow.py"
click node_calibration "https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/calibration.py"
click node_cost "https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/cost.py"
click node_crc "https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/crc.py"
click node_selective "https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/selective.py"
click node_bridge "https://github.com/ajanm007/jevrag/blob/master/jevrag/_rag_gate.py"
click node_vendor_crc "https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/crc.py"
click node_evaluator "https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/evaluator.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_document,node_index,node_query,node_retrieval,node_generator,node_answer,node_cache,node_no_answer toneBlue
class node_chunking,node_context,node_sufficiency,node_abstain,node_cache_trust toneAmber
class node_decision,node_jev_backend,node_logprob,node_shadow toneMint
class node_calibration,node_cost,node_crc,node_selective,node_bridge,node_vendor_crc,node_evaluator toneRose
class node_jev_service toneIndigo
```

## Components

### RAG workflow

- **Document ingestion**
- **Search index**
- **User query**
- **Retrieval**
- **Answer generation**
- **Grounded answer**
- **Cache lookup**
- **Suppressed answer**

### Decision primitives

- [Chunk boundary](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/chunk_boundary.py): `jevrag/primitives/chunk_boundary.py`
- [Context selection](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/context_selection.py): `jevrag/primitives/context_selection.py`
- [Evidence sufficiency](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/sufficiency.py): `jevrag/primitives/sufficiency.py`
- [Answer abstain](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/answer_abstain.py): `jevrag/primitives/answer_abstain.py`
- [Cache trust](https://github.com/ajanm007/jevrag/blob/master/jevrag/primitives/cache_trust.py): `jevrag/primitives/cache_trust.py`

### Decision backends

- [Decision interface](https://github.com/ajanm007/jevrag/blob/master/jevrag/decision.py): `jevrag/decision.py`
- [Jev backend](https://github.com/ajanm007/jevrag/blob/master/jevrag/decision.py): `jevrag/decision.py`
- [Logprob backend](https://github.com/ajanm007/jevrag/blob/master/jevrag/backends/logprob_decision.py): `jevrag/backends/logprob_decision.py`
- [Shadow backend](https://github.com/ajanm007/jevrag/blob/master/jevrag/backends/shadow.py): `jevrag/backends/shadow.py`

### Evaluation and calibration

- [Confidence calibration](https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/calibration.py): `jevrag/eval/calibration.py`
- [Cost accounting](https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/cost.py): `jevrag/eval/cost.py`
- [CRC thresholds](https://github.com/ajanm007/jevrag/blob/master/jevrag/eval/crc.py): `jevrag/eval/crc.py`
- [Risk coverage](https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/selective.py): `jevrag/_vendor/selective.py`
- [Vendor bridge](https://github.com/ajanm007/jevrag/blob/master/jevrag/_rag_gate.py): `jevrag/_rag_gate.py`
- [Vendored CRC](https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/crc.py): `jevrag/_vendor/crc.py`
- [Answer evaluator](https://github.com/ajanm007/jevrag/blob/master/jevrag/_vendor/evaluator.py): `jevrag/_vendor/evaluator.py`

### Other components

- **Jev service**

## Connections

- Document ingestion → Chunk boundary: submits text (evidence: `README.md`)
- Chunk boundary → Search index: split or merge (evidence: `README.md`)
- User query → Retrieval: requests evidence (evidence: `README.md`)
- Search index → Retrieval: supplies passages (evidence: `README.md`)
- Retrieval → Context selection: filters passages (evidence: `README.md`)
- Context selection → Evidence sufficiency: provides context (evidence: `README.md`)
- Evidence sufficiency → Retrieval: requests another round (evidence: `README.md`)
- Evidence sufficiency → Answer generation: permits generation (evidence: `README.md`)
- Answer generation → Answer abstain: checks answer (evidence: `README.md`)
- Answer abstain → Grounded answer: returns grounded (evidence: `README.md`)
- Answer abstain → Suppressed answer: suppresses ungrounded (evidence: `README.md`)
- User query → Cache lookup: checks cache (evidence: `README.md`)
- Cache lookup → Cache trust: assesses entry
- Cache trust → Grounded answer: serves if safe
- Cache trust → Retrieval: falls back if unsafe (evidence: `README.md`)
- Chunk boundary → Decision interface: asks (evidence: `jevrag/primitives/chunk_boundary.py`)
- Context selection → Decision interface: asks (evidence: `jevrag/primitives/context_selection.py`)
- Evidence sufficiency → Decision interface: asks (evidence: `jevrag/primitives/sufficiency.py`)
- Answer abstain → Decision interface: asks (evidence: `jevrag/primitives/answer_abstain.py`)
- Cache trust → Decision interface: asks (evidence: `jevrag/primitives/cache_trust.py`)
- Jev backend → Jev service: calls (evidence: `jevrag/decision.py`)
- Logprob backend → Decision interface: implements (evidence: `jevrag/backends/logprob_decision.py`)
- Shadow backend → Decision interface: wraps (evidence: `jevrag/backends/shadow.py`)
- Confidence calibration → Risk coverage: uses risk metrics (evidence: `jevrag/eval/calibration.py`)
- CRC thresholds → Vendor bridge: loads CRC core (evidence: `jevrag/eval/crc.py`)
- Vendor bridge → Vendored CRC: exposes (evidence: `jevrag/_rag_gate.py`)
- Vendor bridge → Risk coverage: exposes (evidence: `jevrag/_rag_gate.py`)
- Vendor bridge → Answer evaluator: exposes (evidence: `jevrag/_rag_gate.py`)
