# caspianmoon/memoripy architecture

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

- Interactive diagram: https://gitdiagram.com/caspianmoon/memoripy
- Repository: https://github.com/caspianmoon/memoripy

## Overview

##### Main Components

a) Core Components:
- Memory Manager (Central Controller)
- Memory Store (Memory Organization)
- Storage Systems (Abstract and Implementations)
- Model Interfaces (AI Models Integration)

b) External Integrations:
- OpenAI API
- Ollama API
- External Storage (JSON files)

**Top Layer: Client Interface**
**Middle Layer: Core Components**
**Bottom Layer: External Services & Storage**

##### Specific Component Relationships

a) Memory Manager Layer:
- It as the central orchestrator
- It bidirectionally with Memory Store
- Connections to Model interfaces
- Concept extraction and embedding generation flows

b) Memory Store Layer:
- Both short-term and long-term memory stores
- Hierarchical clustering system
- Graph-based associations
- Decay and reinforcement mechanisms

c) Storage Layer:
- Abstract storage interface
- Implementations (JSONStorage and InMemoryStorage)
- Persistence flows

##### Specific Elements

a) Components:
**[Memory Manager]**
- Concept Extraction
- Embedding Generation
- Response Generation
- Interaction Management

**[Memory Store]**
- Short-term Memory
- Long-term Memory
- Clustering System
- Graph Associations

**[Storage Interface]**
- JSON Storage
- In-Memory Storage

**[Model Interface]**
- OpenAI Models
- Ollama Models

b) Data Flows:
- Embedding generation flow
- Concept extraction process
- Demonstrate memory retrieval paths
- Storage operations

##### Key Interactions to Highlight

- Memory Manager ↔ AI Models (concept extraction and embeddings)
- Memory Manager ↔ Memory Store (storage and retrieval)
- Memory Store ↔ Storage Implementation (persistence)
- Graph-based associations within Memory Store
- Clustering mechanisms within Memory Store

##### Implementation Details

Use standardized UML or similar notation:
- Diamond endings for composition relationships

##### Optimization Recommendations

- Related components visually
- Use clear, readable labels
- Version information
- Brief descriptions for complex interactions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        MM[Memory Manager]
    end

    subgraph Core_Services
        MS[Memory Store]
        ML[Model Layer]
        ST[Storage Systems]
    end

    subgraph Model_Components
        CI[Chat Interface]
        EI[Embedding Interface]
    end

    subgraph Storage_Types
        IMS[In-Memory Storage]
        JS[JSON Storage]
    end

    subgraph External_Services
        OAI[OpenAI API]
        OLA[Ollama API]
        FA[FAISS Vector Store]
        NET[Network Layer]
    end

    %% Core Relationships
    MM --> MS
    MM --> ML
    MS <--> ST
    ML --> CI
    ML --> EI

    %% Storage Relationships
    ST --> IMS
    ST --> JS

    %% External Service Connections
    CI --> OAI
    CI --> OLA
    EI --> FA
    OAI & OLA & FA --> NET

    %% Click Events
    click MM "https://github.com/caspianmoon/memoripy/blob/master/memoripy/memory_manager.py"
    click MS "https://github.com/caspianmoon/memoripy/blob/master/memoripy/memory_store.py"
    click ST "https://github.com/caspianmoon/memoripy/blob/master/memoripy/storage.py"
    click IMS "https://github.com/caspianmoon/memoripy/blob/master/memoripy/in_memory_storage.py"
    click JS "https://github.com/caspianmoon/memoripy/blob/master/memoripy/json_storage.py"
    click ML "https://github.com/caspianmoon/memoripy/blob/master/memoripy/model.py"
    click CI "https://github.com/caspianmoon/memoripy/blob/master/memoripy/implemented_models.py"
    click EI "https://github.com/caspianmoon/memoripy/blob/master/memoripy/implemented_models.py"
    click OAI "https://github.com/caspianmoon/memoripy/blob/master/examples/openai_example.py"

    %% Styling
    classDef core fill:#2374ab
    classDef storage fill:#2a9d8f
    classDef external fill:#e76f51
    classDef model fill:#8338ec

    class MM,MS core
    class ST,IMS,JS storage
    class OAI,OLA,FA,NET external
    class ML,CI,EI model

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Storage Systems]:::storage
        L3[External Services]:::external
        L4[Model Components]:::model
    end
```
