# pranad-mangalkar/local-memory-engine architecture

> Architecture diagram of the GitHub repository pranad-mangalkar/local-memory-engine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pranad-mangalkar/local-memory-engine
- Repository: https://github.com/pranad-mangalkar/local-memory-engine

## Overview

Local Memory Engine is an offline memory service for conversational AI. A chat client submits messages through the FastAPI layer; the engine filters small talk, classifies informative messages, embeds them, and stores them, replacing conflicting active memories when needed. Recall embeds a query and ranks active memories by cosine similarity. The API also lists and deletes memories. SQLite persists memory records and replacement history. The README documents these capabilities; the graph focuses on the runtime modules shown, not the benchmark suite.

Main entry points: [`engine.py`](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py) (Memory orchestration), [`storage.py`](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/storage.py) (Memory store), [`main.py`](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py) (Add memory API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_api_add["Add memory API<br/>[main.py]"]
  node_api_recall["Recall API<br/>[main.py]"]
  node_api_list["List memories API<br/>[main.py]"]
  node_api_delete["Delete memory API<br/>[main.py]"]
end

subgraph group_engine["Memory Engine"]
  node_engine["Memory orchestration<br/>[engine.py]"]
  node_noise["Small-talk filter<br/>[engine.py]"]
  node_classification["Fact classification<br/>[engine.py]"]
  node_embedding["Local embeddings<br/>[engine.py]"]
  node_conflict["Conflict detection<br/>[engine.py]"]
  node_recall["Semantic recall<br/>[engine.py]"]
end

subgraph group_persistence["Persistence"]
  node_store["Memory store<br/>[storage.py]"]
  node_database[("SQLite memory database")]
end

node_client(("Chat client"))
node_model["SentenceTransformer model"]

node_client -->|"submits message"| node_api_add
node_client -->|"submits query"| node_api_recall
node_client -->|"requests list"| node_api_list
node_client -->|"requests deletion"| node_api_delete
node_api_add -->|"processes message"| node_engine
node_engine -->|"filters message"| node_noise
node_engine -->|"extracts details"| node_classification
node_engine -->|"encodes text"| node_embedding
node_embedding -->|"encodes locally"| node_model
node_engine -->|"reads active memories"| node_store
node_engine -->|"checks conflicts"| node_conflict
node_conflict -->|"marks replacement"| node_store
node_api_recall -->|"recalls memories"| node_engine
node_engine -->|"ranks matches"| node_recall
node_recall -->|"encodes query"| node_embedding
node_recall -->|"reads active memories"| node_store
node_api_list -->|"reads all memories"| node_store
node_api_delete -->|"deletes memory"| node_store
node_store -->|"reads and writes"| node_database

click node_api_add "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py"
click node_api_recall "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py"
click node_api_list "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py"
click node_api_delete "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py"
click node_engine "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_noise "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_classification "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_embedding "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_conflict "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_recall "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py"
click node_store "https://github.com/pranad-mangalkar/local-memory-engine/blob/main/storage.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_add,node_api_recall,node_api_list,node_api_delete,node_client toneBlue
class node_engine,node_noise,node_classification,node_embedding,node_conflict,node_recall toneAmber
class node_store,node_database toneMint
class node_model toneIndigo
```

## Components

### HTTP API

- [Add memory API](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py): `main.py`
- [Recall API](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py): `main.py`
- [List memories API](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py): `main.py`
- [Delete memory API](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/main.py): `main.py`

### Memory Engine

- [Memory orchestration](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`
- [Small-talk filter](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`
- [Fact classification](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`
- [Local embeddings](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`
- [Conflict detection](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`
- [Semantic recall](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/engine.py): `engine.py`

### Persistence

- [Memory store](https://github.com/pranad-mangalkar/local-memory-engine/blob/main/storage.py): `storage.py`
- **SQLite memory database**

### Other components

- **Chat client**
- **SentenceTransformer model**

## Connections

- Chat client → Add memory API: submits message (evidence: `README.md`)
- Chat client → Recall API: submits query (evidence: `README.md`)
- Chat client → List memories API: requests list (evidence: `README.md`)
- Chat client → Delete memory API: requests deletion (evidence: `README.md`)
- Add memory API → Memory orchestration: processes message (evidence: `main.py`)
- Memory orchestration → Small-talk filter: filters message (evidence: `engine.py`)
- Memory orchestration → Fact classification: extracts details (evidence: `engine.py`)
- Memory orchestration → Local embeddings: encodes text (evidence: `engine.py`)
- Local embeddings → SentenceTransformer model: encodes locally (evidence: `engine.py`)
- Memory orchestration → Memory store: reads active memories (evidence: `engine.py`)
- Memory orchestration → Conflict detection: checks conflicts (evidence: `engine.py`)
- Conflict detection → Memory store: marks replacement (evidence: `engine.py`)
- Recall API → Memory orchestration: recalls memories (evidence: `main.py`)
- Memory orchestration → Semantic recall: ranks matches (evidence: `engine.py`)
- Semantic recall → Local embeddings: encodes query (evidence: `engine.py`)
- Semantic recall → Memory store: reads active memories (evidence: `engine.py`)
- List memories API → Memory store: reads all memories (evidence: `main.py`)
- Delete memory API → Memory store: deletes memory (evidence: `main.py`)
- Memory store → SQLite memory database: reads and writes (evidence: `storage.py`)
