Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

System Overview

┌──────────┐  ┌───────────┐  ┌──────────┐  ┌──────────┐
│MCP Client│  │REST Client│  │  gRPC    │  │  psql    │
│ (stdio)  │  │  (HTTP)   │  │ (tonic)  │  │ (pgwire) │
└────┬─────┘  └─────┬─────┘  └────┬─────┘  └────┬─────┘
     │              │              │              │
     ▼              ▼              ▼              ▼
┌────────────────────────────────────────────────────────┐
│                    MnemoEngine                          │
│  ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│  │ Remember │ │  Recall  │ │ Forget/  │ │Checkpoint│ │
│  │ Pipeline │ │ Pipeline │ │Share/... │ │/Branch/  │ │
│  │          │ │  (RRF)   │ │          │ │Merge     │ │
│  └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│       └─────────────┴────────────┴────────────┘       │
│                         │                              │
│  ┌──────────────────────▼──────────────────────────┐  │
│  │          StorageBackend (trait)                   │  │
│  │   ┌──────────┐              ┌─────────────┐     │  │
│  │   │  DuckDB   │              │  PostgreSQL  │     │  │
│  │   │           │              │  + pgvector  │     │  │
│  │   └──────────┘              └─────────────┘     │  │
│  └──────────────────────────────────────────────────┘  │
│                                                         │
│  ┌────────────┐ ┌──────────┐ ┌──────────┐ ┌────────┐ │
│  │VectorIndex │ │FullText  │ │Embeddings│ │Encrypt │ │
│  │USearch/PG  │ │ Tantivy  │ │OpenAI/   │ │AES-256 │ │
│  │  (HNSW)   │ │ (BM25)   │ │ONNX/Noop │ │  GCM   │ │
│  └────────────┘ └──────────┘ └──────────┘ └────────┘ │
│                                                         │
│  ┌────────────┐ ┌──────────┐ ┌──────────────────────┐ │
│  │   Cache    │ │ColdStore │ │  Poisoning Detection  │ │
│  │ (in-mem)   │ │  (S3)    │ │  + Prompt Injection   │ │
│  └────────────┘ └──────────┘ └──────────────────────┘ │
└─────────────────────────────────────────────────────────┘

Crate Structure

CratePurpose
mnemo-coreStorage, data model, query engine, indexing, encryption
mnemo-mcpMCP server via rmcp 3.0 (STDIO transport)
mnemo-cliCLI binary with clap argument parsing
mnemo-postgresPostgreSQL storage backend via sqlx + pgvector
mnemo-restREST API via Axum 0.8
mnemo-adminAdmin dashboard endpoints (agent stats)
mnemo-pgwirePostgreSQL wire protocol server
mnemo-grpcgRPC API via tonic 0.12
pythonPython bindings via PyO3

Data Model

MemoryRecord

The core data structure. Key fields:

FieldTypeDescription
idUUID v7Time-ordered unique identifier
agent_idStringOwning agent
contentStringMemory content (encrypted at rest if enabled)
memory_typeEnumEpisodic, Semantic, Procedural, Strategic
scopeEnumPrivate, Shared, Global
importancef320.0-1.0 importance score
tagsVecSearchable tags
embeddingVecVector embedding
content_hashVec<u8>SHA-256 hash
prev_hashOptionPrevious record hash (chain)
quarantinedboolFlagged by poisoning detection
decay_rateOption<f32>Custom decay rate
decay_functionOptionCustom decay function

Retrieval Pipeline

Recall uses Reciprocal Rank Fusion (RRF) to combine:

  1. Vector similarity (cosine via USearch or pgvector HNSW)
  2. BM25 full-text (Tantivy)
  3. Recency scoring (exponential decay with configurable half-life)
  4. Graph expansion (1-2 hop relation traversal)

Weights are configurable via hybrid_weights parameter. Permission-safe ANN pre-filtering ensures only authorized memories appear in results.

Access Control

Three-tier permission model:

  1. Owner: Agent who created the memory has full access
  2. ACL: Explicit grants via share with permission levels (Read, Write, Delete, Share, Delegate)
  3. Delegation: Transitive, scoped, time-bounded permission delegation with depth limits

Hash Chain Integrity

Every memory record is linked via SHA-256 hashes:

Record₁ → content_hash = SHA256(content + agent_id + timestamp)
Record₂ → prev_hash = SHA256(content_hash₂ + content_hash₁)
Record₃ → prev_hash = SHA256(content_hash₃ + content_hash₂)

The verify tool checks the entire chain for tampering using constant-time comparisons.

Security Layers

  • Encryption: AES-256-GCM at-rest content encryption (pluggable via ContentEncryption)
  • Validation: agent_id charset/length validation at engine level
  • Poisoning: anomaly scoring + prompt injection pattern detection → quarantine
  • CORS: configurable origin allowlist, defaults to localhost
  • Error sanitization: internal errors logged only, generic messages returned