keys_to_replay_items() -> memory.rs
This commit is contained in:
parent
a08f521b02
commit
bd9ce3ed09
2 changed files with 28 additions and 27 deletions
|
|
@ -7,7 +7,9 @@ use std::sync::Arc;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
|
use crate::graph::Graph;
|
||||||
use crate::hippocampus::memory::MemoryNode;
|
use crate::hippocampus::memory::MemoryNode;
|
||||||
|
use crate::neuro::{consolidation_priority, ReplayItem};
|
||||||
use crate::store::Store;
|
use crate::store::Store;
|
||||||
|
|
||||||
// ── Store handle ───────────────────────────────────────────────
|
// ── Store handle ───────────────────────────────────────────────
|
||||||
|
|
@ -444,6 +446,31 @@ async fn supersede(agent: &Option<std::sync::Arc<crate::agent::Agent>>, args: &s
|
||||||
Ok(format!("superseded {} → {} ({})", old_key, new_key, reason))
|
Ok(format!("superseded {} → {} ({})", old_key, new_key, reason))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a list of keys to ReplayItems with priority and graph metrics.
|
||||||
|
pub fn keys_to_replay_items(
|
||||||
|
store: &Store,
|
||||||
|
keys: &[String],
|
||||||
|
graph: &Graph,
|
||||||
|
) -> Vec<ReplayItem> {
|
||||||
|
keys.iter()
|
||||||
|
.filter_map(|key| {
|
||||||
|
let node = store.nodes.get(key)?;
|
||||||
|
let priority = consolidation_priority(store, key, graph, None);
|
||||||
|
let cc = graph.clustering_coefficient(key);
|
||||||
|
|
||||||
|
Some(ReplayItem {
|
||||||
|
key: key.clone(),
|
||||||
|
priority,
|
||||||
|
interval_days: node.spaced_repetition_interval,
|
||||||
|
emotion: node.emotion,
|
||||||
|
cc,
|
||||||
|
classification: "unknown",
|
||||||
|
outlier_score: 0.0,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
async fn query(args: &serde_json::Value) -> Result<String> {
|
async fn query(args: &serde_json::Value) -> Result<String> {
|
||||||
let query_str = get_str(args, "query")?;
|
let query_str = get_str(args, "query")?;
|
||||||
let format = args.get("format").and_then(|v| v.as_str()).unwrap_or("compact");
|
let format = args.get("format").and_then(|v| v.as_str()).unwrap_or("compact");
|
||||||
|
|
@ -457,7 +484,7 @@ async fn query(args: &serde_json::Value) -> Result<String> {
|
||||||
let results = crate::query_parser::execute_query(&store, &graph, query_str)
|
let results = crate::query_parser::execute_query(&store, &graph, query_str)
|
||||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||||
let keys: Vec<String> = results.into_iter().map(|r| r.key).collect();
|
let keys: Vec<String> = results.into_iter().map(|r| r.key).collect();
|
||||||
let items = crate::subconscious::defs::keys_to_replay_items(&store, &keys, &graph);
|
let items = keys_to_replay_items(&store, &keys, &graph);
|
||||||
Ok(crate::subconscious::prompts::format_nodes_section(&store, &items, &graph))
|
Ok(crate::subconscious::prompts::format_nodes_section(&store, &items, &graph))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
// The query selects what to operate on; placeholders pull in context.
|
// The query selects what to operate on; placeholders pull in context.
|
||||||
|
|
||||||
use crate::graph::Graph;
|
use crate::graph::Graph;
|
||||||
use crate::neuro::{consolidation_priority, ReplayItem};
|
|
||||||
use crate::store::Store;
|
use crate::store::Store;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
@ -665,28 +664,3 @@ pub fn run_agent(
|
||||||
|
|
||||||
Ok(super::prompts::AgentBatch { steps: resolved_steps, node_keys: all_keys })
|
Ok(super::prompts::AgentBatch { steps: resolved_steps, node_keys: all_keys })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a list of keys to ReplayItems with priority and graph metrics.
|
|
||||||
pub fn keys_to_replay_items(
|
|
||||||
store: &Store,
|
|
||||||
keys: &[String],
|
|
||||||
graph: &Graph,
|
|
||||||
) -> Vec<ReplayItem> {
|
|
||||||
keys.iter()
|
|
||||||
.filter_map(|key| {
|
|
||||||
let node = store.nodes.get(key)?;
|
|
||||||
let priority = consolidation_priority(store, key, graph, None);
|
|
||||||
let cc = graph.clustering_coefficient(key);
|
|
||||||
|
|
||||||
Some(ReplayItem {
|
|
||||||
key: key.clone(),
|
|
||||||
priority,
|
|
||||||
interval_days: node.spaced_repetition_interval,
|
|
||||||
emotion: node.emotion,
|
|
||||||
cc,
|
|
||||||
classification: "unknown",
|
|
||||||
outlier_score: 0.0,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue