ICM (Infinite Context Memory)

repository·main·Indexed 19 days ago

https://github.com/rtk-ai/icm

A permanent memory layer for AI agents providing a unified, cross-tool SQLite-backed database for episodic memories and structured knowledge graphs. It enables agents like Claude, Gemini, and Cursor to share context via a CLI, an HTTP API, or the Model Context Protocol (MCP). Features include hybrid search (FTS5 BM25 and vector search via ONNX Runtime), a TUI dashboard, verbatim session transcripts, and project isolation through topic naming.

Tokens
88.8K
Snippets
228
Records
404
Agent score
53%

What's inside ICM

  1. Compare ICM capabilities with alternatives

    main

    ICM provides a high-performance memory layer for AI tools with the following key advantages:

    • Tool Support: Supports 17 tools.
    • One-command Setup: Uses icm init for rapid configuration.
    • Hooks: Supports 5 tools with automatic retrieval on startup.
    • Hybrid Search: Uses a 30/70 weighted mix of FTS5 and Vector search.
    • Multilingual Embeddings: Supports 100+ languages (768d).
    • Knowledge Graph: Utilizes the Memoir system.
    • Temporal Decay & Merging: Access-aware decay models.
    • TUI Dashboard: Accessible via icm dashboard.
    • Automatic Extraction: 3-layer extraction from tool outputs with zero LLM overhead.
    • Feedback Loop: Supports icm_feedback_* for correction.
    • Runtime: Single Rust executable, local-first with zero dependencies (SQLite file).
  2. Understand the three layers of ICM auto-extraction

    main

    ICM uses three layers of automatic memory extraction. All three layers are implemented with zero LLM cost and are installed automatically via icm init --mode hook.

    LayerHook CommandDescription
    Layer 0: Pattern hooksicm hook postRule-based keyword extraction from tool outputs (e.g., Bash errors, git commits, config changes, decisions, preferences, learnings, constraints).
    Layer 1: PreCompacticm hook compactExtracts memories from the transcript before context is compressed/lost. Supports --store-raw fallback.
    Layer 2: UserPromptSubmiticm hook promptInjects recalled memories into the agent's context on every user prompt, ensuring the agent starts with relevant context.

    Workflow Summary:

    1. PostToolUse (Layer 0) captures raw events.
    2. PreCompact (Layer 1) captures context before it's compressed.
    3. UserPromptSubmit (Layer 2) performs the recall and injection loop.
  3. How ICM's memory models work

    main

    ICM uses two distinct memory models to manage information efficiently:

    1. Episodic Memories: Captures specific events like decisions, errors, or configuration changes. These memories are designed to decay naturally over time so that one-time fixes do not clutter the context indefinitely.
    2. Semantic Knowledge: Captures structural information like architecture graphs (e.g., service dependencies). This knowledge persists forever to maintain a stable understanding of the project.

    This dual approach ensures that critical architectural context is always available while preventing context window bloat from transient session details.

  4. How automatic memory extraction works in ICM

    main

    ICM extracts memories automatically using a three-layer architecture designed to minimize LLM costs and latency. These layers capture different stages of the interaction lifecycle:

    1. Layer 0: Pattern hooks (icm hook post) - Rule-based extraction (zero LLM cost) from tool outputs, such as Bash errors, git commits, config changes, decisions, preferences, learnings, and constraints.
    2. Layer 1: PreCompact (icm hook compact) - Extracts context from transcripts just before they are compressed, ensuring information isn't lost during context window management. It uses the same patterns as Layer 0 with a --store-raw fallback.
    3. Layer 2: UserPromptSubmit (icm hook prompt) - Injects relevant memories into the context immediately when a user sends a prompt, so the agent starts with the necessary background information.

    To automatically install and configure all three layers, use the following command:

    icm init --mode hook
  5. CLI vs MCP: Choosing the right interface

    main

    ICM can be used via the CLI (icm command) or as an MCP server (icm serve). Both access the same database.

    FeatureCLI (icm)MCP (icm serve)
    Latency~30ms (Direct binary)~50ms (JSON-RPC stdio)
    Token Cost0 (Hook-based, invisible)~20-50 tokens/call (Tool schema)
    Setupicm init --mode hookicm init --mode mcp
    Supported ToolsClaude Code, Gemini, Codex, Copilot, OpenCode (via hooks)All 17 MCP-compatible tools
    Best Use CasePower users, token savingUniversal compatibility
  6. Isolate memories by project using topic naming

    main

    ICM achieves project isolation through a specific topic naming convention rather than a separate database column. This ensures that memories from Project A do not leak into Project B.

    Naming Convention

    Use the format {kind}-{project} for project-specific memories. Certain topics are global and will always be included across all projects:

    • {kind}-{project}: e.g., decisions-icm, errors-resolved-icm, contexte-rtk-cloud
    • preferences: Global user preferences
    • identity: Global user identity

    Automatic Project Detection

    When using the icm_wake_up command, ICM performs segment-aware matching. For example, providing { project: "icm" } will match decisions-icm or errors-icm-core, but will not match icmp-notes.

    To automate isolation, run each project from its own directory. The UserPromptSubmit hook (icm hook prompt) and the SessionStart hook (icm hook start) automatically derive the project name from the cwd (current working directory) field in the hook JSON using the basename of the directory.

    // Example icm_wake_up call
    {
      "project": "icm"
    }
  7. Use the Memory and Memoir data models

    main

    ICM uses two primary data models to manage information: Memory for raw data points and Memoir for structured knowledge graphs.

    Memory

    Represents an individual piece of information. Key fields include:

    • id: A ULID.
    • importance: An enum (Critical, High, Medium, Low) that controls how the memory decays over time.
    • source: Where the memory came from (ClaudeCode, Conversation, or Manual).
    • embedding: An optional vector (384, 768, or 1024 dimensions) for semantic search.

    Memoir (Knowledge Graph)

    Organizes information into structured concepts using a graph model:

    • Memoir: A named container for a specific knowledge domain.
    • Concept: A node in the graph representing a defined idea. Concepts are unique within a memoir.
    • ConceptLink: A typed edge connecting two concepts. Relations include PartOf, DependsOn, RelatedTo, Contradicts, Refines, AlternativeTo, CausedBy, InstanceOf, and SupersededBy.
  8. How CLI and MCP modes differ

    main

    ICM can be used via the CLI (direct icm commands) or as an MCP server (icm serve). Both access the same database.

    FeatureCLIMCP
    Latency~30ms (direct binary)~50ms (JSON-RPC stdio)
    Token Cost0 (via hooks, invisible)~20-50 tokens/call (tool schema)
    Configurationicm init --mode hookicm init --mode mcp
    CompatibilityClaude Code, Gemini, Codex, Copilot, OpenCode (via hooks)17 MCP-compatible tools
    Auto-extractionYes (hooks trigger icm extract)Yes (MCP tools call store)
    Best ForAdvanced users, saving tokensUniversal compatibility
  9. Understand ICM data privacy and storage

    main

    ICM is designed with local-first privacy.

    • Local Storage: All memories are stored in a local SQLite database on your machine.
    • No Telemetry Transmission: While ICM records "hook telemetry" (viewable via icm hook-log or icm hook-stats), this data stays in your local database and is never transmitted to the authors.
    • External Providers: If you configure an embedding provider or an LLM CLI, ICM contacts those services using your own credentials. You are responsible for reviewing and complying with the terms of service of those third-party providers.
    • Responsibility: You are responsible for managing the confidentiality and performing backups of your local store.
  10. Compare ICM with alternatives

    main

    ICM is designed for multi-agent environments with high recall accuracy (98%) and zero-dependency local-first storage. Key differentiators include:

    • Tool Support: Supports 17 tools (e.g., Claude Code, Copilot, Cursor, Windsurf, Zed, Amp) with one-command setup via icm init.
    • Hybrid Search: Combines FTS5 and Vector search with a 30/70 weighting.
    • Automatic Extraction: Uses a 3-layer, zero-LLM approach to extract information from tool outputs.
    • Hooks: Provides automatic recall at startup for 5 supported tools.
    • Runtime: A single Rust binary using SQLite for local-first, zero-dependency operation.
    • Features: Includes a TUI dashboard (icm dashboard), multi-language embeddings (100+ languages), and a feedback/correction loop (icm_feedback_*).
  11. How ICM's dual memory model works

    main

    ICM uses two distinct memory models to manage information:

    Episodic Memory (Topics)

    Captures decisions, errors, and preferences. Memories have a weight that decays over time based on their importance level:

    ImportanceDecay RatePruningBehavior
    criticalNoneNeverNever forgotten or pruned
    highSlow (0.5x)NeverFades slowly, never automatically deleted
    mediumNormalYesStandard decay; pruned when weight falls below threshold
    lowFast (2x)YesForgotten quickly

    Decay is access-aware: Frequently recalled memories decay slower (formula: decay / (1 + access_count * 0.1)). Decay is applied automatically if more than 24 hours have passed since the last decay event.

    Memory Health Features:

    • Auto-deduplication: Updates existing memories if new content has >85% similarity to an existing topic.
    • Consolidation Prompts: icm_memory_store prompts the caller to consolidate when a topic exceeds 7 records.
    • Health Audits: icm_memory_health reports entry counts, average weights, stale entries, and consolidation needs.
    • No Silent Data Loss: critical and high importance memories are never automatically pruned.

    Semantic Memory (Memoirs)

  12. How hybrid search and embeddings work

    main

    When embeddings are enabled, ICM uses a hybrid search approach combining keyword matching and semantic similarity:

    • FTS5 BM25 (30%): Full-text keyword matching.
    • Cosine Similarity (70%): Semantic vector search via sqlite-vec.

    The default model is intfloat/multilingual-e5-base (768d). Changing the model in the configuration will automatically recreate the vector index (existing embeddings are cleared and can be regenerated using icm_memory_embed_all).

    [embeddings]
    model = "intfloat/multilingual-e5-base"