OpenMemory Documentation

repository·main·Indexed 26 days ago

https://github.com/caviraoss/openmemory

A cognitive memory engine for LLMs and agents providing long-term, self-hosted, and explainable memory. It supports temporal reasoning, multi-sector memory (episodic, semantic, procedural, emotional, reflective), and decay/reinforcement mechanisms. The project includes a JavaScript library (openmemory-js), a Python SDK (openmemory-py), a VSCode extension for AI assistant context, and a management dashboard. It features integrations with OpenAI, LangChain, and the Model Context Protocol (MCP), as well as connectors for GitHub, Notion, and Google Drive.

Tokens
29.9K
Snippets
74
Records
212
Agent score
86%

What's inside OpenMemory

  1. Overview of OpenMemory Architecture

    main
    OpenMemory is a self-hosted AI memory engine that implements the Hierarchical Memory Decomposition (HMD) v2 architecture. It is designed to provide persistent, structured, and semantic memory for LLM applications using multi-sector embeddings and single-waypoint graph linking.
  2. Understand OpenMemory's Architectural Differences

    main

    Unlike standard Vector Databases that store flat embeddings and rely solely on cosine similarity, OpenMemory uses a multi-sector cognitive engine (HMD v2).

    Key architectural features include:

    • Memory Sectors: Information is categorized into episodic, semantic, procedural, emotional, and reflective sectors.
    • Single-Waypoint Graph: Automatically creates a single, strongest connection between related memories to enable explainable recall.
    • Composite Similarity: Retrieval uses both similarity and activation spreading across sectors.
    • Temporal Awareness: Built-in recency and salience scoring for memory decay and reinforcement.
    • Local-First: Uses SQLite and FAISS/Chroma locally, making it highly efficient and private.
  3. Understand Temporal Graph capabilities

    main

    OpenMemory treats time as a first-class citizen via a Temporal Graph. It tracks the following metadata to enable time-based querying:

    • Creation Time: When the memory was first recorded.
    • Last Access: The last time the memory was retrieved (used to calculate decay).
    • Sequence: The causal chain of events (e.g., Chat History).

    This enables temporal queries such as retrieving information from a specific timeframe or determining the sequence of events leading up to a specific interaction.

  4. Understand User Partitioning and Security

    main
    OpenMemory enforces strict data isolation through user partitioning. All memories are partitioned by a user_id. This ensures that in multi-user environments (such as SaaS applications), memory data from one user is never accessible to another.
  5. OpenMemory System Components and Data Flow

    main

    The OpenMemory system is organized into several layers and core components:

    Client Layer

    Users interact with OpenMemory via:

    • HTTP Clients
    • JavaScript SDK
    • Python SDK
    • LangGraph Apps

    Backend Services

    All client requests are handled by a REST API Server (TypeScript/Node) running on Port 8080.

    Core Engine Components

    • HSG Memory Engine: Handles classification, encoding, storage, querying, decay, and reinforcement of memories.
    • Embedding Processor: Supports multiple embedding providers including OpenAI, Gemini, AWS, Ollama, and Local/Synthetic models via a Batch API.
    • Ingestion Pipeline: Processes raw data through PDF parsing, DOCX parsing, URL scraping, and text chunking.

    Storage Layer

    • Database (SQLite): Stores memories, vectors, waypoints, and embed_logs.
    • Waypoint Graph: Manages single-waypoint auto-linking, reinforcement, and pruning.
  6. Understand OpenMemory's Memory Types

    main

    OpenMemory implements a cognitive architecture with three distinct memory types:

    1. Episodic Memory: Stores specific events and individual interactions.
    2. Semantic Memory: Stores generalized facts and knowledge extracted from episodic data.
    3. Procedural Memory: (Planned) Intended for storing "how-to" knowledge and tool usage instructions.
  7. Compare OpenMemory with Vector Databases (Chroma/Pinecone)

    main

    OpenMemory is designed as an agentic memory layer rather than a standard vector database. Unlike Chroma or Pinecone, OpenMemory provides built-in management for:

    • User separation: Keeping memories isolated between different users.
    • Temporal tracking: Managing the timeline of information.
    • Memory dynamics: Handling automated processes like memory decay and reinforcement.
  8. Understand OpenMemory Architecture

    main

    OpenMemory utilizes Hierarchical Memory Decomposition combined with a Temporal Graph.

    Key architectural components include:

    • Sector Classifier: Routes inputs into specific memory sectors (Episodic, Semantic, Procedural, Emotional, or Reflective).
    • Recall Engine: Performs retrieval using Vector Search, Waypoint Graphs, Composite Scoring, and a Decay Engine.
    • Temporal KG (Knowledge Graph): Manages Facts and Timelines.
    • Storage: Uses SQLite or Postgres to store memories, vectors, and waypoints.
    • Processes: Includes Embedding, Consolidation, and Reflection to refine memory and output recall traces.
  9. Understand OpenMemory's Hierarchical Storage Graph (HSG)

    main

    OpenMemory organizes data using a Hierarchical Storage Graph (HSG) rather than a flat vector index. This structure allows for domain-specific organization and relationship mapping:

    • Sectors: High-level domains used to categorize memory (e.g., Personal, Work, Code).
    • Nodes: Individual memory units.
    • Edges: Relationships between memories, which can be temporal, semantic, or based on explicit entities.
  10. Quickstart with OpenMemory Python SDK

    main

    Install the openmemory-py package to use OpenMemory locally with Python. The SDK is local-first and uses SQLite by default. Note that add, search, get, and delete are asynchronous methods and must be awaited in async contexts.

    pip install openmemory-py
    from openmemory.client import Memory
    
    mem = Memory()
    await mem.add("user prefers dark mode", user_id="u1")
    results = await mem.search("preferences", user_id="u1")
    await mem.delete("memory_id")
  11. Quickstart with OpenMemory Node/JavaScript SDK

    main

    Install openmemory-js for use in Node.js backends, CLIs, or local tools. The SDK is local-first and supports asynchronous operations.

    npm install openmemory-js
    import { Memory } from "openmemory-js"
    
    const mem = new Memory()
    await mem.add("user likes spicy food", { user_id: "u1" })
    const results = await mem.search("food?", { user_id: "u1" })
    await mem.delete("memory_id")