# mfmezger/conversational-agent-langchain architecture

> Architecture diagram of the GitHub repository mfmezger/conversational-agent-langchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mfmezger/conversational-agent-langchain
- Repository: https://github.com/mfmezger/conversational-agent-langchain

## Overview

##### Main Components

a) Client Layer:
- Frontend (Streamlit-based UI)
- External API clients (Bruno API testing)

b) API Layer:
- FastAPI Backend with the following endpoints:
- Embeddings
- RAG (Retrieval Augmented Generation)
- Search
- Collection management
- Delete operations

c) Core Services:
- LLM Providers:
- OpenAI/Azure OpenAI
- Cohere
- Ollama

d) Data Layer:
- Qdrant Vector Database
- Document Storage

##### Architecture Patterns to Highlight

- Strategy Pattern for LLM implementations (evident from LLMStrategy.py)
- REST API architecture
- Microservices-like separation of concerns
- RAG (Retrieval Augmented Generation) pattern

**[Client Layer]**

**[API Gateway/FastAPI]**

**[Service Layer]**

**[Data Layer]**

##### Key Flows

a) Document Processing Flow:
- Document ingestion
- Embedding generation
- Vector storage

b) Search Flow:
- Query embedding
- Semantic search
- Result retrieval

c) RAG Flow:
- Document retrieval
- LLM processing
- Response generation

##### Important Details

- Configuration management (config/ directory)
- Environment variables and secrets management
- Docker containerization
- Testing infrastructure

##### Specific Implementation Notes

- The modular LLM provider system
- The vector database integration
- The separation between embedding and RAG services
- The async nature of the FastAPI implementation

##### Technical Stack Indicators

- Python
- FastAPI
- Streamlit
- Qdrant
- Docker
- Various LLM providers

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI["Frontend (Streamlit)"]
        API_Client["API Client (Bruno)"]
    end

    subgraph API_Gateway
        FastAPI["FastAPI Backend"]
        subgraph Routes
            Embed["Embeddings API"]
            RAG_API["RAG API"]
            Search["Search API"]
            Collection["Collection API"]
            Delete["Delete API"]
        end
    end

    subgraph Services
        subgraph LLM_Services
            LLM_Base["LLM Base Class"]
            LLM_Strategy["LLM Strategy"]
            OpenAI["OpenAI Service"]
            Cohere["Cohere Service"]
            Ollama["Ollama Service"]
            LangGraph["Langgraph Integration"]
        end
    end

    subgraph Data
        VDB["Vector Database (Qdrant)"]
        subgraph Models
            Internal["Internal Models"]
            Request["Request Models"]
            Response["Response Models"]
        end
        subgraph Config
            MainConfig["Main Config"]
            QdrantConfig["Qdrant Config"]
        end
        subgraph Prompts
            OpenAIPrompt["OpenAI Prompts"]
            CoherePrompt["Cohere Prompts"]
        end
    end

    %% Connections
    UI --> FastAPI
    API_Client --> FastAPI
    FastAPI --> Routes
    Routes --> LLM_Services
    LLM_Strategy --> LLM_Base
    LLM_Base --> OpenAI
    LLM_Base --> Cohere
    LLM_Base --> Ollama
    LLM_Services --> VDB
    LLM_Services --> Models
    LLM_Services --> Prompts
    LLM_Services --> Config

    %% Click Events
    click UI "https://github.com/mfmezger/conversational-agent-langchain/blob/main/frontend/assistant.py"
    click API_Client "https://github.com/mfmezger/conversational-agent-langchain/tree/main/ConvAgentBruno/"
    click Embed "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/routes/embeddings.py"
    click RAG_API "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/routes/rag.py"
    click Search "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/routes/search.py"
    click Collection "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/routes/collection.py"
    click Delete "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/routes/delete.py"
    click OpenAI "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/services/open_ai_service.py"
    click Cohere "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/services/cohere_service.py"
    click Ollama "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/services/ollama_service.py"
    click LLM_Strategy "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/LLMStrategy.py"
    click LLM_Base "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/LLMBase.py"
    click LangGraph "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/backend/graph.py"
    click VDB "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/utils/vdb.py"
    click Internal "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/data_model/internal_model.py"
    click Request "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/data_model/request_data_model.py"
    click Response "https://github.com/mfmezger/conversational-agent-langchain/blob/main/src/agent/data_model/response_data_model.py"
    click MainConfig "https://github.com/mfmezger/conversational-agent-langchain/blob/main/config/main.yml"
    click QdrantConfig "https://github.com/mfmezger/conversational-agent-langchain/blob/main/config/qdrant.yaml"
    click OpenAIPrompt "https://github.com/mfmezger/conversational-agent-langchain/blob/main/prompts/chat/openai-qa.j2"
    click CoherePrompt "https://github.com/mfmezger/conversational-agent-langchain/blob/main/prompts/chat/cohere_chat.j2"

    %% Styling
    classDef client fill:#a8d1ff,stroke:#333,stroke-width:2px
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef service fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef data fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px

    class UI,API_Client client
    class FastAPI,Embed,RAG_API,Search,Collection,Delete api
    class LLM_Base,LLM_Strategy,OpenAI,Cohere,Ollama,LangGraph service
    class VDB,Internal,Request,Response data
    class MainConfig,QdrantConfig,OpenAIPrompt,CoherePrompt config
```
