memory-likehuman-pro - v1.5.0
    Preparing search index...

    memory-likehuman-pro - v1.5.0

    ๐Ÿง  brain-memory

    ไธบ AI Agent ๆ‰“้€ ็š„ๅคง่„‘็บง่ฎฐๅฟ†็ณป็ปŸ

    ่ฎฉ Agent ๅƒไบบไธ€ๆ ท่ฎฐไฝ ยท ้—ๅฟ˜ ยท ๅๆ€ ยท ๆŽจ็†

    Features โ€ข Architecture โ€ข Installation โ€ข Quick Start โ€ข Memory Categories โ€ข Recall Strategies โ€ข API โ€ข License

    Unified knowledge graph + vector memory system for AI agents.
    Merges graph-memory with memory-lancedb-pro into an 8-category system with intelligent decay and reflection.


    brain-memory simulates human brain memory mechanisms:

    ๐Ÿงฌ Human Mechanism โšก Code Implementation
    Short-term โ†’ Long-term Working Memory โ†’ Knowledge Graph persistence
    Forgetting Curve Weibull decay model (3-tier + dynamic acceleration)
    Knowledge Association Personalized PageRank + Community detection
    Reflection Turn reflection (lightweight) + Session reflection (deep)
    Inductive Reasoning 4-type reasoning engine (path / implicit / pattern / contradiction)

    ๐Ÿ“ฆ Memory System โ€” 8 categories ยท Bidirectional extraction ยท Graph structure ยท Time decay
    • 8-Category Memory โ€” profile / preferences / entities / events / tasks / skills / cases / patterns
    • Bidirectional Knowledge Extraction โ€” Extracts both user messages and AI replies (suggestions, code, tool recommendations)
    • Graph Nodes + Edges โ€” 3 node types (TASK / SKILL / EVENT) ร— 11 edge types with strict direction constraints
    • Time Decay โ€” Weibull model with static/dynamic differentiated decay
    ๐Ÿ” Recall Engine โ€” Dual-path ยท Hybrid fusion ยท Intent analysis ยท Query expansion ยท Reranking
    • Dual-Path Recall โ€” Precise path (vector โ†’ community expansion โ†’ graph walk โ†’ PPR) + Generalized path (community match โ†’ graph walk โ†’ PPR)
    • Hybrid Recall โ€” Graph + vector recall in parallel, Min-Max normalization + RRF fusion
    • Vector-Only Mode โ€” Vector search + BM25 full-text + RRF fusion, no graph dependency
    • Intent Analysis โ€” 5 intent types (technical / preference / factual / task / general)
    • Query Expansion โ€” 14 bilingual synonym mappings (Chinese/English)
    • Cross-Encoder Reranking โ€” Supports Jina / SiliconFlow / Voyage / DashScope / TEI / Pinecone
    ๐Ÿ•ธ๏ธ Knowledge Graph โ€” Community detection ยท PageRank ยท Fusion ยท Graph walk
    • Community Detection โ€” Label Propagation Algorithm (LPA), LLM-generated community summaries
    • Personalized PageRank โ€” Query-dependent ranking based on seed nodes
    • Knowledge Fusion โ€” Two-phase dedup (name overlap + vector similarity), LLM decides merge/link/none
    • Graph Walk โ€” Recursive CTE from seed nodes, builds related subgraphs
    ๐Ÿ”„ Smart Maintenance โ€” Reflection ยท Compression ยท Pipeline maintenance
    • Session-End Reflection โ€” LLM full analysis, 4 insight types (user model / agent lessons / experience / decisions)
    • Turn Reflection โ€” Lightweight evaluation, dynamically boosts node importance
    • Graph Maintenance Pipeline โ€” Dedup โ†’ PageRank โ†’ Community detection โ†’ Community summaries
    • Incremental Maintenance โ€” Dirty-node marking + subgraph PageRank/LPA + smart threshold trigger (v1.1.0)
    • Session Compression โ€” Knowledge density evaluation, auto-summarize low-value sessions
    ๐Ÿ›ก๏ธ Engineering โ€” Scope isolation ยท Working memory ยท Noise filtering ยท Security
    • Multi-Scope Isolation โ€” Isolate by session / agent / workspace, parameterized queries prevent SQL injection
    • Working Memory โ€” Zero LLM overhead, tracks current tasks / decisions / constraints / attention
    • Noise Filtering โ€” Multilingual regex filtering (EN / CN / JP / KR / FR / ES / DE / IT)
    • Prompt Injection Protection โ€” 6-rule safety filter for reflection content

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ ๐ŸŒ API Layer โ”‚
    โ”‚ ContextEngine (Unified Facade Interface) โ”‚
    โ”‚ processTurn โ”‚ recall โ”‚ performFusion โ”‚ reflectOnSession โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ ๐ŸŽ›๏ธ Control Layer โ”‚
    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚ โ”‚ Extractorโ”‚ โ”‚ Recaller โ”‚ โ”‚ Fusion โ”‚ โ”‚Reflectionโ”‚ โ”‚Reasoningโ”‚ โ”‚
    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚ โ”‚ Hybrid โ”‚ โ”‚ Vector โ”‚ โ”‚ Rerank โ”‚ โ”‚Admission โ”‚ โ”‚ Working โ”‚ โ”‚
    โ”‚ โ”‚ Recall โ”‚ โ”‚ Recall โ”‚ โ”‚ er โ”‚ โ”‚ Control โ”‚ โ”‚ Memory โ”‚ โ”‚
    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ โš™๏ธ Algorithm Layer โ”‚
    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚ โ”‚ PageRank โ”‚ โ”‚ Community โ”‚ โ”‚ LSH โ”‚ โ”‚ Temporal โ”‚ โ”‚
    โ”‚ โ”‚ (PPR) โ”‚ โ”‚ Detection โ”‚ โ”‚ Dedup โ”‚ โ”‚ Classifier โ”‚ โ”‚
    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚ โ”‚ Decay โ”‚ โ”‚ Intent โ”‚ โ”‚ Query โ”‚ โ”‚
    โ”‚ โ”‚ (Weibull) โ”‚ โ”‚ Analyzer โ”‚ โ”‚ Expander โ”‚ โ”‚
    โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ ๐Ÿ’พ Storage Layer โ”‚
    โ”‚ SQLite: 6 tables + FTS5 + Triggers + 8 indexes (v1.1.0: IStorageAdapter abstraction, supports LanceDB POC) โ”‚
    โ”‚ bm_nodes โ”‚ bm_edges โ”‚ bm_vectors โ”‚ bm_messages โ”‚
    โ”‚ bm_communities โ”‚ bm_nodes_fts โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

    npm install memory-likehuman-pro
    

    Note: The published npm package contains the compiled dist/ output. Source files (src/, test/, etc.) are not included in the npm package.

    git clone https://github.com/DylingCreation/brain-memory.git
    cd brain-memory
    npm install
    1. Visit https://github.com/DylingCreation/brain-memory
    2. Click Code โ†’ Download ZIP
    3. Extract and install dependencies:
    cd brain-memory
    npm install

    import { ContextEngine, DEFAULT_CONFIG } from 'memory-likehuman-pro';

    const config = {
    ...DEFAULT_CONFIG,
    dbPath: '~/.openclaw/brain-memory.db',
    llm: {
    apiKey: process.env.LLM_API_KEY,
    baseURL: 'https://your-ll-api-endpoint/v1',
    model: 'your-model-name'
    },
    embedding: {
    apiKey: process.env.EMBEDDING_API_KEY,
    baseURL: 'https://your-embedding-api-endpoint/v1',
    model: 'your-embedding-model'
    }
    };

    const engine = new ContextEngine(config);

    // ๐Ÿ“ Process conversation turns, extract knowledge
    const result = await engine.processTurn({
    sessionId: 'session-1',
    agentId: 'agent-1',
    workspaceId: 'workspace-1',
    messages: [{
    role: 'user',
    content: 'I need to implement a memory system in TypeScript'
    }]
    });

    console.log(`Extracted ${result.extractedNodes.length} nodes, ${result.extractedEdges.length} edges`);

    // ๐Ÿ” Recall relevant memories
    const recall = await engine.recall('TypeScript memory system', 'session-1', 'agent-1', 'workspace-1');
    console.log(`Recalled ${recall.nodes.length} relevant memories`);

    brain-memory is designed as an OpenClaw plugin. Configure it in your OpenClaw config file (default: ~/.openclaw/openclaw.json):

    {
    "plugins": {
    "entries": {
    "brain-memory": {
    "enabled": true,
    "config": {
    "llm": {
    "apiKey": "your-api-key-here",
    "baseURL": "https://your-ll-api-endpoint/v1",
    "model": "your-model-name"
    },
    "embedding": {
    "apiKey": "your-embedding-api-key",
    "baseURL": "https://your-embedding-api-endpoint/v1",
    "model": "your-embedding-model"
    },
    "engine": "hybrid",
    "storage": "sqlite",
    "mode": "full",
    "dbPath": "~/.openclaw/brain-memory.db"
    }
    }
    }
    }
    }

    Plugin hooks registered automatically:

    ๐Ÿ”— Hook โฐ Trigger ๐ŸŽฏ Function
    message_received After user sends a message Extract knowledge from user messages
    message_sent โœจ After AI sends a reply Extract suggestions / code / commitments from AI replies
    before_message_write Before AI sends a reply Inject relevant memories into context
    session_start New session starts Warm up memory cache
    session_end Session ends Run reflection + graph maintenance

    The project includes interactive configuration scripts. These are generic setup tools (not platform-specific) that generate basic LLM/Embedding API config files:

    # Interactive config โ€” generates config.js, .env, llm_client.js
    npm run configure

    # OpenClaw integration โ€” writes config into ~/.openclaw/openclaw.json
    npm run setup-openclaw

    Important: The interactive config scripts only set up core API credentials (LLM endpoint, API key, model name, embedding settings) and run mode (full/lite). They do not configure advanced brain-memory features such as decay parameters, reflection settings, fusion thresholds, or working memory limits. Those must be configured manually in your OpenClaw config file or programmatically via BmConfig.

    Lite mode (mode: "lite"): Skips LLM reflection and knowledge fusion. Keeps heuristic extraction + vector recall + working memory. Recommended for local models (e.g. qwen3.5:9b via Ollama) to reduce latency.

    Quickly check your environment, dependencies, configuration, and database status:

    npm run doctor
    # or: npx brain-memory-doctor

    Checks: Node.js version, dependency installation, LLM/Embedding config, database file/schema version/table stats, WAL/SHM residual files.


    brain-memory uses 8 memory categories to cover all valuable conversation information:

    ๐Ÿท๏ธ Category ๐Ÿ“– Meaning ๐Ÿ’ก Example
    profile User identity / role / background "User is a full-stack engineer"
    preferences Likes / dislikes / habits "User prefers concise replies"
    entities Projects / tools / environments "Project uses SQLite"
    events Errors / exceptions that occurred "Docker port conflict"
    tasks Completed tasks / discussion topics "Implement memory system"
    skills Reusable procedures (how-to) "npm install command"
    cases Case experience (success / failure) "Check port before deploying"
    patterns Cross-case abstract patterns "Checking port before deploy is a general rule"

    ๐Ÿš€ Mode ๐Ÿ“ Description ๐ŸŽฏ Use Case
    graph (default) Knowledge graph + Community + PPR When relationship context matters
    vector Pure vector + BM25 + RRF Lightweight deployment, no graph dependency
    hybrid Graph + vector recall in parallel fusion Best recall quality

    ๐ŸŽฏ Precise Path (graph mode):

    Query โ†’ Vector search / FTS5 โ†’ Community expansion (distance 2) โ†’ Graph walk (maxDepth) โ†’ PPR ranking โ†’ Time decay โ†’ Return Top N
    

    ๐ŸŒ Generalized Path (graph mode):

    Query โ†’ Community vector match โ†’ Community members โ†’ Graph walk (1 layer) โ†’ PPR ranking โ†’ Merge with precise path
    

    ๐Ÿ”€ Hybrid Fusion:

    Graph recall (PPR score) โ”€โ”€โ”
    โ”œโ”€โ”€โ†’ Min-Max normalization โ†’ RRF fusion โ†’ Sort โ†’ Return
    Vector recall (RRF score) โ”€โ”€โ”˜

    ๐Ÿ“‹ Click to expand full configuration reference
    interface BmConfig {
    // ๐Ÿš€ Engine mode: graph(default) | vector | hybrid
    engine: 'graph' | 'vector' | 'hybrid';

    // ๐Ÿƒ Run mode: full(default) | lite (skips LLM reflection/fusion)
    mode: 'full' | 'lite';
    engine: 'graph' | 'vector' | 'hybrid';

    // ๐Ÿ’พ Storage backend: sqlite(default) | lancedb
    storage: 'sqlite' | 'lancedb';

    // ๐Ÿ“ Database path
    dbPath: string;

    // ๐Ÿ—œ๏ธ Session compression turn count
    compactTurnCount: number;

    // ๐Ÿ” Recall settings
    recallMaxNodes: number; // default: 6
    recallMaxDepth: number; // default: 2
    recallStrategy: 'full' | 'summary' | 'adaptive' | 'off';

    // ๐Ÿค– LLM settings
    llm: {
    apiKey?: string;
    baseURL?: string;
    model?: string;
    };

    // ๐Ÿ”ข Embedding settings
    embedding: {
    apiKey?: string;
    baseURL?: string;
    model?: string;
    dimensions?: number;
    };

    // ๐Ÿ”„ Dedup threshold
    dedupThreshold: number; // default: 0.90

    // ๐Ÿ“Š PageRank settings
    pagerankDamping: number; // default: 0.85
    pagerankIterations: number; // default: 20

    // โณ Decay settings
    decay: {
    enabled: boolean; // default: false
    recencyHalfLifeDays: number; // default: 30
    recencyWeight: number; // default: 0.4
    frequencyWeight: number; // default: 0.3
    intrinsicWeight: number; // default: 0.3
    timeDecayHalfLifeDays: number; // default: 60
    betaCore: number; betaWorking: number; betaPeripheral: number;
    coreDecayFloor: number; workingDecayFloor: number; peripheralDecayFloor: number;
    };

    // ๐Ÿ”‡ Noise filter
    noiseFilter: {
    enabled: boolean; // default: true
    minContentLength: number; // default: 10
    };

    // ๐Ÿ’ญ Reflection
    reflection: {
    enabled: boolean; // default: true
    turnReflection: boolean; // default: false
    sessionReflection: boolean; // default: true
    safetyFilter: boolean; // default: true
    maxInsights: number; // default: 8
    importanceBoost: number; // default: 0.15
    minConfidence: number; // default: 0.6
    };

    // ๐Ÿง  Working memory
    workingMemory: {
    enabled: boolean; // default: true
    maxTasks: number; // default: 3
    maxDecisions: number; // default: 5
    maxConstraints: number; // default: 5
    };

    // ๐Ÿ”— Knowledge fusion
    fusion: {
    enabled: boolean; // default: true
    similarityThreshold: number; // default: 0.75
    minNodes: number; // default: 20
    minCommunities: number; // default: 3
    };

    // ๐Ÿงฉ Reasoning
    reasoning: {
    enabled: boolean; // default: true
    maxHops: number; // default: 2
    maxConclusions: number; // default: 3
    minRecallNodes: number; // default: 3
    };
    }

    The unified context engine โ€” main entry point for all features.

    class ContextEngine {
    // ๐Ÿ“ Process conversation turn, extract knowledge
    processTurn(params: {
    sessionId: string; agentId: string; workspaceId: string;
    messages: Array<{ role: string; content: string }>;
    }): Promise<{
    extractedNodes: BmNode[]; extractedEdges: BmEdge[];
    reflections: ReflectionInsight[]; workingMemory: WorkingMemoryState;
    }>;

    // ๐Ÿ” Recall relevant memories
    recall(query: string, sessionId?: string, agentId?: string, workspaceId?: string): Promise<RecallResult>;

    // ๐Ÿ”— Knowledge fusion (merge duplicate nodes)
    performFusion(sessionId?: string): Promise<FusionResult>;

    // ๐Ÿ’ญ Session reflection
    reflectOnSession(sessionId: string, messages: Array<{ role: string; content: string }>): Promise<ReflectionInsight[]>;

    // ๐Ÿงฉ Reasoning engine
    performReasoning(query?: string): Promise<ReasoningConclusion[]>;

    // ๐Ÿ”„ Maintenance (dedup + PageRank + community detection)
    runMaintenance(): Promise<void>;

    // ๐Ÿง  Working memory context
    getWorkingMemoryContext(): string | null;

    // ๐Ÿ”Ž Node search
    searchNodes(query: string, limit?: number): BmNode[];

    // ๐Ÿ“Š Statistics (enhanced in v0.2.0)
    getStats(): EngineStats; // nodes by type/status/source, communities, vectors, dbSizeBytes, schemaVersion, uptimeMs, embedCache, queryTimeMs

    // ๐Ÿฉบ Health check (new in v0.2.0)
    healthCheck(): HealthStatus; // overall status, component status (db/llm/embedding), stats, uptime, schemaVersion

    // โŒ Close database
    close(): void;
    }

    brain-memory uses SQLite with 6 tables + FTS5 full-text index:

    ๐Ÿ“‹ Table ๐Ÿ“ Purpose ๐Ÿ”‘ Key Fields
    bm_nodes Memory nodes id, type, category, name, content, pagerank, importance, scope_*
    bm_edges Knowledge edges from_id, to_id, type, instruction, condition
    bm_vectors Vector embeddings node_id(FK), embedding(BLOB), hash
    bm_messages Conversation messages session_id, turn_index, role, content, extracted
    bm_communities Community summaries id, summary, node_count, embedding
    bm_nodes_fts FTS5 index name, description, content (auto-synced via triggers)

    ๐Ÿ›ก๏ธ Feature ๐Ÿ“ Description
    Parameterized SQL All DB operations use ? placeholders โ€” no SQL injection
    Scope Isolation Memory isolated by session / agent / workspace with cross-scope authorization
    Prompt Injection Protection 6-rule safety filter on reflection content (ignore-instruction / key-leak / role-switch / HTML-inject / role-prefix / disable-safety)
    Input Validation Strict validation on node types / edge types / memory categories

    npm test
    

    Comprehensive test coverage (v1.5.0):

    • โœ… 625+ test cases โ€” 59 test files, 0 failures (LLM timeout excluded)
    • โœ… comprehensive code coverage โ€” Core modules (recall, llm, embed, plugin) > 90%
    • โœ… Unit tests โ€” Individual components
    • โœ… Integration tests โ€” Full workflows
    • โœ… Performance benchmarks โ€” 0.44ms recall avg, 7.21ms vector search
    • โœ… Error handling โ€” Graceful degradation, edge case coverage

    # Build the project
    npm run build

    # Clean build artifacts
    npm run clean

    # Run linting
    npm run lint

    # Generate API docs
    npm run docs

    ๐Ÿ“‚ Click to expand directory structure
    brain-memory/
    โ”œโ”€โ”€ src/ # Source code
    โ”‚ โ”œโ”€โ”€ store/ # Database operations (CRUD + FTS5 + vectors)
    โ”‚ โ”œโ”€โ”€ extractor/ # Knowledge extraction (LLM node/edge extraction)
    โ”‚ โ”œโ”€โ”€ recaller/ # Dual-path recall engine
    โ”‚ โ”œโ”€โ”€ retriever/ # Hybrid recall / Vector recall / Reranker / Admission control
    โ”‚ โ”œโ”€โ”€ reasoning/ # Reasoning engine
    โ”‚ โ”œโ”€โ”€ reflection/ # Reflection system
    โ”‚ โ”œโ”€โ”€ fusion/ # Knowledge fusion & dedup
    โ”‚ โ”œโ”€โ”€ decay/ # Weibull forgetting algorithm
    โ”‚ โ”œโ”€โ”€ scope/ # Multi-scope isolation
    โ”‚ โ”œโ”€โ”€ temporal/ # Temporal classification (static/dynamic)
    โ”‚ โ”œโ”€โ”€ noise/ # Noise filtering
    โ”‚ โ”œโ”€โ”€ working-memory/ # Working memory management
    โ”‚ โ”œโ”€โ”€ format/ # Context formatting & assembly
    โ”‚ โ”œโ”€โ”€ engine/ # Core engines (LLM + Embedding + ContextEngine)
    โ”‚ โ”œโ”€โ”€ graph/ # Graph algorithms (PageRank / Community / Dedup / Maintenance)
    โ”‚ โ”œโ”€โ”€ preferences/ # Preference slot extraction
    โ”‚ โ”œโ”€โ”€ session/ # Session compression
    โ”‚ โ”œโ”€โ”€ plugin/ # OpenClaw plugin interfaces
    โ”‚ โ””โ”€โ”€ utils/ # Utilities (JSON / Similarity / Text / XML)
    โ”‚
    โ”œโ”€โ”€ test/ # Test files
    โ”‚ โ”œโ”€โ”€ *.test.ts # Unit tests
    โ”‚ โ””โ”€โ”€ integration/ # Integration tests
    โ”‚
    โ”œโ”€โ”€ docs/ # Documentation
    โ”œโ”€โ”€ scripts/ # Configuration scripts
    โ”œโ”€โ”€ openclaw-*.ts # OpenClaw plugin entry points
    โ””โ”€โ”€ index.ts # Module export entry

    ,


    MIT ยท See CHANGELOG.md for full release history.

    Made with โค๏ธ for AI Agents