# thomasjanssen-tech/chatbot-with-rag-and-langchain architecture

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

- Interactive diagram: https://gitdiagram.com/thomasjanssen-tech/chatbot-with-rag-and-langchain
- Repository: https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain

## Overview

##### Project type and purpose
- This is a small Python-based full-stack “chatbot” tool that implements Retrieval-Augmented Generation (RAG) using LangChain.
- ingest_database.py builds the vector‐store (by reading PDFs from data/), and chatbot.py serves as the user-facing interactive chatbot that retrieves context and calls the OpenAI API.

##### File structure
- Top-level scripts:
– ingest_database.py: loads documents, splits them into chunks, creates embeddings, and writes them into a vector database.
– chatbot.py: reads user input, queries the vector database for relevant chunks, and orchestrates calls to the LLM via LangChain.
- data/: stores source documents (e.g., the “Attention Is All You Need” paper).
- .env (from .env.example): holds the OpenAI API key.
- requirements.txt: lists dependencies (langchain, openai, vector-store adapter such as Chroma or Pinecone, etc.).

##### README for additional insights
- Implies usage of OpenAI API, LangChain as the orchestrator, and a local or hosted vector store.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Ingestion Phase
    subgraph "Ingestion Phase"
        direction TB
        ING_SCRIPT["ingest_database.py"]:::script
        PDF_LOADER["PDF Loader"]:::pipeline
        TEXT_SPLITTER["Text Splitter"]:::pipeline
        EMB_GEN["Embedding Generator"]:::pipeline
        VECTOR_STORE["Vector Store"]:::db
        ING_SCRIPT -->|reads PDFs| PDF_LOADER
        PDF_LOADER -->|splits text| TEXT_SPLITTER
        TEXT_SPLITTER -->|generates embeddings| EMB_GEN
        EMB_GEN -->|stores vectors| VECTOR_STORE
    end

    %% Chatbot Phase
    subgraph "Chatbot Phase"
        direction TB
        CHAT_SCRIPT["chatbot.py"]:::script
        USER["User"]:::external
        QUERY_PROC["Query Processor"]:::pipeline
        RETRIEVER["Retriever Chain"]:::pipeline
        LLM_CHAIN["LangChain LLM Chain"]:::pipeline
        OPENAI_GEN["OpenAI Completion API"]:::external
        USER -->|inputs query| CHAT_SCRIPT
        CHAT_SCRIPT -->|parses input| QUERY_PROC
        QUERY_PROC -->|vector search| RETRIEVER
        RETRIEVER -->|fetches context| VECTOR_STORE
        RETRIEVER -->|passes context| LLM_CHAIN
        LLM_CHAIN -->|calls| OPENAI_GEN
        OPENAI_GEN -->|returns response| CHAT_SCRIPT
        CHAT_SCRIPT -->|outputs reply| USER
    end

    %% Configuration
    subgraph "Configuration & Secrets"
        direction TB
        DOTENV[".env loader"]:::config
        CHAT_SCRIPT -->|loads API key| DOTENV
        ING_SCRIPT -->|loads API key| DOTENV
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OPENAI_EMB["OpenAI Embedding API"]:::external
        VECTOR_DB_HOST["Vector DB Host (optional)"]:::external
        EMB_GEN -->|calls| OPENAI_EMB
        VECTOR_STORE -->|hosted endpoint| VECTOR_DB_HOST
    end

    %% Documentation
    subgraph "Documentation & Dependencies"
        direction TB
        REQ["requirements.txt"]:::docs
        README["readme.md"]:::docs
    end

    %% Click Events
    click ING_SCRIPT "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/blob/main/ingest_database.py"
    click PDF_LOADER "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/tree/main/data/"
    click CHAT_SCRIPT "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/blob/main/chatbot.py"
    click DOTENV "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/blob/main/.env.example"
    click REQ "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/blob/main/requirements.txt"
    click README "https://github.com/thomasjanssen-tech/chatbot-with-rag-and-langchain/blob/main/readme.md"

    %% Styles
    classDef pipeline fill:#AED6F1,stroke:#1F618D,color:#1B2631
    classDef script fill:#F2F3F4,stroke:#A6ACAF,color:#1B2631
    classDef db fill:#F9E79F,stroke:#B7950B,color:#1B2631
    classDef external fill:#F5CBA7,stroke:#B9770E,color:#1B2631
    classDef config fill:#FADBD8,stroke:#C39BD3,color:#1B2631
    classDef docs fill:#D7BDE2,stroke:#7D3C98,color:#1B2631
```
