# ivanpetrushev/easy-rag architecture

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

- Interactive diagram: https://gitdiagram.com/ivanpetrushev/easy-rag
- Repository: https://github.com/ivanpetrushev/easy-rag

## Overview

Key Components to Include:

##### Processing Pipeline
- PDF Processing Component
- Text Chunking Component
- Embedding Generation Component
- Vector Store (ChromaDB)
- Query Processing Component
- Answer Generation Component

##### External Services
- AWS Bedrock (containing two sub-components):
- Titan Embed Text Model (for embeddings)
- Claude 3 Haiku Model (for answer generation)

##### Component Relationships

a. Document Processing Flow:
- PDF → Text Extraction → Text Chunking → Embedding Generation → ChromaDB

b. Query Processing Flow:
- User Query → Query Processing → Embedding Generation → ChromaDB Retrieval → Context Assembly → Answer Generation → Response

##### Technical Details in Labels
- Use of LangChain framework
- Specify model names (amazon.titan-embed-text-v2:0, anthropic.claude-3-haiku-20240307-v1:0)
- Token processing capabilities

##### Important Notes
- A processing time indicator (~3 min for embeddings)
- Approximate costs ($0.004 for corpus processing, $0.005 for example queries)
- Potential improvement points (as noted in README)

##### Docker Container Boundary
- Environment variable dependencies

Special Considerations:

##### RAG-specific elements
- Clear separation between retrieval and generation components
- How the vector store bridges document processing and query handling

##### Performance Aspects
- Batch processing for document ingestion
- Real-time flow for query processing

##### Integration Points
- AWS credentials integration
- Docker environment variables
- Local file system interaction

##### Future Extensibility
- Potential integration points for suggested improvements
- Where alternative models could be plugged in

Remember to indicate that this is a demo/prototype architecture, with clear markers for where production-grade improvements could be made (such as streaming responses, memory context, and alternative model options).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Input Layer"
        PDF[("PDF Documents")]
        UserQuery["User Queries"]:::input
    end

    subgraph "Document Processing Pipeline"
        PDFProcess["PDF Processing"]:::process
        TextChunk["Text Chunking"]:::process
        EmbedGen1["Embedding Generation"]:::process
    end

    subgraph "Query Processing Pipeline"
        QueryProcess["Query Processing"]:::process
        EmbedGen2["Embedding Generation"]:::process
        ContextAssembly["Context Assembly"]:::process
        AnsGen["Answer Generation"]:::process
        Response["Response"]:::output
    end

    subgraph "Storage Layer"
        ChromaDB[(ChromaDB Vector Store)]:::storage
        Results["Results Storage"]:::storage
    end

    subgraph "AWS Bedrock Services"
        direction TB
        TitanEmbed["Titan Embed Text Model"]:::aws
        Claude["Claude 3 Haiku Model"]:::aws
    end

    %% Relationships
    PDF --> PDFProcess
    PDFProcess --> TextChunk
    TextChunk --> EmbedGen1
    EmbedGen1 --> ChromaDB

    UserQuery --> QueryProcess
    QueryProcess --> EmbedGen2
    EmbedGen2 --> ChromaDB
    ChromaDB --> ContextAssembly
    ContextAssembly --> AnsGen
    AnsGen --> Response
    Response --> Results

    EmbedGen1 --> TitanEmbed
    EmbedGen2 --> TitanEmbed
    AnsGen --> Claude

    %% Click Events
    click PDFProcess "https://github.com/ivanpetrushev/easy-rag/blob/master/image/pdfloader.py"
    click QueryProcess "https://github.com/ivanpetrushev/easy-rag/blob/master/image/chromadb-query.py"
    click PDF "https://github.com/ivanpetrushev/easy-rag/blob/master/image/t60.pdf"
    click Results "https://github.com/ivanpetrushev/easy-rag/tree/master/results/"

    %% Styling
    classDef process fill:#90EE90,stroke:#333,stroke-width:2px
    classDef storage fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef aws fill:#B19CD9,stroke:#333,stroke-width:2px
    classDef input fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef output fill:#87CEEB,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Process"]:::process
        L2[(Storage)]:::storage
        L3["AWS Service"]:::aws
        L4["Input/Output"]:::input
    end
```
