# yacinebessadi/bennabi-rag architecture

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

- Interactive diagram: https://gitdiagram.com/yacinebessadi/bennabi-rag
- Repository: https://github.com/yacinebessadi/bennabi-rag

## Overview

##### Project type and purpose
- This is a single-page, full-stack RAG (Retrieval-Augmented Generation) chatbot built in Python with a Streamlit UI.
- It retrieves passages from three PDF books by Malek Bennabi using FAISS and BM25, re-ranks with a cross-encoder, and then generates answers via the Mistral LLM.

##### File structure
- Top-level files:
- app.py – the entrypoint defining the Streamlit UI and orchestrating the RAG pipeline
- Procfile – Heroku deployment specification (web: streamlit run app.py)
- PDFs – source documents loaded at runtime (Les_conditions_de_la_renaissance.pdf, probleme.idees_.pdf, vocation-de-lislam.pdf)
- README.md – project overview
- .gitignore – excludes Python artifacts

##### Extract additional insights from the README
- Core features:
- Hybrid retrieval: FAISS vector store + BM25 inverted index
- Cross-encoder re-ranking of candidate passages
- LangChain for document loading, chains, and prompt templates
- Streamlit web interface
- Deployment target: Cloud (Heroku or similar)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entities
    User["User (Browser)"]:::external

    %% UI Layer
    subgraph "Frontend Layer"
        Streamlit["Streamlit Frontend"]:::ui
    end

    %% Backend Layer
    subgraph "Backend Logic"
        DocumentLoader["Document Loader & Preprocessing"]:::backend
        Retrieval["Retrieval Layer (BM25 + FAISS)"]:::retrieval
        Rerank["Re-ranker (Cross-Encoder)"]:::ml
        LLM["LLM Inference (Mistral-small)"]:::ml
    end

    %% Storage Layer
    subgraph "Storage"
        PDF1["Les_conditions_de_la_renaissance.pdf"]:::storage
        PDF2["probleme.idees_.pdf"]:::storage
        PDF3["vocation-de-lislam.pdf"]:::storage
        VectorStore["FAISS Vector Store Files"]:::storage
        BM25Index["BM25 Index Files"]:::storage
    end

    %% Project Files
    subgraph "Project Files"
        Procfile["Procfile"]:::files
        README["README.md"]:::files
        Gitignore[".gitignore"]:::files
    end

    %% Data Flows
    User -->|"submits query"| Streamlit
    Streamlit -->|"query"| Retrieval
    Retrieval -->|"candidate docs"| Rerank
    Rerank -->|"top-n passages"| Streamlit
    Streamlit -->|"prompt + context"| LLM
    LLM -->|"generated answer"| Streamlit
    Streamlit -->|reply| User

    %% Ingestion Flows (offline)
    DocumentLoader ---|"ingest PDFs"| PDF1
    DocumentLoader ---|"ingest PDFs"| PDF2
    DocumentLoader ---|"ingest PDFs"| PDF3
    DocumentLoader ---|"build vector store"| VectorStore
    DocumentLoader ---|"build BM25 index"| BM25Index

    %% Click Events
    click Streamlit "https://github.com/yacinebessadi/bennabi-rag/blob/main/app.py"
    click Retrieval "https://github.com/yacinebessadi/bennabi-rag/blob/main/app.py"
    click Rerank "https://github.com/yacinebessadi/bennabi-rag/blob/main/app.py"
    click LLM "https://github.com/yacinebessadi/bennabi-rag/blob/main/app.py"
    click DocumentLoader "https://github.com/yacinebessadi/bennabi-rag/blob/main/app.py"
    click PDF1 "https://github.com/yacinebessadi/bennabi-rag/blob/main/Les_conditions_de_la_renaissance.pdf"
    click PDF2 "https://github.com/yacinebessadi/bennabi-rag/blob/main/probleme.idees_.pdf"
    click PDF3 "https://github.com/yacinebessadi/bennabi-rag/blob/main/vocation-de-lislam.pdf"
    click Procfile "https://github.com/yacinebessadi/bennabi-rag/tree/main/Procfile"
    click README "https://github.com/yacinebessadi/bennabi-rag/blob/main/README.md"
    click Gitignore "https://github.com/yacinebessadi/bennabi-rag/blob/main/.gitignore"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#1f77b4,color:#1f1f1f
    classDef retrieval fill:#ffe5cc,stroke:#d47400,color:#1f1f1f
    classDef ml fill:#e5ffcc,stroke:#2ca02c,color:#1f1f1f
    classDef storage fill:#f2f2f2,stroke:#888888,color:#1f1f1f
    classDef backend fill:#fff5cc,stroke:#d4a017,color:#1f1f1f
    classDef external fill:#ffffff,stroke:#000000,color:#1f1f1f
    classDef files fill:#f9f9f9,stroke:#aaaaaa,color:#1f1f1f
```
