docs.rs failed to build cortex-mem-core-2.7.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Cortex Memory Core Library
cortex-mem-core is the foundational library of the Cortex Memory system, providing core services and abstractions for AI agent memory management.
๐ง Overview
Cortex Memory Core implements:
- A virtual filesystem with
cortex://URI scheme for memory storage - Three-tier memory architecture (L0/L1/L2 layers)
- Session-based conversational memory management
- Vector search integration with Qdrant
- LLM-based memory extraction and profiling
- Event-driven automation system
- Incremental memory update system with event coordination, cascade layer updates, and LLM result caching
- Memory forgetting mechanism based on the Ebbinghaus forgetting curve
๐๏ธ Architecture
Core Modules
| Module | Purpose | Key Components |
|---|---|---|
filesystem |
Virtual file system with custom URI scheme | CortexFilesystem, CortexUri, FilesystemOperations |
session |
Conversational session management | SessionManager, Message, TimelineGenerator, ParticipantManager |
vector_store |
Vector database abstraction | VectorStore trait, QdrantVectorStore |
search |
Semantic and layered search engines | VectorSearchEngine, SearchOptions, SearchResult |
extraction |
Memory extraction and profiling | MemoryExtractor, ExtractedMemories |
automation |
Event-driven automation | AutomationManager, AutoIndexer, AutoExtractor, LayerGenerator |
layers |
Three-tier memory architecture | LayerManager, ContextLayer |
llm |
Large language model abstraction | LLMClient trait, LLMClientImpl |
embedding |
Embedding generation | EmbeddingClient, EmbeddingCache |
events |
Event system for automation | CortexEvent, EventBus |
builder |
Unified initialization API | CortexMemBuilder, CortexMem |
memory_index |
Memory index and version tracking | MemoryIndex, MemoryMetadata, MemoryScope, MemoryType |
memory_events |
Memory change event types | MemoryEvent, ChangeType, DeleteReason |
memory_index_manager |
Persistent index management | MemoryIndexManager |
incremental_memory_updater |
Incremental diff-based updates | IncrementalMemoryUpdater |
cascade_layer_updater |
Cascading L0/L1 layer updates | CascadeLayerUpdater, UpdateStats |
cascade_layer_debouncer |
Batch debouncing for layer updates | LayerUpdateDebouncer, DebouncerConfig |
llm_result_cache |
LRU+TTL cache for LLM results | LlmResultCache, CacheConfig, CacheStats |
vector_sync_manager |
Vector store sync coordination | VectorSyncManager, VectorSyncStats |
memory_event_coordinator |
Central event orchestration hub | MemoryEventCoordinator, CoordinatorConfig |
memory_cleanup |
Forgetting mechanism | MemoryCleanupService, MemoryCleanupConfig, CleanupStats |
๐ Quick Start
Using CortexMemBuilder (Recommended)
use ;
use Arc;
async
Basic Filesystem Usage
use ;
use Arc;
async
Session Management
use ;
use Arc;
async
Vector Search
use ;
use Arc;
async
๐ The Cortex Filesystem
The Cortex Filesystem extends standard file operations with custom URIs:
URI Scheme
cortex://{dimension}/{category}/{subcategory}/{resource}
Dimensions and Categories
| Dimension | Categories | Description |
|---|---|---|
session |
{session-id}/timeline |
Conversational sessions with timeline |
user |
preferences, entities, events |
User-specific memories |
agent |
cases, skills, instructions |
Agent-specific memories |
resources |
Various | Shared resources |
Example URIs
cortex://session/tech-support/timeline/2024/01/15/14_30_00_abc123.md
cortex://user/john/preferences.md
cortex://agent/assistant/skills/rust-programming.md
cortex://resources/templates/meeting-notes.md
๐ Memory Architecture (Three-Tier System)
Cortex implements a three-tier memory system:
| Layer | Size | Purpose | File Suffix |
|---|---|---|---|
| L0 Abstract | ~100 tokens | Ultra-condensed summaries, quick relevance check | .abstract.md |
| L1 Overview | ~500-2000 tokens | Detailed summaries, key points and decisions | .overview.md |
| L2 Detail | Full content | Complete original content, source of truth | .md (original) |
Layer Generation
use LayerManager;
let layer_manager = new;
// Generate all layers for content
let layers = layer_manager.generate_all_layers.await?;
// Load specific layer
let abstract_content = layer_manager.load.await?;
๐ API Reference
Core Types
// Dimension enum
// Context layers
// Memory types
// User memory categories
// Agent memory categories
// File entry
// Memory with embedding
// Search result
FilesystemOperations Trait
VectorStore Trait
LLMClient Trait
๐ง Configuration
QdrantConfig
EmbeddingConfig
LLMConfig
SessionConfig
AutomationConfig
๐ Event System
Cortex includes an event-driven automation system:
use ;
// Create event bus
let = new;
// Publish events
event_tx.publish;
// Handle events in automation manager
match event
Event Types
โก Incremental Update System
Introduced an event-driven incremental update pipeline that keeps memory layers in sync efficiently:
MemoryEventCoordinator: Central hub that receivesMemoryEvents (create/update/delete) and orchestrates downstream processing.IncrementalMemoryUpdater: Computes content diffs to only re-process changed memories, skipping unchanged content.CascadeLayerUpdater: When a memory changes, cascades L0/L1 layer updates up the directory tree. Uses content hash check (Phase 1) and LLM result cache (Phase 3) to minimize redundant work.LayerUpdateDebouncer: Batches rapid successive updates to the same directory (Phase 2), reducing LLM calls by 70-90%.LlmResultCache: LRU + TTL cache for generated L0/L1 content. Reduces LLM API costs by 50-75% for repeated content.VectorSyncManager: Keeps the Qdrant vector store synchronized with filesystem changes.
๐งน Memory Cleanup (Forgetting Mechanism)
The MemoryCleanupService which implements the Ebbinghaus forgetting curve:
- Periodically scans the memory index and calculates memory strength based on recency and access frequency.
- Memories with strength below
archive_threshold(default: 0.1) are archived (marked but not deleted). - Archived memories with strength below
delete_threshold(default: 0.02) are permanently deleted. - Prevents unbounded storage growth in long-running AI agents.
use ;
let svc = new;
let stats = svc.run_cleanup.await?;
println!;
๐ Integration with Other Crates
cortex-mem-config: Configuration loading and managementcortex-mem-tools: High-level utilities and MCP tool definitionscortex-mem-rig: Rig framework adapterscortex-mem-service: REST API implementationcortex-mem-cli: Command-line interfacecortex-mem-mcp: MCP server implementationcortex-mem-insights: Observability dashboard
๐งช Testing
Running tests requires all features:
๐ฆ Dependencies
Key dependencies include:
serde/serde_jsonfor serializationtokiofor async runtimeqdrant-clientfor vector storagerig-corefor LLM integrationchronofor timestampsuuidfor unique identifiersregexfor text matchingsha2for hashingtracingfor loggingreqwestfor HTTP requests
๐ License
MIT License - see the LICENSE file for details.
๐ค Contributing
Please read our contributing guidelines and submit pull requests to the main repository.