# mohamed-amine-sassi/selfcorrectingrag architecture

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

- Interactive diagram: https://gitdiagram.com/mohamed-amine-sassi/selfcorrectingrag
- Repository: https://github.com/mohamed-amine-sassi/selfcorrectingrag

## Overview

This repository implements PDF-based retrieval-augmented question answering. Its main workflow extracts and chunks a PDF, embeds the chunks in a persistent Chroma collection, then invokes a correction graph that retrieves and grades context, generates an answer, and may rewrite the query or regenerate an answer. The graph’s shared state is a useful internal layer. The tree also includes a RAGAS evaluation area; its evaluator’s implementation was read but not excerpted, so its connections are not shown. Edges below are limited to relationships visible in excerpts or the source index.

Main entry points: [`Correction/Graph.py`](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/Graph.py) (Correction graph), [`RAGBase/main.py`](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/main.py) (RAG entry point), [`RAGBase/Chunking.py`](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Chunking.py) (Text chunking), [`RAGBase/Embedding.py`](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Embedding.py) (Embedding store setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_pdf["PDF input<br/>[AIBook2.pdf]"]
  node_main["RAG entry point<br/>[main.py]"]
  node_extract["PDF extraction<br/>[Extracting.py]"]
  node_chunk["Text chunking<br/>[Chunking.py]"]
  node_embed["Embedding store setup<br/>[Embedding.py]"]
end

subgraph group_retrieval["Retrieval and generation"]
  node_store[("Chroma collection")]
  node_retrieve["Similarity retrieval<br/>[Retrieve.py]"]
  node_generate["Answer generation<br/>[Generate.py]"]
end

subgraph group_correction["Answer correction"]
  node_graph["Correction graph<br/>[Graph.py]"]
  node_state["RAG state<br/>[RAGState.py]"]
  node_retrieve_node["Retrieve node<br/>[RetreiveNode.py]"]
  node_grade_docs["Grade documents<br/>[GradeDocuments.py]"]
  node_decisions["Routing decisions<br/>[DecisionNodes.py]"]
  node_rewrite["Rewrite query<br/>[RewriteQuery.py]"]
  node_generate_node["Generate node<br/>[GenerateNode.py]"]
  node_grade_answer["Grade answer<br/>[GradeAnswer.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_ragas["RAGAS evaluation<br/>[Evaluate.py]"]
end

node_user(("Questioner"))

node_user -->|"asks question"| node_main
node_pdf -->|"input PDF"| node_main
node_main -->|"chunks PDF"| node_chunk
node_chunk -->|"extracts text"| node_extract
node_main -->|"embeds chunks"| node_embed
node_embed -->|"creates or loads"| node_store
node_main -->|"invokes graph"| node_graph
node_graph -->|"registers node"| node_retrieve_node
node_graph -->|"registers node"| node_grade_docs
node_graph -->|"registers node"| node_grade_answer
node_graph -->|"registers node"| node_rewrite
node_graph -->|"registers node"| node_generate_node
node_graph -->|"routes via"| node_decisions
node_retrieve_node -->|"calls retrieval"| node_retrieve
node_retrieve -->|"searches chunks"| node_store
node_generate_node -->|"calls generator"| node_generate
node_graph -->|"uses state schema"| node_state

click node_pdf "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/files/AIBook2.pdf"
click node_main "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/main.py"
click node_extract "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Extracting.py"
click node_chunk "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Chunking.py"
click node_embed "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Embedding.py"
click node_graph "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/Graph.py"
click node_state "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RAGState.py"
click node_retrieve_node "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RetreiveNode.py"
click node_retrieve "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Retrieve.py"
click node_grade_docs "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GradeDocuments.py"
click node_decisions "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/DecisionNodes.py"
click node_rewrite "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RewriteQuery.py"
click node_generate_node "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GenerateNode.py"
click node_generate "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Generate.py"
click node_grade_answer "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GradeAnswer.py"
click node_ragas "https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGAS/Evaluate.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_pdf,node_main,node_extract,node_chunk,node_embed toneBlue
class node_store,node_retrieve,node_generate toneAmber
class node_graph,node_state,node_retrieve_node,node_grade_docs,node_decisions,node_rewrite,node_generate_node,node_grade_answer toneMint
class node_ragas toneRose
class node_user toneIndigo
```

## Components

### Document ingestion

- [PDF input](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/files/AIBook2.pdf): `files/AIBook2.pdf`
- [RAG entry point](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/main.py): `RAGBase/main.py`
- [PDF extraction](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Extracting.py): `RAGBase/Extracting.py`
- [Text chunking](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Chunking.py): `RAGBase/Chunking.py`
- [Embedding store setup](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Embedding.py): `RAGBase/Embedding.py`

### Retrieval and generation

- **Chroma collection**
- [Similarity retrieval](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Retrieve.py): `RAGBase/Retrieve.py`
- [Answer generation](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGBase/Generate.py): `RAGBase/Generate.py`

### Answer correction

- [Correction graph](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/Graph.py): `Correction/Graph.py`
- [RAG state](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RAGState.py): `Correction/RAGState.py`
- [Retrieve node](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RetreiveNode.py): `Correction/RetreiveNode.py`
- [Grade documents](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GradeDocuments.py): `Correction/GradeDocuments.py`
- [Routing decisions](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/DecisionNodes.py): `Correction/DecisionNodes.py`
- [Rewrite query](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/RewriteQuery.py): `Correction/RewriteQuery.py`
- [Generate node](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GenerateNode.py): `Correction/GenerateNode.py`
- [Grade answer](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/Correction/GradeAnswer.py): `Correction/GradeAnswer.py`

### Evaluation

- [RAGAS evaluation](https://github.com/mohamed-amine-sassi/selfcorrectingrag/blob/main/RAGAS/Evaluate.py): `RAGAS/Evaluate.py`

### Other components

- **Questioner**

## Connections

- Questioner → RAG entry point: asks question (evidence: `RAGBase/main.py`)
- PDF input → RAG entry point: input PDF (evidence: `RAGBase/main.py`)
- RAG entry point → Text chunking: chunks PDF (evidence: `RAGBase/main.py`)
- Text chunking → PDF extraction: extracts text (evidence: `RAGBase/Chunking.py`)
- RAG entry point → Embedding store setup: embeds chunks (evidence: `RAGBase/main.py`)
- Embedding store setup → Chroma collection: creates or loads (evidence: `RAGBase/Embedding.py`)
- RAG entry point → Correction graph: invokes graph (evidence: `RAGBase/main.py`)
- Correction graph → Retrieve node: registers node (evidence: `Correction/Graph.py`)
- Correction graph → Grade documents: registers node (evidence: `Correction/Graph.py`)
- Correction graph → Grade answer: registers node (evidence: `Correction/Graph.py`)
- Correction graph → Rewrite query: registers node (evidence: `Correction/Graph.py`)
- Correction graph → Generate node: registers node (evidence: `Correction/Graph.py`)
- Correction graph → Routing decisions: routes via (evidence: `Correction/Graph.py`)
- Retrieve node → Similarity retrieval: calls retrieval (evidence: `Correction/RetreiveNode.py`)
- Similarity retrieval → Chroma collection: searches chunks (evidence: `RAGBase/Retrieve.py`)
- Generate node → Answer generation: calls generator (evidence: `Correction/GenerateNode.py`)
- Correction graph → RAG state: uses state schema (evidence: `Correction/Graph.py`)
