# forestavanade/vector-search-ai-assistant-mongodbvcore architecture

> Architecture diagram of the GitHub repository forestavanade/vector-search-ai-assistant-mongodbvcore, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/forestavanade/vector-search-ai-assistant-mongodbvcore
- Repository: https://github.com/forestavanade/vector-search-ai-assistant-mongodbvcore

## Overview

##### Main Components

a. Client Layer:
- Blazor Server Web Application (Search project)
- Chat interface components
- Session management
- Token tracking visualization

b. Application Services Layer:
- ChatService
- OpenAiService
- MongoDbService
- Vector processing services

c. Data Layer:
- Azure Cosmos DB for MongoDB vCore
- Products collection (with vectors)
- Customers collection (with vectors)
- Sales Orders collection (with vectors)
- Completions collection (chat history)

d. External Services:
- Azure OpenAI Service
- Text embeddings model (text-embedding-ada-002)
- Chat completions model (gpt-4-32k)

e. Data Processing Layer:
- Azure Functions
- Ingest and Vectorize function
- Remove Data function

##### Component Relationships and Data Flow

a. Primary Flow:
##### Response back to UI

b. Data Processing Flow:

##### Important Subsystems to Highlight

a. Vector Processing Pipeline:
- Text input → Embeddings generation → Vector storage/search

b. Conversation Management:
- Session tracking
- Token management
- History storage

c. RAG Pattern Implementation:
- Vector search
- Context assembly
- Completion generation

##### Additional Details

Key architectural aspects:
- Token management boundaries
- Collection relationships
- Vector index types (IVF/HNSW)
- Deployment boundaries

##### Notes

Annotations for:
- Maximum token limits
- Vector search parameters
- Collection configurations
- Model specifications

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Blazor Web Application"]
        Chat["Chat Interface"]
        Session["Session Management"]
        UI --> Chat
        UI --> Session
    end

    subgraph "Application Services"
        ChatS["Chat Service"]
        OpenAIS["OpenAI Service"]
        MongoS["MongoDB Service"]
        ChatS --> OpenAIS
        ChatS --> MongoS
    end

    subgraph "Data Processing"
        IngestFn["Ingest and Vectorize"]
        AddRemoveFn["Add Remove Data"]
    end

    subgraph "Data Layer"
        CosmosDB[(Azure Cosmos DB)]
        Products[("Products Collection")]
        Customers[("Customers Collection")]
        Sales[("Sales Orders Collection")]
        History[("Completions Collection")]
        CosmosDB --> Products
        CosmosDB --> Customers
        CosmosDB --> Sales
        CosmosDB --> History
    end

    subgraph "External Services"
        AzureOpenAI["Azure OpenAI Service"]
        Embeddings["text-embedding-ada-002"]
        ChatGPT["gpt-4-32k"]
        AzureOpenAI --> Embeddings
        AzureOpenAI --> ChatGPT
    end

    Chat --> ChatS
    ChatS -.-> History
    MongoS --> CosmosDB
    OpenAIS --> AzureOpenAI
    IngestFn --> AzureOpenAI
    IngestFn --> CosmosDB
    AddRemoveFn --> CosmosDB

    classDef frontend fill:#3498db
    classDef service fill:#2ecc71
    classDef function fill:#f1c40f
    classDef database fill:#9b59b6
    classDef external fill:#e74c3c
    
    class UI,Chat,Session frontend
    class ChatS,OpenAIS,MongoS service
    class IngestFn,AddRemoveFn function
    class CosmosDB,Products,Customers,Sales,History database
    class AzureOpenAI,Embeddings,ChatGPT external

    click UI "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/tree/main/Search"
    click Chat "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/Search/Pages/ChatPane.razor"
    click Session "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/SharedLib/Models/Session.cs"
    click ChatS "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/Search/Services/ChatService.cs"
    click OpenAIS "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/SharedLib/Services/OpenAiService.cs"
    click MongoS "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/SharedLib/Services/MongoDbService.cs"
    click IngestFn "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/Vectorize/IngestAndVectorize.cs"
    click AddRemoveFn "https://github.com/ForestAvanade/Vector-Search-AI-Assistant-MongoDBvCore/blob/main/Vectorize/AddRemoveData.cs"
```
