LTM-RAG

April 3, 2025 ยท View on GitHub

Long-Term Memory for Claude with RAG (Retrieval-Augmented Generation) using Weaviate.

This Model Context Protocol (MCP) server provides Claude with long-term memory capabilities by integrating with a Weaviate-based RAG system. It allows Claude to remember conversations across sessions and retrieve relevant information from past interactions.

Features

Memory Management

  • Memory Types: Supports different memory types (procedural, semantic, episodic)
  • Configurable Memory Settings:
    • Importance threshold for what to remember
    • Retention period for automatic forgetting
    • Memory strength boosting for frequently accessed information
  • Memory Operations:
    • Save conversations to long-term memory
    • Search across all memories semantically
    • Retrieve memories by type
    • Forget old or specific memories

External Knowledge Sources

  • Source Types:
    • File sources (individual files)
    • Directory sources (folders with multiple files)
    • Web sources (URLs to web pages)
  • Source Management:
    • Add, update, and remove knowledge sources
    • Enable/disable sources
    • Index sources into the memory system

Tools

  • store_message - Stores individual chat messages in temporary memory
  • save_chat - Saves the current chat to a file and optionally imports it into the RAG system
  • search_rag - Searches the RAG system for relevant information
  • get_memory_by_type - Retrieves memories of a specific type (procedural, semantic, episodic)
  • get_entity_info - Gets information about a specific entity from the memory system
  • get_memory_settings - Retrieves current memory configuration settings
  • update_memory_settings - Updates memory configuration (thresholds, retention, etc.)
  • forget_old_memories - Forgets memories older than the retention period
  • forget_memories - Forgets specific memories by ID
  • list_knowledge_sources - Lists all configured external knowledge sources
  • add_knowledge_source - Adds a new external knowledge source
  • update_knowledge_source - Updates an existing knowledge source
  • delete_knowledge_source - Removes a knowledge source
  • index_knowledge_source - Indexes a knowledge source into the memory system

Prompts

  • default - Default prompt that introduces the long-term memory capability
  • researcher - Researcher assistant with memory integration
  • knowledge-explorer - Specialized prompt for exploring external knowledge sources

Installation

Prerequisites

  1. Node.js (v18 or higher)
  2. Python 3.8+ with the Weaviate-Chat-RAG system installed
  3. Docker for running Weaviate

Setup

  1. Clone the repository:

    git clone [repository_url] /Users/lorenzo/_pythonScripts/LTM-RAG
    cd /Users/lorenzo/_pythonScripts/LTM-RAG
    
  2. Install dependencies:

    npm install
    
  3. Build the server:

    npm run build
    
  4. Create a symlink to the Claude MCP directory:

    mkdir -p ~/Library/Application\ Support/Claude/MCP/
    ln -s /Users/lorenzo/_pythonScripts/LTM-RAG ~/Library/Application\ Support/Claude/MCP/LTM-RAG
    
  5. Configure Claude Desktop to use the MCP server by editing: ~/Library/Application Support/Claude/claude_desktop_config.json

    Add the following configuration:

    {
      "mcpServers": {
        "ltm-rag": {
          "command": "node",
          "args": [
            "/Users/lorenzo/Library/Application Support/Claude/MCP/LTM-RAG/dist/index.js"
          ],
          "env": {}
        }
      }
    }
    
  6. Or use the provided installation script:

    ./install.sh
    

Usage

  1. Start Claude Desktop
  2. Click the paperclip icon, then the plug icon
  3. Select "default", "researcher", or "knowledge-explorer" under "ltm-rag"
  4. Chat with Claude normally

Basic Commands

  • "Save this conversation to your long-term memory" - Saves the current chat
  • "Search your memory for [query]" - Searches the RAG system
  • "What do you know about [entity]?" - Retrieves entity information
  • "What [memory type] memories do you have?" - Retrieves memories by type
  • "Show me your memory settings" - Displays current configuration
  • "Update your memory settings" - Changes memory configuration
  • "Forget memories older than your retention period" - Removes old memories
  • "List your knowledge sources" - Shows configured external sources
  • "Add a new knowledge source" - Sets up a new source
  • "Index knowledge source [name]" - Imports external content into memory

External Knowledge Source Integration

The system supports integrating with various external knowledge sources:

  1. Files:

    • PDF documents, text files, markdown files, etc.
    • Example: "Add a new knowledge source for my research paper at /path/to/paper.pdf"
  2. Directories:

    • Folders containing multiple related documents
    • Example: "Add a new knowledge source for my project documentation at /path/to/docs/"
  3. Web Pages:

The integration works by:

  1. Registering the source in the LTM-RAG configuration
  2. When indexed, the content is processed:
    • Extracted and broken into manageable chunks
    • Embedded using the same embedding model as chat memories
    • Stored in the Weaviate vector database with appropriate metadata
    • Made available for retrieval alongside conversation memories

Knowledge sources can be enabled/disabled and managed over time.

Future Enhancements Under Consideration

The following enhancements are being considered for future development:

  1. Scheduled Indexing:

    • Automatic re-indexing of sources on a schedule
    • Support for sources that change or update frequently
  2. Specialized Source Types:

    • GitHub repositories integration (code, documentation, issues)
    • Notion workspaces or other note-taking systems
    • SQL databases for structured data access
    • Email archives
    • Calendar data integration
  3. Authentication and Access Control:

    • Support for authenticated sources (API keys, OAuth)
    • Permissions and access controls for sensitive information
  4. Knowledge Source Processing Plugins:

    • Specialized processors for different file types
    • Custom extractors for domain-specific information
    • Custom classifiers for domain-specific memory types
  5. Active Learning for Source Relevance:

    • Track which sources provide useful information
    • Adjust source importance based on user feedback
    • Prioritize sources that consistently provide valuable information
  6. Knowledge Graph Building:

    • Automatically extract entities and relationships from sources
    • Build a knowledge graph connecting information across sources
    • Enable more sophisticated reasoning over the combined knowledge

Development

For development with auto-rebuild:

npm run watch

Debugging

Since MCP servers communicate over stdio, debugging can be challenging. You can add console.log statements that will appear in the Claude Desktop logs.

Configuration Files

The LTM-RAG system uses configuration files stored in ~/.ltm-rag/:

  • memory_settings.json - Contains memory configuration parameters
  • knowledge_sources.json - Lists configured external knowledge sources

License

MIT