# arturshevchenko/rag_example architecture

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

- Interactive diagram: https://gitdiagram.com/arturshevchenko/rag_example
- Repository: https://github.com/arturshevchenko/rag_example

## Overview

##### Main Components

a) Input Layer:
- Document Input Component (for processing files from /docs)
- User Query Input Component

b) Processing Layer:
- Document Processing Pipeline
- Text Chunking Module
- Document Embedding Generator
- Vector Database (FAISS)
- Document Vectors Storage
- Similarity Search Component

c) Question-Answering Layer:
- Context Retrieval Component
- OpenAI Integration (GPT-3.5-turbo)
- Response Generation Module

##### Component Relationships

- Document Flow:
- Documents → Text Chunking → Embedding Generation → Vector Database

- Query Flow:
- User Query → [Branch 1] Context-based Path
→ Vector DB Retrieval → Context + Query → LLM → Response
- User Query → [Branch 2] Context-free Path
→ Direct LLM Query → Response

##### Additional Elements

- A configuration section showing:
- Environment variables (OPENAI_API_KEY)
- Python environment

- Component types

##### Technical Details to Highlight

- LangChain integration points
- FAISS vector database implementation
- Document processing pipeline
- OpenAI API interaction layer

##### Important Notes

- Dual-mode operation (context-based vs. context-free)
- Clear separation between document processing and query processing
- Asynchronous nature of document processing vs. real-time querying
- Error handling and fallback paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        DI[Document Input]
        QI[User Query Input]
    end

    subgraph Processing
        subgraph "Document Processing Pipeline"
            TC[Text Chunking]
            EG[Embedding Generator]
        end

        subgraph "Vector Storage"
            VDB[(FAISS Vector DB)]
        end
    end

    subgraph "Question-Answering"
        CR[Context Retrieval]
        OAI["OpenAI GPT-3.5"]
        RG[Response Generator]
    end

    %% Decision diamond
    D{Context Required?}

    %% Connections
    DI --> TC
    TC --> EG
    EG --> VDB
    QI --> D
    D -->|Yes| CR
    D -->|No| OAI
    CR --> VDB
    VDB --> OAI
    OAI --> RG

    %% Click events
    click DI "https://github.com/arturshevchenko/rag_example/tree/main//docs/"
    click VDB "https://github.com/arturshevchenko/rag_example/blob/main//main.py"
    click OAI "https://github.com/arturshevchenko/rag_example/blob/main//main.py"
    click CR "https://github.com/arturshevchenko/rag_example/blob/main//main.py"

    %% Styling
    classDef input fill:#a8d1ff,stroke:#000
    classDef processing fill:#90EE90,stroke:#000
    classDef storage fill:#FFE5B4,stroke:#000
    classDef external fill:#DDA0DD,stroke:#000
    classDef decision fill:#FFB6C1,stroke:#000

    class DI,QI input
    class TC,EG,CR,RG processing
    class VDB storage
    class OAI external
    class D decision

    %% Legend
    subgraph Legend
        L1[Input/Output]:::input
        L2[Processing]:::processing
        L3[(Storage)]:::storage
        L4[External Service]:::external
        L5{Decision Point}:::decision
    end
```
