# kolhesamiksha/hybrid-search-rag architecture

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

- Interactive diagram: https://gitdiagram.com/kolhesamiksha/hybrid-search-rag
- Repository: https://github.com/kolhesamiksha/hybrid-search-rag

## Overview

Key Components to Include in the System Design:

##### Frontend Layer
- Streamlit App (chat_streamlit_app)
- FastAPI Swagger UI
- User interaction flows

##### API Layer
- FastAPI Backend (chat_restapi)
- Main endpoints (/predict)
- Rate limiting component (router/limiter.py)

##### Core RAG Pipeline (hybrid_rag)
a. Query Processing:
- Query Expansion
- Self-Query Retriever
- Metadata Filtering

b. Search Components:
- Hybrid Search (combining sparse and dense embeddings)
- Reranker
- Vector Store (Milvus)

c. LLM Integration:
- GPT-4 Model
- Prompt Management
- Guard Rails

##### Data Storage
- MongoDB (for API secrets and metadata)
- Zilliz Milvus Vector Store (for embeddings)
- Chat History Storage

##### External Services
- AI/ML API Integration
- Embedding Models:
- Qdrant/bm42-all-minilm-l6-v2-attentions (Sparse)
- jinaai/jina-embeddings-v2-base-en (Dense)

- User Interface (Top)
- API Layer (Upper Middle)
- RAG Pipeline (Middle)
- Storage Layer (Bottom)
- External Services (Right Side)

##### Specific Flows
1. User Query Flow:
User → Streamlit → FastAPI → Query Processing → Hybrid Search → LLM → Response

2. Document Processing Flow:
Web Crawling → Semantic Chunking → Embedding Generation → Vector Storage

3. Retrieval Flow:
Query → Hybrid Search (Sparse + Dense) → Reranking → Context Selection → LLM

##### Additional Elements
- Metrics and limits (e.g., context window sizes)
- Security boundaries
- Deployment environments

##### Technical Details to Highlight
- Embedding dimensions
- Chunk sizes
- Rate limits
- API endpoints
- Storage capacities

##### Performance Optimization Points
- Where caching occurs
- Parallel processing
- Reranking checkpoints

Remember to:
- Keep components proportional to their importance
- Use clear, readable labels
- Version numbers for key components
- Both synchronous and asynchronous paths
- Error handling paths
- Monitoring and logging points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api 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:#95a5a6,stroke:#7f8c8d,color:white
    
    %% Frontend Layer
    subgraph Frontend
        UI1[Streamlit App]
        UI2[FastAPI Swagger UI]
    end
    class UI1,UI2 frontend
    click UI1 "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/chat_streamlit_app/app.py"

    %% API Layer
    subgraph APILayer
        API[FastAPI Backend]
        RL[Rate Limiter]
        RR["RAG Router (/predict)"]
    end
    class API,RL,RR api
    click API "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/chat_restapi/main.py"
    click RL "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/chat_restapi/router/limiter.py"
    click RR "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/chat_restapi/router/rag_router.py"

    %% Core RAG Pipeline
    subgraph RAGPipeline
        QP[Query Processing]
        HS[Hybrid Search]
        RNK[Reranker]
        LLM[LLM Integration]
        
        subgraph QueryProcessing
            QE[Query Expander]
            SQR[Self-Query Retriever]
            MF[Metadata Filtering]
        end
        
        subgraph LLMComponents
            GPT[GPT-4 Model]
            PM[Prompt Management]
            GR[Guard Rails]
            QM[Question Moderator]
        end
    end
    class QP,HS,RNK,LLM,QE,SQR,MF,GPT,PM,GR,QM rag
    click QE "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/advance_rag/query_expander.py"
    click SQR "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/advance_rag/self_query_retriever.py"
    click HS "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/advance_rag/hybrid_search.py"
    click RNK "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/advance_rag/reranker.py"
    click GPT "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/models/llm_model/model.py"
    click PM "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/prompts/prompt.py"
    click GR "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/guardrails/rails.py"
    click QM "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/moderation/question_moderator.py"

    %% Storage Layer
    subgraph Storage
        DB[(MongoDB)]
        VS[(Milvus Vector Store)]
        CH[(Chat History)]
    end
    class DB,VS,CH storage
    click DB "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/utils/mongo_init.py"
    click VS "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/vectordb/zillinz_milvus.py"
    click CH "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/chat_streamlit_app/chat_history/chat_history.csv"

    %% External Services
    subgraph ExternalServices
        EM1["Sparse Embeddings
        (bm42-all-minilm)"]
        EM2["Dense Embeddings
        (jina-embeddings)"]
    end
    class EM1,EM2 external
    click EM1 "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/models/retriever_model/models.py"

    %% Core RAG Implementation
    CRAG[Core RAG Implementation]
    class CRAG rag
    click CRAG "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/rag.py"

    %% Evaluation System
    EVAL[Evaluation System]
    class EVAL rag
    click EVAL "https://github.com/kolhesamiksha/Hybrid-Search-RAG/blob/main/hybrid_rag/src/evaluate/rag_evaluation.py"

    %% Connections
    UI1 --> API
    UI2 --> API
    API --> RL
    RL --> RR
    RR --> QP
    QP --> QE
    QE --> SQR
    SQR --> MF
    MF --> HS
    HS --> RNK
    RNK --> LLM
    LLM --> GPT
    GPT --> PM
    PM --> GR
    QM --> GR
    HS --> VS
    GPT --> DB
    UI1 --> CH
    HS --> EM1
    HS --> EM2
    CRAG --> HS
    CRAG --> LLM
    EVAL --> CRAG
```
