Agentmemory uses a multi-stage pipeline to capture, compress, and index observations from agent tool usage.
1. Capture (Hooks)
Various hooks trigger memory actions:
SessionStart: Loads project profile (concepts, files, patterns).UserPromptSubmit: Captures user prompts (after privacy filtering).PreToolUse: Captures file access patterns and context enrichment.PostToolUse: Captures tool name, input, and output.PostToolUseFailure: Captures error context.Stop / SessionEnd: Triggers session summarization and knowledge graph extraction (if GRAPH_EXTRACTION_ENABLED=true).
2. Processing Pipeline
When a PostToolUse hook fires:
- Deduplication: SHA-256 dedup within a 5-minute window.
- Privacy Filter: Strips secrets and API keys.
- Storage: Stores the raw observation.
- Compression: An LLM compresses observations into structured facts, concepts, and narratives.
- Embedding: Generates vector embeddings (via 6 providers or local).
- Indexing: Indexes data in both BM25 and vector stores.
3. Retrieval (Triple-Stream Search)
Search uses Reciprocal Rank Fusion (RRF, k=60) to combine three streams:
- BM25: Keyword matching with stemming and synonym expansion.
- Vector: Dense embedding cosine similarity.
- Graph: Knowledge graph exploration via entity matching.
To optimize retrieval for CJK (Chinese, Japanese, Korean) languages, install a segmenter to enable word-level tokenization:
npm install @node-rs/jieba tiny-segmenter
npm install @node-rs/jieba tiny-segmenter