Expand description
§relay-memory
Tiered memory engine with semantic embeddings, FTS5 hybrid retrieval, and Weibull decay.
§Overview
relay-memory stores facts and retrieves them via hybrid search: full-text (FTS5) combined with semantic similarity (all-MiniLM-L6-v2 embeddings). Memories are organized in tiers (hot, warm, cold) and decay nightly using a Weibull distribution, promoting or demoting entries based on access patterns and confidence scores. Conflicts are detected via SHA-256 hashing of content, and embeddings can be backfilled from earlier versions.
§Usage
Add as a dependency:
[dependencies]
relay-memory = { path = "../relay-memory" }
relay-core = { path = "../relay-core" }Example:
use cortex_rs_memory::{MemoryStore, WriteOptions};
use cortex_rs_core::Db;
use std::path::Path;
fn main() -> anyhow::Result<()> {
let db = Db::open(Path::new("/Users/me/.cortex/memory.db"))?;
let store = MemoryStore::new(db);
// Write a memory
let memory = store.write(
"prefer named exports in TypeScript",
WriteOptions::default(),
)?;
// Recall by keyword + semantic match
let results = store.recall("exports", 5)?;
println!("Found {} memories", results.len());
// Get hot-tier context for session preamble
let hot = store.hot_context()?;
println!("Hot memories: {:?}", hot);
Ok(())
}§Public API
MemoryStore::new(db)- initialize the storeMemoryStore::write(content, opts)- save a new memoryMemoryStore::recall(query, limit)- hybrid FTS5 + semantic searchMemoryStore::hot_context()- fetch top hot-tier memoriesMemoryStore::pin(id)- mark a memory to bypass decayMemoryStore::decay_pass()- promote/demote tiers nightlyMemoryStore::backfill_embeddings(batch)- populate embeddings for old memoriesMemoryStore::open_conflicts()- fetch unresolved conflict pairsWriteOptions- builder for write behavior (pinned, confidence, etc)
§Dependencies
relay-core- types, database, configrusqlite- SQLite queriesfastembed- ONNX embedding model (all-MiniLM-L6-v2). Optional, gated behind theembeddingsfeature flag which is on by default. Disable with--no-default-featuresfor FTS5-only builds.sha2- hash-based conflict detectionchrono- timestamps
§Part of Relay
relay-memory is one of six MIT-licensed pillar crates. It can be used standalone in other projects that need tiered semantic memory with decay. Relay also includes relay-core (schema and types), relay-notes (wikilinks), relay-router (task classification), relay-stats (cost tracking), and relay-miner (pattern mining). The three architecture crates (relay-mcp, relay-daemon, relay-cli) compose all pillars into the MCP server.
See the workspace README and LICENSING.md for details.
§License
MIT. See LICENSE.