Fix: only evict scored memories, not unscored

lowest_scored_memory() now skips memories with score=None. Unscored
memories haven't been evaluated — dropping them before scored
low-value ones loses potentially important context.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 21:06:45 -04:00
parent a20f3e3642
commit e213644514

View file

@ -223,12 +223,11 @@ fn trim_entries(entries: &[ContextEntry], fixed_tokens: usize) -> Vec<ContextEnt
fn lowest_scored_memory(entries: &[ContextEntry]) -> Option<usize> { fn lowest_scored_memory(entries: &[ContextEntry]) -> Option<usize> {
entries.iter().enumerate() entries.iter().enumerate()
.filter(|(_, e)| e.entry.is_memory()) .filter_map(|(i, e)| match &e.entry {
.min_by(|(_, a), (_, b)| { ConversationEntry::Memory { score: Some(s), .. } => Some((i, *s)),
let sa = match &a.entry { ConversationEntry::Memory { score, .. } => score.unwrap_or(0.0), _ => 0.0 }; _ => None,
let sb = match &b.entry { ConversationEntry::Memory { score, .. } => score.unwrap_or(0.0), _ => 0.0 };
sa.partial_cmp(&sb).unwrap_or(std::cmp::Ordering::Equal)
}) })
.min_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
.map(|(i, _)| i) .map(|(i, _)| i)
} }