# 28naem-del/mnemosyne architecture

> Architecture diagram of the GitHub repository 28naem-del/mnemosyne, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/28naem-del/mnemosyne
- Repository: https://github.com/28naem-del/mnemosyne

## Overview

1. **What this repository is**
   Mnemosyne is a TypeScript/Node.js memory subsystem for AI agents, packaged as a library rather than an app. Its architecture is split into layered memory services: ingestion, retrieval, graph enrichment, caching/broadcast, and self-improvement. The public entrypoint is `src/index.ts`, with higher-level agent-facing tools under `src/tools`.

2. **Primary runtime boundary**
   The only hard dependency is **Qdrant** for vector storage and similarity search. **Redis** is optional but powers the L1/L2 cache and pub/sub broadcast. **FalkorDB** is optional and provides the temporal knowledge graph. This means the repo can run in a minimal vector-only mode or a fuller multi-agent mode depending on config.

3. **Storage and search core**
   `src/core` holds the low-level primitives: embeddings, BM25 support, deduplication, Qdrant access, and security filtering. This layer is the foundation for both write and read paths; it isolates vector DB interaction from the cognitive logic above it.

4. **Ingestion pipeline**
   `src/pipeline` is the write path. Inputs pass through security filtering, embedding, dedup/merge, extraction/classification, then into storage and downstream enrichment. The README describes this as a zero-LLM, multi-step ingestion pipeline that produces structured memory records quickly and deterministically.

5. **Memory classification and normalization**
   Pipeline modules like `classifier.ts`, `extraction.ts`, and `extractor.ts` turn raw text into typed memory objects. The repo’s memory model includes urgency, domain, type, confidence, and temporal fields, which later drive ranking and graph behavior. This is where unstructured text becomes durable memory metadata.

6. **Knowledge graph layer**
   `src/graph` is the optional relational layer. It handles auto-linking, activation/pathing, and temporal sequences over entities and memories. In architecture terms, the graph is not the primary store; it is an enrichment and navigation layer attached to memories already stored in Qdrant.

7. **Recall and ranking path**
   Retrieval is handled primarily in `src/cognitive`, with cache support from `src/cache`. The read path is: cache lookup, embedding, vector search, intent-aware scoring, diversity reranking, then optional graph enrichment and reasoning. This layer is where multi-signal ranking, recency/importance weighting, confidence, and query intent are combined.

8. **Cache and broadcast**
   `src/cache/layer-cache.ts` implements the two-tier cache strategy, while `src/broadcast` handles cross-agent propagation. Redis is the boundary here: it provides both short-lived recall acceleration and real-time fan-out for memory events, enabling multiple agent instances to stay in sync.

9. **Cognitive/self-improvement layer**
   `src/cognitive` contains the higher-order memory behaviors: decay, consolidation, confidence, intent, sentiment, preferences, proactive recall, lesson extraction, pattern mining, and Theory of Mind. Conceptually, this layer sits above storage and retrieval and continually re-weights or reshapes memory based on usage and feedback.

10. **Agent-facing tools**
   `src/tools` is the main integration surface for external agent frameworks. It exposes operations such as store, recall, forget, feedback, consolidate, preferences, lessons, patterns, and mesh blocks. These tools are thin orchestration wrappers over the pipeline, cognitive, graph, cache, and broadcast subsystems.

11. **Multi-agent mesh features**
   The `broadcast` and `tools` packages together enable shared-state behavior across agents: shared memory blocks, cross-agent synthesis, and awareness queries about what another agent knows. This is the repository’s main distributed-systems boundary, and it depends on Redis-backed messaging plus shared persistence services.

12. **Project structure and validation**
   `examples/` shows integration usage, while `tests/` focuses on core behaviors like BM25, configuration, recall, and storage. CI is GitHub Actions-based, with Docker assets for local deployment. The architecture is therefore library-first, service-backed, and validated around retrieval/storage correctness rather than UI or HTTP concerns.

Main entry points: [`src/pipeline/index.ts`](https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/index.ts) (Pipeline), [`src/core/index.ts`](https://github.com/28naem-del/mnemosyne/blob/main/src/core/index.ts) (Core), [`src/tools/index.ts`](https://github.com/28naem-del/mnemosyne/blob/main/src/tools/index.ts) (Tools), [`src/index.ts`](https://github.com/28naem-del/mnemosyne/blob/main/src/index.ts) (Public API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_src["src"]
  node_n_index["Public API<br/>entrypoint<br/>[index.ts]"]
  node_n_config["Config<br/>settings<br/>[config.ts]"]
  node_n_core{{"Core<br/>storage+search<br/>[index.ts]"}}
  node_n_embeddings["Embeddings<br/>vectorization<br/>[embeddings.ts]"]
  node_n_bm25["BM25<br/>lexical ranking<br/>[bm25.ts]"]
  node_n_qdrant[("Qdrant<br/>vector store<br/>[qdrant.ts]")]
  node_n_security["Security<br/>filtering<br/>[security.ts]"]
  node_n_pipeline{{"Pipeline<br/>ingestion<br/>[index.ts]"}}
  node_n_classifier["Classifier<br/>labeling<br/>[classifier.ts]"]
  node_n_extraction["Extraction<br/>normalization<br/>[extraction.ts]"]
  node_n_graph{{"Graph<br/>enrichment<br/>[index.ts]"}}
  node_n_autolink["Auto-link<br/>linking<br/>[autolink.ts]"]
  node_n_falkor[("FalkorDB<br/>graph store<br/>[falkordb.ts]")]
  node_n_cache["Cache<br/>[layer-cache.ts]"]
  node_n_broadcast["Broadcast<br/>pub/sub<br/>[index.ts]"]
  node_n_cognitive{{"Cognitive<br/>ranking+learning<br/>[index.ts]"}}
  node_n_retrieval["Recall<br/>retrieval<br/>[retrieval.ts]"]
  node_n_consolidation["Consolidation<br/>learning<br/>[consolidation.ts]"]
  node_n_tools{{"Tools<br/>agent api<br/>[index.ts]"}}
end

subgraph group_grp_docs["docs"]
  node_n_examples["Examples<br/>usage<br/>[README.md]"]
end

subgraph group_grp_ci["infra"]
  node_n_docker["Deploy<br/>infra<br/>[docker-compose.yml]"]
end

node_n_index -->|"loads"| node_n_config
node_n_index -->|"exposes"| node_n_core
node_n_index -->|"exposes"| node_n_pipeline
node_n_index -->|"exposes"| node_n_cognitive
node_n_index -->|"exposes"| node_n_tools
node_n_pipeline -->|"filters"| node_n_security
node_n_pipeline -->|"embeds"| node_n_embeddings
node_n_pipeline -->|"classifies"| node_n_classifier
node_n_pipeline -->|"normalizes"| node_n_extraction
node_n_pipeline -->|"stores"| node_n_core
node_n_core -->|"persists"| node_n_qdrant
node_n_core -->|"ranks"| node_n_bm25
node_n_core -->|"uses"| node_n_embeddings
node_n_core -->|"guards"| node_n_security
node_n_cognitive -->|"coordinates"| node_n_retrieval
node_n_cognitive -->|"learns"| node_n_consolidation
node_n_retrieval -->|"checks"| node_n_cache
node_n_retrieval -->|"queries"| node_n_core
node_n_retrieval -->|"enriches"| node_n_graph
node_n_graph -->|"links"| node_n_autolink
node_n_graph -->|"stores"| node_n_falkor
node_n_broadcast -->|"shares"| node_n_cache
node_n_broadcast -->|"powers"| node_n_tools
node_n_tools -->|"stores via"| node_n_pipeline
node_n_tools -->|"recalls via"| node_n_retrieval
node_n_tools -->|"consolidates"| node_n_consolidation
node_n_examples -.->|"demonstrates"| node_n_tools
node_n_docker -.->|"deploys with"| node_n_qdrant
node_n_docker -.->|"optionally deploys"| node_n_falkor

click node_n_index "https://github.com/28naem-del/mnemosyne/blob/main/src/index.ts"
click node_n_config "https://github.com/28naem-del/mnemosyne/blob/main/src/config.ts"
click node_n_core "https://github.com/28naem-del/mnemosyne/blob/main/src/core/index.ts"
click node_n_embeddings "https://github.com/28naem-del/mnemosyne/blob/main/src/core/embeddings.ts"
click node_n_bm25 "https://github.com/28naem-del/mnemosyne/blob/main/src/core/bm25.ts"
click node_n_qdrant "https://github.com/28naem-del/mnemosyne/blob/main/src/core/qdrant.ts"
click node_n_security "https://github.com/28naem-del/mnemosyne/blob/main/src/core/security.ts"
click node_n_pipeline "https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/index.ts"
click node_n_classifier "https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/classifier.ts"
click node_n_extraction "https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/extraction.ts"
click node_n_graph "https://github.com/28naem-del/mnemosyne/blob/main/src/graph/index.ts"
click node_n_autolink "https://github.com/28naem-del/mnemosyne/blob/main/src/graph/autolink.ts"
click node_n_falkor "https://github.com/28naem-del/mnemosyne/blob/main/src/graph/falkordb.ts"
click node_n_cache "https://github.com/28naem-del/mnemosyne/blob/main/src/cache/layer-cache.ts"
click node_n_broadcast "https://github.com/28naem-del/mnemosyne/blob/main/src/broadcast/index.ts"
click node_n_cognitive "https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/index.ts"
click node_n_retrieval "https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/retrieval.ts"
click node_n_consolidation "https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/consolidation.ts"
click node_n_tools "https://github.com/28naem-del/mnemosyne/blob/main/src/tools/index.ts"
click node_n_examples "https://github.com/28naem-del/mnemosyne/blob/main/examples/README.md"
click node_n_docker "https://github.com/28naem-del/mnemosyne/blob/main/docker-compose.yml"

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_n_index,node_n_config,node_n_core,node_n_embeddings,node_n_bm25,node_n_qdrant,node_n_security,node_n_pipeline,node_n_classifier,node_n_extraction,node_n_graph,node_n_autolink,node_n_falkor,node_n_cache,node_n_broadcast,node_n_cognitive,node_n_retrieval,node_n_consolidation,node_n_tools toneBlue
class node_n_examples toneAmber
class node_n_docker toneMint
```

## Components

### src

Core library implementation

- [Public API](https://github.com/28naem-del/mnemosyne/blob/main/src/index.ts): entrypoint · Library entrypoint that re-exports the main memory system · `src/index.ts`
- [Config](https://github.com/28naem-del/mnemosyne/blob/main/src/config.ts): settings · Runtime configuration and service wiring · `src/config.ts`
- [Core](https://github.com/28naem-del/mnemosyne/blob/main/src/core/index.ts): storage+search · Low-level embeddings, BM25, deduplication, Qdrant access, and security filtering · `src/core/index.ts`
- [Embeddings](https://github.com/28naem-del/mnemosyne/blob/main/src/core/embeddings.ts): vectorization · Embedding generation used by ingestion and recall · `src/core/embeddings.ts`
- [BM25](https://github.com/28naem-del/mnemosyne/blob/main/src/core/bm25.ts): lexical ranking · Sparse lexical scoring support for retrieval · `src/core/bm25.ts`
- [Qdrant](https://github.com/28naem-del/mnemosyne/blob/main/src/core/qdrant.ts): vector store · Primary persistent vector store and similarity search boundary · `src/core/qdrant.ts`
- [Security](https://github.com/28naem-del/mnemosyne/blob/main/src/core/security.ts): filtering · Input and retrieval safety filtering · `src/core/security.ts`
- [Pipeline](https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/index.ts): ingestion · Write path that transforms raw input into structured memory · `src/pipeline/index.ts`
- [Classifier](https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/classifier.ts): labeling · Assigns memory types, urgency, domain, and confidence · `src/pipeline/classifier.ts`
- [Extraction](https://github.com/28naem-del/mnemosyne/blob/main/src/pipeline/extraction.ts): normalization · Turns raw text into structured memory records · `src/pipeline/extraction.ts`
- [Graph](https://github.com/28naem-del/mnemosyne/blob/main/src/graph/index.ts): enrichment · Optional relational layer for linking and temporal navigation · `src/graph/index.ts`
- [Auto-link](https://github.com/28naem-del/mnemosyne/blob/main/src/graph/autolink.ts): linking · Creates relationships between related memories and entities · `src/graph/autolink.ts`
- [FalkorDB](https://github.com/28naem-del/mnemosyne/blob/main/src/graph/falkordb.ts): graph store · Optional temporal knowledge graph backend · `src/graph/falkordb.ts`
- [Cache](https://github.com/28naem-del/mnemosyne/blob/main/src/cache/layer-cache.ts): two-tier cache · L1/L2 cache interface for recall acceleration · `src/cache/layer-cache.ts`
- [Broadcast](https://github.com/28naem-del/mnemosyne/blob/main/src/broadcast/index.ts): pub/sub · Cross-agent memory propagation and synthesis · `src/broadcast/index.ts`
- [Cognitive](https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/index.ts): ranking+learning · Decay, consolidation, intent, confidence, recall, and self-improvement behaviors · `src/cognitive/index.ts`
- [Recall](https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/retrieval.ts): retrieval · Read-path scoring and result assembly · `src/cognitive/retrieval.ts`
- [Consolidation](https://github.com/28naem-del/mnemosyne/blob/main/src/cognitive/consolidation.ts): learning · Promotes and reshapes memory based on usage and feedback · `src/cognitive/consolidation.ts`
- [Tools](https://github.com/28naem-del/mnemosyne/blob/main/src/tools/index.ts): agent api · Agent-facing operations for store, recall, forget, feedback, and memory mining · `src/tools/index.ts`

### docs

Repository documentation and examples

- [Examples](https://github.com/28naem-del/mnemosyne/blob/main/examples/README.md): usage · Integration examples for basic, Redis, and FalkorDB setups · `examples/README.md`

### infra

Build, release, and deployment assets

- [Deploy](https://github.com/28naem-del/mnemosyne/blob/main/docker-compose.yml): infra · Container and compose assets for local deployment · `docker-compose.yml`

## Connections

- Public API → Config: loads · Entry point wires runtime configuration
- Public API → Core: exposes · Public API re-exports storage/search primitives
- Public API → Pipeline: exposes · Public API exposes ingestion workflow
- Public API → Cognitive: exposes · Public API exposes higher-order memory behaviors
- Public API → Tools: exposes · Public API exposes agent-facing tools
- Pipeline → Security: filters · Write path begins with safety filtering
- Pipeline → Embeddings: embeds · Pipeline vectorizes incoming content
- Pipeline → Classifier: classifies · Pipeline assigns memory metadata
- Pipeline → Extraction: normalizes · Pipeline converts text into structured memory
- Pipeline → Core: stores · Structured memories are persisted through the core layer
- Core → Qdrant: persists · Core owns the hard vector-store dependency
- Core → BM25: ranks · Core combines sparse lexical scoring with vector retrieval
- Core → Embeddings: uses · Core shares embedding primitives with ingestion and recall
- Core → Security: guards · Core applies filtering around stored/retrieved content
- Cognitive → Recall: coordinates · Cognitive layer orchestrates read-path ranking
- Cognitive → Consolidation: learns · Cognitive layer updates memory importance over time
- Recall → Cache: checks · Recall consults the cache before vector search
- Recall → Core: queries · Recall uses core search primitives
- Recall → Graph: enriches · Recall can add graph-based context
- Graph → Auto-link: links · Graph layer builds relationships between memories
- Graph → FalkorDB: stores · Optional graph backend for temporal knowledge
- Broadcast → Cache: shares · Broadcasting complements cache-backed shared state
- Broadcast → Tools: powers · Agent tools expose shared-memory operations
- Tools → Pipeline: stores via · Store tool invokes ingestion pipeline
- Tools → Recall: recalls via · Recall tool invokes ranked retrieval
- Tools → Consolidation: consolidates · Tools expose consolidation workflows
- Examples → Tools: demonstrates · Examples show how to use the agent-facing API
- Deploy → Qdrant: deploys with · Local deployment includes the vector store service
- Deploy → FalkorDB: optionally deploys · Compose setup can include the graph backend
