docs.rs failed to build cortex-mem-tools-2.5.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 Tools Library
cortex-mem-tools provides high-level abstractions and utilities for working with the Cortex Memory system. It offers simplified APIs for common operations three tiered access (L0/L1/L2 layers).
๐ ๏ธ Overview
Cortex Memory Tools implements:
- High-level
MemoryOperationsinterface for unified access to Cortex Memory - Tiered Access: L0 (Abstract ~100 tokens), L1 (Overview ~2000 tokens), L2 (Full Content)
- Advanced automation with event-driven processing
- Model Context Protocol (MCP) tool definitions
- Type-safe error handling and comprehensive types
๐๏ธ Core Components
MemoryOperations
The primary interface for working with Cortex Memory:
MemoryOperations
|
+---> Tiered Access (L0/L1/L2)
| |
| +---> get_abstract() -> AbstractResponse
| +---> get_overview() -> OverviewResponse
| +---> get_read() -> ReadResponse
|
+---> Search Operations
| |
| +---> search() -> SearchResponse
| +---> find() -> FindResponse
|
+---> Filesystem Operations
| |
| +---> ls() -> LsResponse
| +---> explore() -> ExploreResponse
|
+---> Storage Operations
| |
| +---> store() -> StoreResponse
|
+---> Session Management
| |
| +---> add_message()
| +---> list_sessions()
| +---> get_session()
| +---> close_session()
|
+---> Automation
|
+---> ensure_all_layers()
+---> index_all_files()
๐ Quick Start
Installation
[]
= { = "../cortex-mem-tools" }
= { = "../cortex-mem-core" }
= { = "1", = ["full"] }
Basic Usage
use MemoryOperations;
use ;
use Arc;
async
Tiered Access
| Layer | Size | Purpose | Method |
|---|---|---|---|
| L0 Abstract | ~100 tokens | Quick relevance judgment | get_abstract() |
| L1 Overview | ~2000 tokens | Partial context understanding | get_overview() |
| L2 Full | Complete content | Deep analysis and processing | read_file() / get_read() |
Tool-Based Operations
use ;
// Search with typed args
let search_result = ops.search.await?;
for result in &search_result.results
// List directory with abstracts
let ls_result = ops.ls.await?;
for entry in &ls_result.entries
// Store with auto layer generation
let store_result = ops.store.await?;
println!;
๐ API Reference
MemoryOperations Constructor
Accessor Methods
| Method | Return Type | Description |
|---|---|---|
filesystem() |
&Arc<CortexFilesystem> |
Get underlying filesystem |
vector_engine() |
&Arc<VectorSearchEngine> |
Get vector search engine |
session_manager() |
&Arc<RwLock<SessionManager>> |
Get session manager |
auto_extractor() |
Option<&Arc<AutoExtractor>> |
Get auto extractor |
layer_generator() |
Option<&Arc<LayerGenerator>> |
Get layer generator |
auto_indexer() |
Option<&Arc<AutoIndexer>> |
Get auto indexer |
Session Management
| Method | Parameters | Description |
|---|---|---|
add_message() |
thread_id, role, content |
Add message to session |
list_sessions() |
- | List all sessions |
get_session() |
thread_id |
Get session info |
close_session() |
thread_id |
Close a session |
Tiered Access (L0/L1/L2)
| Method | Parameters | Returns |
|---|---|---|
get_abstract() |
uri: &str |
AbstractResponse |
get_overview() |
uri: &str |
OverviewResponse |
get_read() |
uri: &str |
ReadResponse |
File Operations
| Method | Parameters | Description |
|---|---|---|
read_file() |
uri |
Read file content |
list_files() |
uri |
List files in directory |
delete() |
uri |
Delete file/directory |
exists() |
uri |
Check existence |
Tool-Based Operations
| Method | Parameters | Returns |
|---|---|---|
search() |
SearchArgs |
SearchResponse |
find() |
FindArgs |
FindResponse |
ls() |
LsArgs |
LsResponse |
explore() |
ExploreArgs |
ExploreResponse |
store() |
StoreArgs |
StoreResponse |
Automation Methods
| Method | Return Type | Description |
|---|---|---|
ensure_all_layers() |
GenerationStats |
Generate missing L0/L1 layers |
index_all_files() |
SyncStats |
Index all files to vector DB |
๐ Type Definitions
Tiered Access Responses
Search Types
Filesystem Types
Storage Types
Session Info
๐ MCP Integration
The library provides tool definitions for Model Context Protocol:
use ;
// Get all available MCP tool definitions
let tools = get_mcp_tool_definitions;
for tool in &tools
// Get a specific tool definition
if let Some = get_mcp_tool_definition
Available MCP Tools
| Tool | Description | Required Params | Optional Params |
|---|---|---|---|
abstract |
Get L0 abstract | uri |
- |
overview |
Get L1 overview | uri |
- |
read |
Get L2 full content | uri |
- |
search |
Intelligent search | query |
recursive, return_layers, scope, limit |
find |
Quick search (L0 only) | query |
scope, limit |
ls |
List directory | uri |
recursive, include_abstracts |
explore |
Intelligent exploration | query |
start_uri, max_depth, return_layers |
store |
Store with auto layers | content, thread_id |
metadata, auto_generate_layers, scope, user_id, agent_id |
โ ๏ธ Error Handling
All operations return Result<T, ToolsError>:
pub type Result<T> = Result;
๐ฆ Dependencies
cortex-mem-core- Core library with all memory operationstokio- Async runtimeserde/serde_json- Serializationanyhow/thiserror- Error handlingtracing- Loggingchrono- Date/time handlinguuid- Unique identifiersasync-trait- Async trait support
๐งช Testing
# Run tests
# Run specific tests
๐ License
MIT License - see the LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add comprehensive tests
- Submit a pull request
๐ Related Crates
cortex-mem-core- Core librarycortex-mem-mcp- MCP server implementationcortex-mem-rig- Rig framework integrationcortex-mem-service- HTTP REST APIcortex-mem-cli- Command-line interface
Built with โค๏ธ using Rust