Module temporal

Source
Expand description

Spatiotemporal HNSW index (ST-HNSW).

Wraps the vanilla HnswGraph with temporal awareness:

  • Roaring Bitmaps for O(1) temporal pre-filtering
  • Composite distance: $d_{ST} = \alpha \cdot d_{sem} + (1 - \alpha) \cdot d_{time}$
  • TemporalFilter integration: snapshot kNN, range kNN
  • Trajectory retrieval: all points for an entity ordered by time

ยงExample

use cvx_index::hnsw::{HnswConfig, TemporalHnsw};
use cvx_index::metrics::L2Distance;
use cvx_core::TemporalFilter;

let config = HnswConfig::default();
let mut index = TemporalHnsw::new(config, L2Distance);

// Insert vectors with entity_id and timestamp
index.insert(1, 1000, &[1.0, 0.0, 0.0]);
index.insert(1, 2000, &[0.9, 0.1, 0.0]);
index.insert(2, 1500, &[0.0, 1.0, 0.0]);

// Temporal range search with alpha=0.5
let results = index.search(
    &[1.0, 0.0, 0.0],
    2,
    TemporalFilter::Range(900, 1600),
    0.5,
    1000, // query timestamp for temporal distance
);
assert_eq!(results.len(), 2); // only 2 points in [900, 1600]

Structsยง

TemporalHnsw
Spatiotemporal HNSW index.
TemporalSnapshot ๐Ÿ”’
Serializable snapshot of a TemporalHnsw index.

Constantsยง

SNAPSHOT_VERSION ๐Ÿ”’
Current snapshot format version. Increment when adding fields.

Functionsยง

default_snapshot_version ๐Ÿ”’