# heniljshah/slackbot-agentic-rag architecture

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

- Interactive diagram: https://gitdiagram.com/heniljshah/slackbot-agentic-rag
- Repository: https://github.com/heniljshah/slackbot-agentic-rag

## Overview

##### Project Overview and Type
- The project is an AI agent focused on extracting answers from PDF documents using an agentic Retrieval-Augmented Generation (RAG) approach.
- It integrates with Slack (via a Slack integration module) for posting structured JSON responses.
- The solution emphasizes a custom retrieval-powered question answering flow using GPT (specifically a GPT-4o-mini model variant) and does not rely on pre-built chains from libraries like LangChain.

##### Analyzing the File Structure
- Top-Level Directories and Files:
- The “app” directory contains production code (main.py, slack_integration.py) for running the agent and handling Slack communication.
- The “POC” directory holds proof-of-concept materials, including:
▪ “docs” (project handbook, PDFs) that might explain internal workflow details.
▪ “notebooks” (for prototyping and experiments, e.g., main.py, prototype.ipynb) where the retrieval and integration logic was likely developed.
▪ “vdb” directory with a vector/database substructure (binary files, chroma.sqlite3) that underpins the retrieval component. This indicates that data is indexed, stored, and queried to enable answer extraction from large PDF documents.
- Other files such as readme.md and requirements.txt give context on dependencies and overall project goals.

##### Key Components
a. User Interface / Integration Layer:
- Slack Integration: Represents how users send questions via Slack.
- (Optionally) a command-line or web interface that might trigger the agent.

b. Agent Core:
- The main processing module (found in app/main.py) which functions as the controller.
- It handles receiving user questions, enhancing queries, and orchestrating the retrieval process.
- The agent uses custom logic to query the retriever multiple times (agentic RAG) to ensure completeness.

c. Retrieval Engine / Data Store:
- The vector database or indexed store (contents under POC/vdb, including binary and SQLite files) is used to retrieve relevant segments from the large PDF document.
- This could be abstracted as a “Retriever” component that interacts with the vectorized PDF representation.

d. AI Processing Module:
- Integration with OpenAI’s GPT model (GPT-4o-mini).
- The module formats enhanced queries with context from the retriever and receives processed answers.

##### Relationships and Data Flow
- A user question is input (via Slack or other channel) and is directed to the Slack integration component.
- The Slack integration module (in app/slack_integration.py) passes the question to the main processing module.
- The main module invokes the agentic RAG logic:
- It performs multiple iterations of retrieval by querying the Retriever.
- It formats each query with the necessary context for GPT processing.
- After obtaining a comprehensive answer, the module formats the response into structured JSON.
- The final output is sent back via the Slack integration module to the Slack channel.
- Internally, the retrieval component fetches data using the prebuilt vector store structure in the “POC/vdb” directory.

##### Architectural Patterns and Important Elements
- Modularity: The separation between the agent’s orchestration logic, retrieval component, and Slack integration.
- Iterative Querying (Agentic RAG): Multiple querying cycles to improve answer quality.
- Separation of Experimentation and Production: The “POC” directory provides proof-of-concept implementations while the “app” directory holds refined production code.
- Data Storage: Use of a custom vectorized data store (binary files and SQLite) to hold and index PDF content.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface
    subgraph "User Interface Layer"
        U["User Input (Slack)"]:::external
    end

    %% Integration Layer
    subgraph "Integration Layer"
        SI["Slack Integration Module"]:::slack
    end

    %% Core Processing Layer
    subgraph "Core Processing"
        AA["Main AI Agent Orchestrator"]:::agent
    end

    %% Data Layer
    subgraph "Data Layer"
        RE["Retrieval Engine (Vector Data Store)"]:::retrieval
    end

    %% External AI Service
    GPT["GPT Processing Service"]:::external

    %% Data Flow
    U -->|"question"| SI
    SI -->|"pass_question"| AA
    AA -->|"query"| RE
    RE -->|"retrieved_data"| AA
    AA -->|"enhanced_query"| GPT
    GPT -->|"processed_answer"| AA
    AA -->|"json_response"| SI
    SI -->|"send_response"| U

    %% Iterative Querying Annotation
    AA ---|"AgenticRAG"| RE

    %% Click Events
    click SI "https://github.com/heniljshah/slackbot-agentic-rag/blob/main/app/slack_integration.py"
    click AA "https://github.com/heniljshah/slackbot-agentic-rag/blob/main/app/main.py"
    click RE "https://github.com/heniljshah/slackbot-agentic-rag/tree/main/POC/vdb"

    %% Styles
    classDef external fill:#FFEDB8,stroke:#D18B00,stroke-width:2px;
    classDef slack fill:#B3C7F9,stroke:#1F4E79,stroke-width:2px;
    classDef agent fill:#C6F7C3,stroke:#2F7A2F,stroke-width:2px;
    classDef retrieval fill:#F9D1B3,stroke:#A65C2E,stroke-width:2px;
```
