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:
parent
a20f3e3642
commit
e213644514
1 changed files with 4 additions and 5 deletions
|
|
@ -223,12 +223,11 @@ fn trim_entries(entries: &[ContextEntry], fixed_tokens: usize) -> Vec<ContextEnt
|
|||
|
||||
fn lowest_scored_memory(entries: &[ContextEntry]) -> Option<usize> {
|
||||
entries.iter().enumerate()
|
||||
.filter(|(_, e)| e.entry.is_memory())
|
||||
.min_by(|(_, a), (_, b)| {
|
||||
let sa = match &a.entry { ConversationEntry::Memory { score, .. } => score.unwrap_or(0.0), _ => 0.0 };
|
||||
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)
|
||||
.filter_map(|(i, e)| match &e.entry {
|
||||
ConversationEntry::Memory { score: Some(s), .. } => Some((i, *s)),
|
||||
_ => None,
|
||||
})
|
||||
.min_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal))
|
||||
.map(|(i, _)| i)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue