# kingjulio8238/memary architecture

> Architecture diagram of the GitHub repository kingjulio8238/memary, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kingjulio8238/memary
- Repository: https://github.com/kingjulio8238/memary

## Overview

##### Main Components Structure

- Chat Agent (Central component)
- Memory Module
- Memory Stream
- Entity Knowledge Store
- Knowledge Graph
- Routing Agent

b) External Services/Integrations:
- LLM Services (Ollama, GPT)
- Vision Models (LLaVA, GPT-4-Vision)
- Database Systems (FalkorDB/Neo4j)
- External APIs (Google Maps, Alpha Vantage, Perplexity)

##### Component Relationships

a) Primary Data Flow:
**User Query → Chat Agent → Routing Agent → Knowledge Graph ↔ Memory Module**

b) Memory Processing Flow:
**Memory Stream → Entity Knowledge Store → Context Window Generation**

c) Knowledge Graph Operations:
**Query → Recursive Retrieval → Entity Extraction → Graph Storage**

##### Specific Implementation Details

Key architectural elements:

a) Memory Module Section:
- Timeline Analysis component
- Entity Ranking System
- Knowledge Categorization
- Memory Compression

b) Knowledge Graph Section:
- Recursive Retrieval System
- Multi-hop Reasoning
- Entity Relationship Mapping

c) Context Window:
- Agent Response Handler
- Entity Relevance Processor
- Chat History Summarizer

##### Additional Details

Elements in separate panels or callouts:

- Memory Compression Workflow
- Entity Knowledge Store Structure
- Recursive Retrieval Process
- Multi-Graph Support

##### Technical Specifications

- Supported Model Types
- Database Options
- API Dependencies
- File Storage Formats

##### Implementation Notes

Create callouts highlighting:
- Auto-generated Memory Features
- Memory Module Integration Points
- System Improvement Metrics
- Memory Rewind Capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Core Components]:::core
        L2[External Services]:::external
        L3[Processing Units]:::processing
        L4[Data Paths]:::datapath
        style Legend fill:#f5f5f5,stroke:#333
    end

    subgraph "Core System"
        CA["Chat Agent"]:::core
        click CA "https://github.com/kingjulio8238/Memary/blob/main/src/memary/agent/chat_agent.py"
        
        subgraph "Memory Module"
            MM["Memory Module"]:::core
            click MM "https://github.com/kingjulio8238/Memary/tree/main/src/memary/memory/"
            MS["Memory Stream"]:::core
            click MS "https://github.com/kingjulio8238/Memary/blob/main/src/memary/memory/memory_stream.py"
            EKS["Entity Knowledge Store"]:::core
            click EKS "https://github.com/kingjulio8238/Memary/blob/main/src/memary/memory/entity_knowledge_store.py"
            MT["Memory Types"]:::core
            click MT "https://github.com/kingjulio8238/Memary/blob/main/src/memary/memory/types.py"
            BM["Base Memory"]:::core
            click BM "https://github.com/kingjulio8238/Memary/blob/main/src/memary/memory/base_memory.py"
        end

        subgraph "Knowledge Processing"
            KG["Knowledge Graph Storage"]:::processing
            click KG "https://github.com/kingjulio8238/Memary/tree/main/dev/KG_memory_stream/storage_graph/"
            RR["Recursive Retrieval"]:::processing
            click RR "https://github.com/kingjulio8238/Memary/blob/main/dev/recursive_retrieval/langchain_retrieval/retrieve.py"
            EE["Entity Extraction"]:::processing
            click EE "https://github.com/kingjulio8238/Memary/blob/main/dev/recursive_retrieval/entity_extraction/entity_extraction.py"
            SE["Synonym Expansion"]:::processing
            click SE "https://github.com/kingjulio8238/Memary/blob/main/src/memary/synonym_expand/synonym.py"
        end

        RA["Routing Agent"]:::core
        click RA "https://github.com/kingjulio8238/Memary/blob/main/dev/legacy_routing_agent/main.py"
        BA["Base Agent"]:::core
        click BA "https://github.com/kingjulio8238/Memary/blob/main/src/memary/agent/base_agent.py"
        DT["Data Types"]:::core
        click DT "https://github.com/kingjulio8238/Memary/blob/main/src/memary/agent/data_types.py"
    end

    subgraph "External Services"
        LLM["LLM Services<br/>(Ollama, GPT)"]:::external
        VM["Vision Models<br/>(LLaVA, GPT-4-Vision)"]:::external
        DB["Graph Databases<br/>(FalkorDB/Neo4j)"]:::external
        API["External APIs<br/>(Maps, Alpha Vantage, Perplexity)"]:::external
        TL["LLM Tools"]:::external
        click TL "https://github.com/kingjulio8238/Memary/blob/main/src/memary/agent/llm_api/tools.py"
    end

    %% Core Relationships
    CA --> RA
    RA --> KG
    KG <--> MM
    MS --> EKS
    EKS --> CA

    %% Knowledge Processing Flow
    KG --> RR
    RR --> EE
    EE --> SE
    SE --> KG

    %% External Service Connections
    CA <--> LLM
    CA <--> VM
    KG <--> DB
    RA <--> API
    LLM <--> TL

    %% Memory Module Internal
    MM --> MS
    MM --> EKS
    MM --> MT
    MM --> BM

    %% Base Implementations
    BA --> CA
    DT --> CA

    classDef core fill:#2374ab,stroke:#333,stroke-width:2px
    classDef external fill:#57a773,stroke:#333,stroke-width:2px
    classDef processing fill:#ffc857,stroke:#333,stroke-width:2px
    classDef datapath fill:#ef476f,stroke:#333,stroke-width:2px
```
