Incremental memory scoring with per-score persistence
score_memories_incremental now takes an async callback that fires after each memory is scored. The callback: - Writes the score to the conversation entry via set_score() - Persists to memory-scores.json immediately - Notifies the UI so the context screen updates live Scoring no longer batches — each score is visible and persisted as it completes. Does not touch the memory store. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
e213644514
commit
fd58386951
2 changed files with 28 additions and 20 deletions
|
|
@ -396,26 +396,28 @@ impl Mind {
|
|||
ag.memory_scoring_in_flight = true;
|
||||
(ag.context.clone(), ag.client_clone())
|
||||
};
|
||||
let result = learn::score_memories_incremental(
|
||||
let _result = learn::score_memories_incremental(
|
||||
&context, max_age as i64, response_window, &client, &agent,
|
||||
|key: String, score: f64| {
|
||||
let agent = agent.clone();
|
||||
let path = scores_path.clone();
|
||||
async move {
|
||||
let mut ag = agent.lock().await;
|
||||
for i in 0..ag.context.conversation.len() {
|
||||
if let ConversationEntry::Memory { key: k, .. } = &ag.context.conversation.entries()[i].entry {
|
||||
if *k == key {
|
||||
ag.context.conversation.set_score(i, Some(score));
|
||||
}
|
||||
}
|
||||
}
|
||||
save_memory_scores(&ag.context.conversation, &path);
|
||||
ag.changed.notify_one();
|
||||
}
|
||||
},
|
||||
).await;
|
||||
{
|
||||
let mut ag = agent.lock().await;
|
||||
ag.memory_scoring_in_flight = false;
|
||||
if let Ok(ref scores) = result {
|
||||
// Write scores onto Memory entries
|
||||
for (key, weight) in scores {
|
||||
for i in 0..ag.context.conversation.len() {
|
||||
if let ConversationEntry::Memory { key: k, .. } = &ag.context.conversation.entries()[i].entry {
|
||||
if k == key {
|
||||
ag.context.conversation.set_score(i, Some(*weight));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Persist all scores to disk
|
||||
save_memory_scores(&ag.context.conversation, &scores_path);
|
||||
}
|
||||
}
|
||||
let _ = bg_tx.send(BgEvent::ScoringDone);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue