# dkwik/rag-knowledge-chatbot-django architecture

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

- Interactive diagram: https://gitdiagram.com/dkwik/rag-knowledge-chatbot-django
- Repository: https://github.com/dkwik/rag-knowledge-chatbot-django

## Overview

##### Main Components

A. Frontend Layer:
- Simple chat interface (HTML/Bootstrap/JavaScript)
- As a single component that handles user interactions
- Located in /templates directory

B. Backend Layer (Django):
- Main Django application structure
- URL routing and view handlers
- REST API endpoints for chat interactions

C. RAG System (Core):
- LangChain Agent Orchestrator
- LlamaIndex Retrieval System
- OpenAI Integration (LLM & Embeddings)
- Memory Management System (6-message context window)

D. Storage Layer:
- PGVector for vector storage
- Neo4J for graph-based knowledge representation (experimental)

##### Component Relationships

**[User Interface] ←→ [Django Backend] ←→ [RAG System] ←→ [Storage Layer]**

##### Detailed Component Breakdown

RAG System (expand this as a subsystem):
**[Query Input] → [Agent Decision Layer] → [Retrieval Router]**
- ↓
**[Multiple Retrieval Strategies] ← [Document Processors]**

##### Special Architectural Elements

A dedicated section showing the experimental RAG techniques:
- Small-to-Large Retrieval
- Recursive Retrieval
- Subquery Engine
- Graph Search (experimental)

##### Key Technical Details to Note

Callouts for:
- Document loading process (/doc_loader)
- Agentic behavior decision making
- Memory management system
- Vector storage mechanisms
- Integration points with OpenAI

##### Implementation Details

Configuration connections:
- Django settings
- Docker configuration (Neo4j)
- URL routing
- Template rendering

## Diagram (Mermaid)

```mermaid
graph TB
    %% Main Components
    UI["Chat Interface"]:::frontend
    Django["Django Backend"]:::backend
    RAG["RAG System"]:::rag
    Storage["Storage Layer"]:::storage
    OpenAI["OpenAI Services"]:::external

    %% Storage Components
    subgraph Storage Layer
        PGVector["PGVector<br/>Vector Storage"]:::storage
        Neo4J["Neo4J Graph DB"]:::storage
    end

    %% Django Components
    subgraph Django Backend Components
        Config["Django Config"]:::backend
        URLs["URL Routing"]:::backend
        Views["View Handlers"]:::backend
        Models["Data Models"]:::backend
    end

    %% RAG Components
    subgraph RAG System
        Agent["LangChain Agent<br/>Orchestrator"]:::rag
        Memory["Memory Manager<br/>(6-msg window)"]:::rag
        Retrieval["Retrieval System"]:::rag
        
        subgraph Advanced Retrieval Strategies
            SmallLarge["Small-to-Large<br/>Retrieval"]:::experimental
            Recursive["Recursive<br/>Retrieval"]:::experimental
            Subquery["Router Query<br/>Engine"]:::experimental
            GraphSearch["Graph Search<br/>(Experimental)"]:::experimental
        end
        
        DocProcessor["Document<br/>Processor"]:::rag
    end

    %% Relationships
    UI <--> Django
    Django <--> RAG
    RAG <--> Storage
    RAG <--> OpenAI
    
    Agent --> Memory
    Agent --> Retrieval
    Retrieval --> SmallLarge & Recursive & Subquery & GraphSearch
    DocProcessor --> Retrieval
    
    %% Click Events
    click UI "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/templates/chatbot.html"
    click Config "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/django_chatbot/settings.py"
    click URLs "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/django_chatbot/urls.py"
    click Views "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/views.py"
    click Models "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/models.py"
    click DocProcessor "https://github.com/dkwik/rag-knowledge-chatbot-django/tree/main/django_chatbot/chatbot/doc_loader/"
    click SmallLarge "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/doc_loader/doc_loader_small_to_large.ipynb"
    click Recursive "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/doc_loader/doc_loader_recursive.ipynb"
    click GraphSearch "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/doc_loader/doc_loader_recursive_graphsearch.ipynb"
    click Subquery "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/chatbot/doc_loader/doc_loader_router_query_engine.ipynb"
    click Neo4J "https://github.com/dkwik/rag-knowledge-chatbot-django/blob/main/django_chatbot/docker-neo4j/docker-compose.yml"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef rag fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef experimental fill:#f1c40f,stroke:#f39c12,color:black

    %% Legend
    subgraph Legend
        F["Frontend"]:::frontend
        B["Backend"]:::backend
        R["RAG Components"]:::rag
        S["Storage"]:::storage
        E["External Services"]:::external
        X["Experimental"]:::experimental
    end
```
