# mohitvverma/rag_with_agents architecture

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

- Interactive diagram: https://gitdiagram.com/mohitvverma/rag_with_agents
- Repository: https://github.com/mohitvverma/rag_with_agents

## Overview

##### Main Components
- Ingestion Module: Represented by components in the "domains/injestion" directory (e.g., doc_loader, models, vector_db_utils). This module is responsible for accepting and processing documents for storage.
- Storage/Vector Database: Although the code doesn’t physically implement the database, conceptually include a component to represent where processed documents will be stored (a vector database such as Pinecone).
- Retrieval Module: Located in "domains/retreival" (e.g., chat_handler, initialize_memory, rag_util, prompts) and the nested "pinecone_doc_retreival" folder. This component is in charge of querying the vector database and fetching relevant documents.
- Agents Module: Found in "domains/agents" (e.g., models, prompt, routes, tools). This part implements a multi-agent architecture to process incoming queries and generate responses using the retrieved data.
- API Layer: The REST endpoints and WebSocket interaction documented in the README are handled by files like "domains/agents/routes.py", "domains/injestion/routes.py", "domains/retreival/routes.py", and the main entry points "service.py" and "domains/app.py".

##### Relationships and Data Flow
- The flow starts with the Ingestion API (POST /ingest): Documents are uploaded and processed.
- Processed documents are then stored in the vector database.
- When a query is received (via the Run Agents API endpoint or WebSocket), the Retrieval module queries the vector database, selects relevant documents, and passes them along.
- The Agents module takes over by analyzing the query in conjunction with the retrieved documents and generates a response using LLMs.
- Finally, the result is sent back to the client via API responses or real-time WebSocket streams.

##### Architectural Patterns and Design Principles
- Modular / Layered Architecture: Notice how each functional component (ingestion, storage, retrieval, generation) is encapsulated in its own module.
- Separation of Concerns: Each module is responsible for a specific part of the workflow, making the system easier to manage and extend.
- Integration via APIs: REST and WebSocket interfaces are used to expose the system’s functionalities, underscoring a clear client-service separation.

##### Technologies and Frameworks
- Python 3.8+ environment and dependencies (listed in requirements.txt).
- Use of AI/ML libraries for LLM interactions (implied by the generation task, even if not explicitly noted in the file tree).
- Vector database integration (suggested by modules interacting with Pinecone).

- Each Component: Create nodes for “Ingestion Module”, “Vector Database”, “Retrieval Module”, “Agents Module”, and “API Layer”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::client
    APILayer["API Layer"]:::api
    Ingestion["Ingestion Module"]:::ingestion
    VectorDB["Vector Database"]:::vectordb
    Retrieval["Retrieval Module"]:::retrieval
    Agents["Agents Module"]:::agents

    Client -->|"Request"| APILayer

    %% Ingestion Flow
    APILayer -->|"POST_/ingest"| Ingestion
    Ingestion -->|"Store_document"| VectorDB

    %% Query Flow
    APILayer -->|"Query_Request"| Retrieval
    Retrieval -->|"Query_VectorDB"| VectorDB
    VectorDB -->|"Return_Documents"| Retrieval
    Retrieval -->|"Process_Query"| Agents
    Agents -->|"Generate_Response"| APILayer
    APILayer -->|"Response_to_Client"| Client

    %% Click Events
    click Ingestion "https://github.com/mohitvverma/rag_with_agents/tree/main/domains/injestion"
    click VectorDB "https://github.com/mohitvverma/rag_with_agents/blob/main/domains/injestion/vector_db_utils.py"
    click Retrieval "https://github.com/mohitvverma/rag_with_agents/tree/main/domains/retreival"
    click Agents "https://github.com/mohitvverma/rag_with_agents/tree/main/domains/agents"
    click APILayer "https://github.com/mohitvverma/rag_with_agents/blob/main/service.py"

    %% Styles
    classDef client fill:#cce5ff,stroke:#2E86C1,stroke-width:2px;
    classDef api fill:#d5f5e3,stroke:#28B463,stroke-width:2px;
    classDef ingestion fill:#fdebd0,stroke:#E67E22,stroke-width:2px;
    classDef vectordb fill:#d6eaf8,stroke:#3498DB,stroke-width:2px;
    classDef retrieval fill:#f9e79f,stroke:#F1C40F,stroke-width:2px;
    classDef agents fill:#fadbd8,stroke:#E74C3C,stroke-width:2px;
```
