Cortex Memory

repository·main·Indexed 43 days ago

https://github.com/sopaco/cortex-mem

An AI-native memory framework built in Rust providing long-term, hierarchical memory for intelligent applications. It utilizes a hybrid storage approach combining a virtual filesystem and vector search via Qdrant to help AI agents remember and personalize interactions. The system includes a CLI for session management, semantic search, and memory layer (L0/L1) manipulation, as well as a core Rust library featuring the CortexMemBuilder and CortexFilesystem.

Tokens
113.4K
Snippets
315
Records
492
Agent score
54%

What's inside Cortex Memory

  1. What is Cortex Memory?

    main

    Cortex Memory (cortex-mem) is a full-stack AI memory management system designed to provide AI agents with persistent, multi-dimensional context across conversational sessions. It solves the problem of statelessness in AI by automatically capturing, structuring, and retrieving dialogue history using a hierarchical memory model.

    Hierarchical Memory Model

    The system organizes memory into three semantic layers:

    • L0 (Abstract): High-level summaries of conversation intent.
    • L1 (Overview): Structured markdown summaries containing key decisions, entities, and outcomes.
    • L2 (Detail): Raw, unprocessed conversation transcripts stored as markdown files.

    These layers are indexed via vector embeddings and stored in a Qdrant vector database, allowing for fast, context-aware semantic search. The system uses filesystem monitoring to automatically trigger LLM-based summarization and synchronization between the filesystem and the vector store.

  2. Explore Cortex Memory Features & Capabilities

    main

    Cortex Memory provides a comprehensive suite of features for building intelligent agents:

    • File-System Based Storage: Uses the cortex:// URI scheme for markdown-based storage.
    • Intelligent Memory Extraction: Uses LLMs to extract structured facts, decisions, and entities with confidence scoring.
    • Vector-Based Semantic Search: High-performance similarity search via Qdrant with metadata filtering.
    • Multi-Modal Access: Support for REST API, CLI, MCP protocol, and direct Rust library integration.
    • Three-Tier Memory Hierarchy: Progressive disclosure (L0/L1/L2) to optimize LLM context windows.
    • Session Management: Automatic indexing of conversation timelines and participants.
    • Multi-Tenancy: Isolated memory spaces for different users/agents via tenant-aware collection naming.
    • Event-Driven Automation: Background processing via file watchers and auto-indexers.
    • LLM Result Caching: Reduces API costs by 50-75% using LRU eviction and TTL.
    • Memory Forgetting Mechanism: MemoryCleanupService manages storage growth using the Ebbinghaus forgetting curve.
    • Integrations: Built-in support for the Rig framework and Model Context Protocol (MCP).
  3. Integrate Cortex Memory with the Rig AI Framework

    main
    The cortex-mem-rig package provides integration between Cortex Memory and the Rig AI framework. It enables AI agents built with Rig to access Cortex Memory's three-tier memory architecture through specialized tools. This integration allows agents to perform high-level memory operations (retrieval, storage, and insight generation) using the Rig tool-calling pattern.
  4. Core Features of Cortex Memory

    main

    Cortex Memory provides several advanced capabilities for AI application developers:

    • File-system based storage: Uses cortex:// URIs to store memory as Markdown files.
    • Intelligent Memory Extraction: Uses LLMs to automatically extract structured facts, decisions, and entities from conversations.
    • Vector-based Semantic Search: High-performance similarity search via Qdrant with metadata filtering and weighted scoring.
    • Multi-modal Access: Interact via REST API, CLI, MCP (Model Context Protocol), or direct Rust library integration.
    • Multi-tenant Support: Isolated memory spaces for different users/agents using tenant-aware collection naming.
    • Event-driven Automation: Background processing via file monitors and automatic indexers.
    • LLM Result Caching: Reduces redundant API calls by 50-75% using LRU eviction and TTL.
    • Incremental Updates: Automatically keeps L0/L1 layers synchronized when memory changes.
    • Memory Forgetting Mechanism: A MemoryCleanupService based on the Ebbinghaus forgetting curve to archive or delete low-intensity memories and prevent storage bloat.
    • Observability: A Svelte 5-based dashboard (Insights) for monitoring and visualizing semantic search.
  5. Understand the Cortex Memory technology stack

    main

    Cortex Memory is built using a layered architecture designed for memory safety, high performance, and modularity. Key technologies include:

    • Core Logic: Written in Rust using the cortex-mem-core crate for business logic.
    • Storage & Search: Uses Qdrant for high-performance vector search and a filesystem abstraction using the cortex:// URI scheme.
    • Interfaces:
      • HTTP Server: Built with Axum for type-safe web services.
      • MCP Server: Uses a custom stdio protocol for low-latency local agent integration.
      • Web UI: A reactive frontend built with Svelte and TypeScript.
      • CLI: Provided via cortex-mem-cli.
    • LLM Integration: Uses OpenAI-compatible HTTP APIs, allowing for both cloud and local models.
    • Configuration: Managed via TOML and Environment Variables.
  6. What is the Extraction Engine Domain?

    main

    The Extraction Engine Domain is a cognitive processing layer in Cortex-Mem that transforms unstructured conversational data into structured, queryable knowledge. It uses NLP pipelines to identify and categorize semantic artifacts such as events, personal info, activities, future plans, relationships, and facts from AI agent conversations.

    Key capabilities include:

    • Semantic Structuring: Converting dialogue into typed objects with metadata.
    • Temporal Awareness: Extracting dated events with timestamps.
    • Attribution Preservation: Maintaining provenance via source URI tracking.
    • Confidence Scoring: Filtering low-quality data using a configurable threshold (default: 0.6).
  7. Overview of Cortex Memory crates and components

    main

    The following crates define the functional surface of the ecosystem:

    • cortex-mem-core: The central engine. Handles cortex:// URI filesystem abstraction, LLM/embedding wrappers, Qdrant integration, session management, the three-tier memory hierarchy (L0/L1/L2), extraction, search, and the MemoryEventCoordinator for incremental updates.
    • cortex-mem-service: An Axum-based REST API server. Exposes all memory operations via /api/v2/* endpoints. Default port: 8085.
    • cortex-mem-cli: The cortex-mem binary for direct administrative and developer interaction with the memory store.
    • cortex-mem-insights: A Svelte 5 SPA for monitoring, analytics, and memory management via a web interface.
    • cortex-mem-mcp: A Model Context Protocol server for AI assistants like Claude Desktop or Cursor.
    • cortex-mem-rig: Integration layer for the rig-core agent framework.
    • cortex-mem-tools: Provides MCP tool schemas and operation wrappers.
    • cortex-mem-config: Manages TOML configuration, environment variables, and tenant overrides.
  8. Overview of the Automation Management Domain

    main

    The Automation Management Domain is a core component of Cortex-Mem that orchestrates background tasks to maintain consistency between filesystem-based memory storage and the Qdrant vector database. It uses an event-driven architecture to respond to data changes in real-time while using batching and throttling to optimize resource usage (like LLM API calls).

    Key Capabilities:

    • Automatic Indexing: Detects new/modified files and generates vector embeddings.
    • Intelligent Extraction: Extracts structured knowledge (facts, decisions, entities) from completed sessions to enrich profiles.
    • Synchronization: Ensures eventual consistency between the filesystem and vector store.
    • Layer Generation: Dynamically generates L0 (abstract) and L1 (overview) summaries from raw L2 (detail) content.
  9. Overview of Cortex-Mem Application Interfaces

    main

    Cortex-Mem provides a unified abstraction layer for memory management through four distinct interaction patterns. This domain uses the Adapter Pattern to wrap the central MemoryOperations service, ensuring consistent business logic, configuration, and multi-tenant isolation across all entry points.

    Available Interfaces:

    • CLI (cortex-mem-cli): Direct memory management via shell commands (Rust).
    • HTTP API (cortex-mem-service): RESTful endpoints for web and integration clients (Rust/Axum).
    • MCP Server (cortex-mem-mcp): AI assistant and IDE integration via Model Context Protocol over stdio (Rust/rmcp).
    • Web Dashboard (cortex-mem-insights): Visualization and management UI (TypeScript/Svelte).
  10. Overview of Cortex Memory core workflows

    main

    Cortex Memory (cortex-mem) manages AI agent memory through five primary operational workflows. These workflows are structured around a layered retrieval architecture (L0 Abstract, L1 Overview, L2 Detail) and combine vector-based semantic search with filesystem abstraction to ensure persistent, context-aware memory across sessions.

    The system's operational landscape is categorized into five workflows:

    1. System Initialization (Bootstrap): Occurs per-instance. Handles configuration loading, Dependency Injection (DI) container setup, and service wiring. This is a critical prerequisite for all other workflows.
    2. Semantic Memory Search (User-facing): Occurs per-query. Utilizes the vector engine, layer manager, and ranking systems to retrieve memory.
    3. Memory Indexing & Sync (Background): Event-driven. Uses file watchers, indexers, and vector stores to keep memory up to date.
    4. Memory Extraction & Profiling (Background): Occurs at session-close. Uses LLM extraction, profile merging, and deduplication to refine memory.
    5. Multi-Tenant Request Handling (Cross-cutting): Occurs per-request. Manages tenant isolation, URI routing, and collection scoping.
  11. Overview of the Tool Support Domain

    main
    The Tool Support Domain acts as a bridge between AI assistant frameworks (like Claude or Cursor) and the Cortex-Mem memory system. It uses the Model Context Protocol (MCP) to expose core memory operations—such as storing, querying, and listing memories—as standardized, schema-validated tools. This allows any MCP-compliant agent to interact with Cortex-Mem without requiring custom adapters.
  12. How Intent Detection and Adaptive Thresholding work

    main

    The engine classifies queries into specific intent categories to adjust the L0 similarity threshold. This ensures higher recall for specific types of queries (like entity lookups) by lowering the required similarity score.

    Intent TypeCharacteristicsAdaptive L0 Threshold
    EntityLookup"Who is...", short names0.28
    Factual"What did X research", "What is X's job"0.32
    Search"Find...", "What activities", "What hobbies"0.35
    Temporal"When...", "Yesterday...", "What date"0.38
    Relational"Relationship status", "How is X related to Y"0.35
    GeneralOpen-ended questions0.45

    Note: EntityLookup uses the lowest threshold (0.28) to maximize candidate coverage even when summaries are sparse.