Skip to main content

Module indexing

Module indexing 

Source
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

OperationTime ComplexitySpace Complexity
InsertO(log n)O(1) amortized
QueryO(log n + k)O(k)
RemoveO(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§

BenchmarkResult
Benchmark result comparing indexed vs linear scan performance.
IndexMetrics
Index metrics for monitoring and optimization.
QueryPerformance
Performance comparison between indexed and linear scan queries.

Traits§

IndexableMemory
Extension trait for integrating indexing with SelfLearningMemory.