Expand description
Hierarchical indexing module for spatiotemporal episode organization.
This module provides efficient indexing structures for episode retrieval:
- Spatiotemporal Index: Time-based hierarchical index (year/month/day/hour)
- Hierarchical Index: Multi-level index combining domain, task type, and time
§Architecture
HierarchicalIndex
├── DomainLevelIndex (e.g., "web-api")
│ ├── TaskTypeLevelIndex (e.g., CodeGeneration)
│ │ └── SpatiotemporalIndex (time hierarchy)
│ └── TaskTypeLevelIndex (e.g., Debugging)
│ └── SpatiotemporalIndex
└── DomainLevelIndex (e.g., "data-processing")
└── ...§Performance
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Insert | O(log n) | O(1) amortized |
| Query | O(log n + k) | O(k) |
| Remove | O(log n) | O(1) |
Where n is total episodes and k is results count.
§Usage Examples
§Basic Spatiotemporal Index
use do_memory_core::indexing::{SpatiotemporalIndex, TimeBucket};
use do_memory_core::{Episode, TaskContext, TaskType};
let mut index = SpatiotemporalIndex::new();
// Insert episode
let episode = Episode::new(
"Test task".to_string(),
TaskContext::default(),
TaskType::CodeGeneration,
);
index.insert(&episode);
// Query by time range
let start = chrono::Utc::now() - chrono::Duration::hours(1);
let end = chrono::Utc::now();
let results = index.query_range(start, end, 100);
// Query by time bucket
let bucket = TimeBucket::Month { year: 2024, month: 3 };
let results = index.query_bucket(&bucket);§Hierarchical Index
use do_memory_core::indexing::{HierarchicalIndex, HierarchicalQuery};
use do_memory_core::{Episode, TaskContext, TaskType};
let mut index = HierarchicalIndex::new();
// Insert episode
let episode = Episode::new(
"Test task".to_string(),
TaskContext::default(),
TaskType::CodeGeneration,
);
index.insert(&episode);
// Query with filters
let query = HierarchicalQuery::new()
.with_domain("web-api")
.with_task_type(TaskType::CodeGeneration)
.with_limit(10);
let results = index.query(&query);Re-exports§
pub use hierarchical::HierarchicalIndex;pub use hierarchical::HierarchicalIndexStats;pub use hierarchical::HierarchicalQuery;pub use spatiotemporal::IndexStats;pub use spatiotemporal::QueryOptions;pub use spatiotemporal::SpatiotemporalIndex;pub use spatiotemporal::TimeBucket;
Modules§
- hierarchical
- Hierarchical index structure for spatiotemporal episode organization.
- spatiotemporal
- Spatiotemporal hierarchical indexing for episode queries.
Structs§
- Benchmark
Result - Benchmark result comparing indexed vs linear scan performance.
- Index
Metrics - Index metrics for monitoring and optimization.
- Query
Performance - Performance comparison between indexed and linear scan queries.
Traits§
- Indexable
Memory - Extension trait for integrating indexing with
SelfLearningMemory.