How mohamed-amine-sassi/selfcorrectingrag works
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: Graph.py Correction graph · main.py RAG entry point · Chunking.py Text chunking · Embedding.py Embedding store setup
Components 18
Document ingestion
- PDF input
files/AIBook2.pdf - RAG entry point
RAGBase/main.py - PDF extraction
RAGBase/Extracting.py - Text chunking
RAGBase/Chunking.py - Embedding store setup
RAGBase/Embedding.py
Retrieval and generation
- Chroma collection
- Similarity retrieval
RAGBase/Retrieve.py - Answer generation
RAGBase/Generate.py
Answer correction
- Correction graph
Correction/Graph.py - RAG state
Correction/RAGState.py - Retrieve node
Correction/RetreiveNode.py - Grade documents
Correction/GradeDocuments.py - Routing decisions
Correction/DecisionNodes.py - Rewrite query
Correction/RewriteQuery.py - Generate node
Correction/GenerateNode.py - Grade answer
Correction/GradeAnswer.py
Evaluation
- RAGAS evaluation
RAGAS/Evaluate.py
Other components
- Questioner
Connections 17
- Questioner → RAG entry point: asks question
RAGBase/main.py - PDF input → RAG entry point: input PDF
RAGBase/main.py - RAG entry point → Text chunking: chunks PDF
RAGBase/main.py - Text chunking → PDF extraction: extracts text
RAGBase/Chunking.py - RAG entry point → Embedding store setup: embeds chunks
RAGBase/main.py - Embedding store setup → Chroma collection: creates or loads
RAGBase/Embedding.py - RAG entry point → Correction graph: invokes graph
RAGBase/main.py - Correction graph → Retrieve node: registers node
Correction/Graph.py - Correction graph → Grade documents: registers node
Correction/Graph.py - Correction graph → Grade answer: registers node
Correction/Graph.py - Correction graph → Rewrite query: registers node
Correction/Graph.py - Correction graph → Generate node: registers node
Correction/Graph.py - Correction graph → Routing decisions: routes via
Correction/Graph.py - Retrieve node → Similarity retrieval: calls retrieval
Correction/RetreiveNode.py - Similarity retrieval → Chroma collection: searches chunks
RAGBase/Retrieve.py - Generate node → Answer generation: calls generator
Correction/GenerateNode.py - Correction graph → RAG state: uses state schema
Correction/Graph.py