SimpleMem Documentation

repository·main·Indexed 25 days ago

https://github.com/aiming-lab/simplemem

An efficient lifelong memory system for LLM agents supporting text and multimodal data (image, audio, video). It features semantic lossless compression, automated backend selection, and self-evolving retrieval optimization via EvolveMem. The system includes CrossMemOrchestrator for persistent cross-conversation memory, a ConsolidationWorker for memory quality maintenance, and a Model Context Protocol (MCP) server for integration with LLM clients like Claude or Cursor.

Tokens
29.6K
Snippets
83
Records
175
Agent score
86%

What's inside SimpleMem

  1. Overview of SimpleMem Architecture Components

    main

    SimpleMem is composed of four functional layers:

    1. API Layer (OpenRouter): Acts as a unified gateway for all LLM and embedding calls, providing multi-provider access and cost tracking.
    2. Storage Layer (LanceDB): A vector database that stores dialogue entries and their semantic embeddings.
    3. Retrieval Layer (Hybrid Retriever): Combines semantic (vector) search and keyword (BM25) search. The number of retrieved entries is controlled via a configurable top-k parameter.
    4. Generation Layer (Answer Generator): Uses retrieved context to generate natural language answers. It supports an optional Reflection Mode for multi-step reasoning on complex queries.
  2. Understand SimpleMem Architecture

    main
    SimpleMem is a persistent conversational memory system designed for LLM agents. It stores dialogues in a LanceDB vector database to enable semantic retrieval and question answering. The system uses OpenRouter as a unified API gateway for both Large Language Models (LLMs) and embedding services, allowing access to multiple providers (Anthropic, OpenAI, Google, etc.) using a single API key.
  3. Offline Capabilities and API Key Requirements

    main

    The following tools run fully offline and do not require an API key:

    • omni_add_text
    • omni_add_document
    • omni_stats
    • omni_list_events
    • omni_list_namespaces
    • omni_consolidate
    • omni_delete_namespace

    Tools requiring an LLM (and thus an OPENAI_API_KEY) include image/audio/video captioning, omni_query, and omni_answer.

  4. Understand SimpleMem Text Memory architecture

    main

    SimpleMem's text backend converts raw dialogue into compact, retrievable memory units using three core mechanisms:

    1. Semantic Structured Compression: Filters redundant content and reformulates dialogue into atomic, self-contained facts with absolute timestamps and resolved coreferences.
    2. Online Semantic Synthesis: Performs on-the-fly synthesis during the write phase. It consolidates related memory fragments into higher-level abstract representations immediately to prevent redundancy.
    3. Intent-Aware Retrieval Planning: Uses an LLM to generate a retrieval plan based on latent search intent, executing parallel multi-view retrieval across semantic, lexical, and symbolic indexes.
  5. Run Omni-SimpleMem as a REST API Server

    main

    You can expose the memory system via a FastAPI REST server. Ensure you have the [server] dependency installed and your OPENAI_API_KEY set.

    pip install -e ".[server]"
    export OPENAI_API_KEY=your_key_here
    python examples/api_server.py

    Once running, the interactive documentation is available at http://localhost:8000/docs.

    pip install -e ".[server]"
    export OPENAI_API_KEY=your_key_here
    python examples/api_server.py
  6. Run the CrossMem HTTP Server

    main

    You can run the memory system as a standalone HTTP service using uvicorn or mount it onto an existing FastAPI application.

    # Option 1: Create a standalone app
    from cross.api_http import create_app
    app = create_app(project="my-project")
    
    # Run via CLI:
    # uvicorn cross.api_http:app --host 0.0.0.0 --port 8000
    
    # Option 2: Mount on an existing FastAPI app
    from fastapi import FastAPI
    from cross.api_http import create_cross_router
    from cross.orchestrator import create_orchestrator
    
    app = FastAPI()
    orch = create_orchestrator(project="my-project")
    router = create_cross_router(orch)
    app.include_router(router, prefix="/cross")
  7. Install and Setup the SimpleMem Skill

    main

    To use the simplemem-skill, install the required dependencies and configure your OpenRouter API key.

    1. Install dependencies: Navigate to the skill directory and install requirements via pip.
    2. Configure OpenRouter: Copy the example configuration file to src/config.py and set your OPENROUTER_API_KEY.
    3. Data Storage: Memories are automatically stored in the data/lancedb/ directory.
    # Install dependencies
    cd ~/.claude/skills/simplemem-skill
    pip install -r requirements.txt
    
    # Configure OpenRouter API
    cp src/config.py.example src/config.py
    # Edit src/config.py and set your OPENROUTER_API_KEY
  8. Set up OpenRouter integration for simplemem-skill

    main

    To use OpenRouter as the unified API gateway for LLM and embedding operations in simplemem-skill, follow these steps:

    1. Get an API Key: Create an account at openrouter.ai/keys. Your key will start with sk-or-.
    2. Initialize Configuration: Navigate to the skill directory and copy the example configuration file to the active config file:
      cd SKILL/simplemem-skill
      cp src/config.py.example src/config.py
    3. Configure Credentials: Open src/config.py and set your OPENROUTER_API_KEY.
    cd SKILL/simplemem-skill
    cp src/config.py.example src/config.py
  9. Configure an MCP Client for SimpleMem

    main

    To use SimpleMem with MCP-compatible clients (like Claude or Cursor), add the server configuration to your MCP JSON settings file. Replace YOUR_TOKEN with the authentication token obtained from the cloud service or your self-hosted instance.

    {
      "mcpServers": {
        "simplemem": {
          "url": "https://mcp.simplemem.cloud/mcp",
          "headers": {
            "Authorization": "Bearer YOUR_TOKEN"
          }
        }
      }
    }