Skip to main content

hippmem_core/
ids.rs

1//! Core ID and key types (ADR-006/007, corresponds to 02#0).
2//!
3//! Contains MemoryId, VectorId, and key type aliases for each dimension.
4
5use serde::{Deserialize, Serialize};
6
7/// Unique memory ID. Generated as a ULID, carried as u128. Lexicographic order = approximate time order. See ADR-006.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
9pub struct MemoryId(pub u128);
10
11impl MemoryId {
12    /// Generates a new MemoryId (ULID).
13    /// Determinism: the time and random parts come from an injectable Clock/Rng; here the system default impl is used.
14    pub fn generate() -> Self {
15        let ulid = ulid::Ulid::new();
16        Self(ulid.into())
17    }
18
19    /// Extracts the inner u128 value.
20    pub fn as_u128(&self) -> u128 {
21        self.0
22    }
23}
24
25/// Reference handle of a dense vector within the semantic_index (not the vector itself).
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
27pub struct VectorId(pub u128);
28
29impl VectorId {
30    /// Extracts the inner u128 value.
31    pub fn as_u128(&self) -> u128 {
32        self.0
33    }
34}
35
36// ── Key type aliases ──
37
38/// Entity key: the canonical entity name hashed to u64 (xxh3, fixed seed 0, ADR-019).
39pub type EntityKey = u64;
40
41/// Topic key: the topic text hashed to u64.
42pub type TopicKey = u64;
43
44/// Goal key: the goal description hashed to u64.
45pub type GoalKey = u64;
46
47/// Event key: the event identifier hashed to u64.
48pub type EventKey = u64;
49
50/// Causal key: the causal claim hashed to u64.
51pub type CausalKey = u64;
52
53/// Emotion key: emotion category enum → u8.
54pub type EmotionKey = u8;
55
56/// Temporal key: time bucket → u32.
57pub type TemporalKey = u32;