# ankitnayak-eth/epsteinfiles-rag architecture

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

- Interactive diagram: https://gitdiagram.com/ankitnayak-eth/epsteinfiles-rag
- Repository: https://github.com/ankitnayak-eth/epsteinfiles-rag

## Overview

##### Project type and purpose
- This is a full-stack Retrieval-Augmented Generation (RAG) pipeline built around the “Epstein Files 20K” dataset.
- It consists of a batch data‐ingestion pipeline (download → clean → chunk → embed), a real-time query component (FastAPI), and a Streamlit UI for interactive querying.

##### File structure
Top level:
- ingest/ – four standalone Python scripts to process raw documents into vector embeddings
- api/main.py – FastAPI application exposing a REST interface for querying
- app.py – Streamlit UI that consumes the REST API
- requirements.txt, .env.example – configuration & dependency management
Key points:
- The “ingest” folder is purely batch-oriented; each script is one stage in the ETL pipeline.
- The API and UI are separate processes communicating over HTTP.
- There is an external dependency on a vector database (Chroma), an LLM inference service (Groq), and a sentence transformer model.

##### README for additional insights
- Three stages:
Stage 1 (Data Prep): download, clean, chunk, embed → stored in Chroma DB
Stage 2 (Retrieval): FastAPI performs MMR search over embeddings
Stage 3 (Answer Generation): queried chunks + question → Groq-backed LLaMA → answer
- Tech stack: Python 3.11, FastAPI, Streamlit, LangChain, Chroma, Sentence Transformers, Groq API
- Runtime setup: two terminals (one runs uvicorn api.main:app, the other runs Streamlit)

a. Main components:
1. Data Source (Hugging Face dataset)
2. Ingestion Pipeline (four scripts)
3. Vector Store (Chroma DB)
4. Embedding Engine (Sentence Transformer)
5. REST API (FastAPI service)
6. Retrieval & MMR module (inside API)
7. LLM Inference Service (Groq Cloud for LLaMA)
8. Web UI (Streamlit app)
b. Relationships & interactions:
- At query time: Web UI → REST API → Retrieval module queries Chroma DB → top-k chunks returned → LLM Inference Service → final answer → REST API → Web UI
c. Architectural patterns & principles:
- Separation of concerns: batch ETL vs. real-time services
- Modular, script-based pipeline for data prep
- Microservice style between UI and API
- Asynchronous HTTP handling in FastAPI for low-latency queries
- Externalized configuration via environment variables
d. Technologies & frameworks:
- Python 3.11, Uvicorn + FastAPI, Streamlit, LangChain orchestration, Chroma vector store, Sentence Transformers for embeddings, Groq Cloud LLM inference

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Batch Pipeline
    HF["Data Source\n(Hugging Face Dataset)"]:::external
    Download["Download Dataset Script"]:::batch
    Clean["Clean Dataset Script"]:::batch
    Chunk["Chunk Dataset Script"]:::batch
    Embed["Embed Chunks Script"]:::batch
    Chroma["Chroma Vector Store (Chroma DB)"]:::storage
    ENV[".env.example\n(Config)"]:::config
    Req["requirements.txt"]:::config

    HF --> Download
    Download --> Clean
    Clean --> Chunk
    Chunk --> Embed
    Embed --> Chroma
    ENV -.-> Embed
    ENV -.-> API
    Req -.-> Download
    Req -.-> Clean
    Req -.-> Chunk
    Req -.-> Embed
    Req -.-> API
    Req -.-> UI

    %% Runtime Query Flow
    subgraph "Runtime Query Flow"
        UI["Streamlit UI"]:::realtime
        API["FastAPI Service"]:::realtime
        subgraph "API Internals"
            Retrieval["Retrieval & MMR Module"]:::realtime
            Orchestrator["LangChain Orchestrator"]:::realtime
            Inference["LLM Inference Service\n(Groq Cloud)"]:::external
        end
    end

    UI -->|"HTTP/JSON"| API
    API -->|"MMR Query"| Retrieval
    Retrieval -->|"vector query"| Chroma
    Chroma -->|"top-k chunks"| Retrieval
    Retrieval -->|"pass chunks"| Orchestrator
    Orchestrator --> Inference
    Inference -->|"answer"| API
    API -->|"HTTP/JSON"| UI

    %% Click Events
    click Download "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/ingest/download_dataset.py"
    click Clean "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/ingest/clean_dataset.py"
    click Chunk "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/ingest/chunk_dataset.py"
    click Embed "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/ingest/embed_chunks.py"
    click ENV "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/.env.example"
    click Req "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/requirements.txt"
    click API "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/api/main.py"
    click Retrieval "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/api/main.py"
    click Inference "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/api/main.py"
    click UI "https://github.com/ankitnayak-eth/epsteinfiles-rag/blob/main/app.py"

    %% Styles
    classDef batch fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef storage fill:#90EE90,stroke:#333,stroke-width:1px
    classDef realtime fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef config fill:#FFFFE0,stroke:#333,stroke-width:1px
```
