hirn-core
⚠️ Experimental: This project is under active development. APIs, on-disk formats, and behaviour may change without notice. Not recommended for production use.
Core types, traits, configuration, and error definitions for the hirn cognitive memory database. This is the leaf crate — all other hirn crates depend on it, but it depends on none.
Key Types
| Type | Backing | Copy? | Description |
|---|---|---|---|
MemoryId |
ULID | Yes | 128-bit universally unique memory identifier |
Namespace |
interned u32 |
Yes | Column-level memory isolation (pre-interns "default", "shared") |
AgentId |
interned u32 |
Yes | Agent identity (pre-interns "system") |
Timestamp |
DateTime<Utc> |
Yes | UTC timestamp with chrono backing |
Layer |
enum | Yes | Memory tier: Working, Episodic, Semantic, Procedural |
EdgeRelation |
enum | Yes | Graph edge types with is_bidirectional() |
Configuration
HirnConfig — 40+ parameters controlling the entire cognitive pipeline:
let config = builder
.db_path
.embedding_dimensions
.rpe_fast_path_threshold
.quality_gate_threshold
.build?;
Builder validation at .build() enforces invariants (threshold ranges, template placeholders).
Traits
Embedder— Embeds text →Vec<f32>(sync + async)LlmProvider— LLM completion for consolidation, causal discoveryEntityExtractor— Named entity extraction from textMcfaAuditSink— Security audit reporting interface
Error Handling
HirnError — #[non_exhaustive] thiserror enum. All crates define their own error types with From impls into HirnError.
Utilities
WelfordStats— Welford's online algorithm for incremental mean/variance/z-scoreStringInterner— Lock-free global interning for Namespace and AgentIdtext_util— UTF-8-safe word boundary truncationtokenizer— Character-based token estimation