# sharonmordechai/ai-assistant-with-vector-store architecture

> Architecture diagram of the GitHub repository sharonmordechai/ai-assistant-with-vector-store, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sharonmordechai/ai-assistant-with-vector-store
- Repository: https://github.com/sharonmordechai/ai-assistant-with-vector-store

## Overview

##### Project type and purpose
- This is a full-stack Python web application (a single, monolithic Streamlit app) that provides an AI-powered conversational interface.
- It uses LangChain to orchestrate agents and memory, FAISS for vector-based document search, and OpenAI for model inference.

##### File structure to extract components
- Top-level script:
- main.py – the entry point, defines the Streamlit UI and glues together all services.
- Utility modules:
- utils/langchain_loaders.py – functions to load documents into LangChain, build FAISS vector stores.
- Configuration & dependencies:
- requirements.txt, dev-requirements.txt, .github/workflows/ci.yaml – CI/CD and linting.
- Supporting material (not in the runtime path):
- examples/, documentation/, tests/

##### README for technical stack and workflow
- Frontend: Streamlit (interactive UI in the browser)
- Backend logic: Python, LangChain agents & memory, document loaders
- Vector store: FAISS
- External API: OpenAI (GPT-4 / GPT-3.5-turbo)

##### Main components
a. Streamlit UI
- Renders input widgets (API key, model selector, temperature slider, file uploader)
- Displays chat history and responses
b. Application Core (main.py)
- Orchestrates user requests and responses
- Calls utils/langchain_loaders to ingest/upload documents
- Manages a LangChain agent or chain instance that:
- Checks memory and vector store for context
- Retrieves relevant docs from FAISS
- Formats prompts and calls OpenAI API
- Updates memory and chat history
c. FAISS Vector Store
- Stores document embeddings for efficient similarity search
- Populated by LangChain loaders when files are uploaded
d. OpenAI API (external service)
- Receives prompts from the application
- Returns model outputs (chat completions)
e. (Optionally) CI/CD pipeline and Dev tools
- GitHub Actions workflow for tests and linting
- pre-commit hooks

##### Relationships and interactions (data flow)
- User → Streamlit UI → Application Core
- File upload → LangChain loader → FAISS store
- User query → Application Core → FAISS (retrieve contexts)
- Application Core → OpenAI API → Application Core → Streamlit UI → User
- (CI/CD) Repo commit → GitHub Actions → Tests/Linters

##### Architectural patterns and design principles
- Monolithic, single-process service but logically layered:
- Presentation layer (Streamlit)
- Orchestration layer (main.py + LangChain)
- Data layer (vector store + in-memory memory)
- Separation of concerns: UI vs. business logic vs. data storage
- External integration points abstracted behind function calls

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        UI["Streamlit UI\n(main.py)"]:::ui
        EXAMPLE_UI["Example Streamlit App\n(examples/streamlit_open_ai.py)"]:::ui
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        CORE["Application Core\n(main.py)"]:::logic
        LOADERS["LangChain Loaders & FAISS Init\n(utils/langchain_loaders.py)"]:::logic
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        FAISS["FAISS Vector Store"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        direction TB
        OPENAI["OpenAI GPT-4/3.5-turbo API"]:::external
    end

    %% Development Tools
    subgraph "Dev Tools & CI/CD"
        direction TB
        GHA["GitHub Actions CI/CD\n(.github/workflows/ci.yaml)"]:::dev
        PRECOMMIT["Pre-commit Hooks\n(.pre-commit-config.yaml)"]:::dev
        REQ["Requirements\n(requirements.txt)"]:::dev
        DEVREQ["Dev Requirements\n(dev-requirements.txt)"]:::dev
        TEST["Test Suite\n(tests/test_document_loader.py)"]:::dev
        TESTFILES["Test Files\n(tests/files/)"]:::dev
        DOCS["Documentation\n(documentation/)"]:::dev
        EXAMPLES_README["Examples README\n(examples/README.md)"]:::dev
    end

    %% User Interaction
    User[/"User"/]:::external
    User -->|inputs query| UI
    UI -->|calls| CORE
    UI -->|uploads file| LOADERS
    LOADERS -.->|indexes docs| FAISS
    CORE -->|searches context| FAISS
    CORE -->|calls API| OPENAI
    OPENAI -->|returns response| CORE
    CORE -->|renders reply| UI
    UI -->|displays| User

    %% CI/CD Flow
    RepoCommit[/"Repo Commit"/]:::dev --> GHA
    GHA -->|runs tests| TEST
    GHA -->|runs lint| PRECOMMIT

    %% Click Events
    click UI "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/main.py"
    click CORE "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/main.py"
    click LOADERS "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/utils/langchain_loaders.py"
    click EXAMPLE_UI "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/examples/streamlit_open_ai.py"
    click GHA "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/.github/workflows/ci.yaml"
    click PRECOMMIT "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/.pre-commit-config.yaml"
    click REQ "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/requirements.txt"
    click DEVREQ "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/dev-requirements.txt"
    click TEST "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/tests/test_document_loader.py"
    click TESTFILES "https://github.com/sharonmordechai/ai-assistant-with-vector-store/tree/master/tests/files/"
    click DOCS "https://github.com/sharonmordechai/ai-assistant-with-vector-store/tree/master/documentation/"
    click EXAMPLES_README "https://github.com/sharonmordechai/ai-assistant-with-vector-store/blob/master/examples/README.md"

    %% Styles
    classDef ui fill:#D0E6FA,stroke:#0366D6,stroke-width:1px;
    classDef logic fill:#E6F4EA,stroke:#28A745,stroke-width:1px;
    classDef datastore fill:#FFE8CC,stroke:#D15704,stroke-width:1px,stroke-dasharray: 5 5;
    classDef external fill:#F0E6FF,stroke:#6F42C1,stroke-width:1px,stroke-dasharray: 2 2;
    classDef dev fill:#F5F5F5,stroke:#6A737D,stroke-width:1px;
```
