# udit-rawat/quest architecture

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

- Interactive diagram: https://gitdiagram.com/udit-rawat/quest
- Repository: https://github.com/udit-rawat/quest

## Overview

##### Main Components

a) Core Components:
- RAG Engine Service
- Document Retriever
- Data Embedder
- Memory Buffer
- Generation Model Interface (Ollama Integration)
- Web Interface (Flask)

b) External Dependencies:
- Ollama Models (qwen2.5-coder:1.5b and deepseek-r1:1.5b)
- FAISS/HNSW Index
- Metadata Store

##### Component Relationships

- User Query Flow: Web Interface → RAG Engine → Retriever/Generator
- Data Processing Flow: Embedder → HNSW Index → Retriever
- Generation Flow: RAG Engine → Ollama Models → Response Processing
- Memory Management: Query/Response → Memory Buffer → Context Enhancement

##### Specific Implementation Details

Key elements:
- HNSW Index for similarity search
- Metadata store for problem information
- Memory buffer for context retention
- Dynamic prompt switching mechanism
- Confidence threshold handling (0.6 threshold)

**┌─────────────────┐**
- Web Interface │
- ┬────────┘
- ↓
**┌─────────────────┐    ┌─────────────────┐**
- RAG Engine    │←→  │  Memory Buffer  │
- ┬────────┘    └─────────────────┘
- ↓
**┌────────┴────────┐    ┌─────────────────┐**
- Retriever    │←→  │   HNSW Index    │
- ┬────────┘    └─────────────────┘
- ↓
**┌─────────────────┐**
- Ollama Models   │
- ┘

##### Key Interactions to Highlight

a) Query Processing Path:
- User input → RAG Engine
- RAG Engine → Retriever → HNSW Index
- RAG Engine → Ollama Models
- Response → Memory Buffer
- Final Output → User Interface

b) Data Flow Path:
- Document Processing → Embedder
- Embeddings → HNSW Index
- Metadata → Storage
- Solutions → JSON Storage

##### Performance Optimizations

- Query retrieval optimization (15s)
- Reasoning model optimization (4min)
- HNSW parameter tuning
- Dynamic prompt switching

##### Implementation Notes

- Version1Components for legacy implementations
- src/DSAAssistant for current implementation
- Research components for experimental features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Presentation
        WI[Web Interface]
        WI --> |User Query| RE
    end

    subgraph "Application Layer"
        RE[RAG Engine Service]
        DR[Document Retriever]
        DE[Data Embedder]
        MB[Memory Buffer]
        DG[Document Generator]
        PM[Prompt Management]
        
        RE --> DR
        RE --> MB
        RE --> DG
        RE --> PM
        DR --> DE
        DG --> MB
    end

    subgraph "Data Layer"
        HI[(HNSW Index)]
        MS[(Metadata Store)]
        DR --> HI
        DR --> MS
        DE --> HI
    end

    subgraph "External Services"
        OM1[Qwen2.5 Model]
        OM2[DeepSeek Model]
        DG --> OM1
        DG --> OM2
    end

    %% Styling
    classDef presentation fill:#9370DB,stroke:#333,stroke-width:2px
    classDef application fill:#4682B4,stroke:#333,stroke-width:2px
    classDef data fill:#228B22,stroke:#333,stroke-width:2px
    classDef external fill:#FFA500,stroke:#333,stroke-width:2px

    class WI presentation
    class RE,DR,DE,MB,DG,PM application
    class HI,MS data
    class OM1,OM2 external

    %% Click events
    click WI "https://github.com/udit-rawat/Quest/blob/main/app.py"
    click RE "https://github.com/udit-rawat/Quest/blob/main/rag_engine3.py"
    click DR "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/retriever2.py"
    click DE "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/embedder2.py"
    click MB "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/memory_buffer.py"
    click DG "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/doc_generator.py"
    click PM "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/prompt_temp.py"
    click HI "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/leetcode_hnsw2.index"
    click MS "https://github.com/udit-rawat/Quest/blob/main/src/DSAAssistant/components/leetcode_metadata2.pkl"

    %% Legend
    subgraph Legend
        L1[Presentation Layer]:::presentation
        L2[Application Layer]:::application
        L3[Data Layer]:::data
        L4[External Services]:::external
    end
```
