Replace rkyv/bincode caching with redb indices
Remove three-tier loading (rkyv snapshot, bincode cache, capnp replay)
in favor of direct capnp log replay + redb for indexed access.
- Remove all rkyv derives from types (Node, Relation, enums, etc.)
- Remove Snapshot struct, RKYV_MAGIC, CACHE_MAGIC constants
- Remove load_snapshot_mmap(), save(), save_snapshot()
- Remove MmapView, AnyView from view.rs (keep StoreView trait)
- Simplify Store::load() to just replay capnp logs
- Add db.rs with redb schema: nodes, uuid_to_key, visits, transcript_progress
- Simplify cmd_fsck to just check capnp integrity + graph health
capnp logs remain source of truth; redb indices will be rebuilt on demand.
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
2026-04-13 18:30:58 -04:00
|
|
|
// Read-only access abstraction for the memory store
|
2026-03-03 12:56:15 -05:00
|
|
|
|
|
|
|
|
use super::types::*;
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// StoreView: read-only access trait for search and graph code.
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
pub trait StoreView {
|
|
|
|
|
/// Iterate all nodes. Callback receives (key, content, weight).
|
|
|
|
|
fn for_each_node<F: FnMut(&str, &str, f32)>(&self, f: F);
|
|
|
|
|
|
2026-03-14 02:40:00 -04:00
|
|
|
/// Iterate all nodes with metadata. Callback receives (key, node_type, timestamp).
|
|
|
|
|
fn for_each_node_meta<F: FnMut(&str, NodeType, i64)>(&self, f: F);
|
|
|
|
|
|
2026-03-03 12:56:15 -05:00
|
|
|
/// Iterate all relations. Callback receives (source_key, target_key, strength, rel_type).
|
|
|
|
|
fn for_each_relation<F: FnMut(&str, &str, f32, RelationType)>(&self, f: F);
|
|
|
|
|
|
|
|
|
|
/// Node weight by key, or the default weight if missing.
|
|
|
|
|
fn node_weight(&self, key: &str) -> f64;
|
|
|
|
|
|
|
|
|
|
/// Node content by key.
|
|
|
|
|
fn node_content(&self, key: &str) -> Option<&str>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl StoreView for Store {
|
|
|
|
|
fn for_each_node<F: FnMut(&str, &str, f32)>(&self, mut f: F) {
|
|
|
|
|
for (key, node) in &self.nodes {
|
|
|
|
|
f(key, &node.content, node.weight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-14 02:40:00 -04:00
|
|
|
fn for_each_node_meta<F: FnMut(&str, NodeType, i64)>(&self, mut f: F) {
|
|
|
|
|
for (key, node) in &self.nodes {
|
|
|
|
|
f(key, node.node_type, node.timestamp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 12:56:15 -05:00
|
|
|
fn for_each_relation<F: FnMut(&str, &str, f32, RelationType)>(&self, mut f: F) {
|
|
|
|
|
for rel in &self.relations {
|
|
|
|
|
if rel.deleted { continue; }
|
|
|
|
|
f(&rel.source_key, &rel.target_key, rel.strength, rel.rel_type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn node_weight(&self, key: &str) -> f64 {
|
2026-04-13 18:50:21 -04:00
|
|
|
let cfg = crate::config::get();
|
|
|
|
|
self.nodes.get(key).map(|n| n.weight as f64).unwrap_or(cfg.default_node_weight)
|
2026-03-03 12:56:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn node_content(&self, key: &str) -> Option<&str> {
|
|
|
|
|
self.nodes.get(key).map(|n| n.content.as_str())
|
|
|
|
|
}
|
|
|
|
|
}
|