Memory scores on entries, not a separate Vec
ConversationEntry::Memory gains score: Option<f64>. The scorer writes scores directly onto entries when results arrive. Removes Agent.memory_scores Vec and the memory_scores parameter from context_state_summary(). Scores are serialized to/from the conversation log as memory_score. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
93f5f8b0c7
commit
39dcf27bd0
6 changed files with 36 additions and 50 deletions
|
|
@ -186,7 +186,7 @@ pub fn is_stream_error(err: &anyhow::Error) -> bool {
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum ConversationEntry {
|
||||
Message(Message),
|
||||
Memory { key: String, message: Message },
|
||||
Memory { key: String, message: Message, score: Option<f64> },
|
||||
/// DMN heartbeat/autonomous prompt — evicted aggressively during compaction.
|
||||
Dmn(Message),
|
||||
/// Debug/status log line — written to conversation log for tracing,
|
||||
|
|
@ -201,7 +201,7 @@ impl Serialize for ConversationEntry {
|
|||
use serde::ser::SerializeMap;
|
||||
match self {
|
||||
Self::Message(m) | Self::Dmn(m) => m.serialize(s),
|
||||
Self::Memory { key, message } => {
|
||||
Self::Memory { key, message, score } => {
|
||||
let json = serde_json::to_value(message).map_err(serde::ser::Error::custom)?;
|
||||
let mut map = s.serialize_map(None)?;
|
||||
if let serde_json::Value::Object(obj) = json {
|
||||
|
|
@ -210,6 +210,9 @@ impl Serialize for ConversationEntry {
|
|||
}
|
||||
}
|
||||
map.serialize_entry("memory_key", key)?;
|
||||
if let Some(s) = score {
|
||||
map.serialize_entry("memory_score", s)?;
|
||||
}
|
||||
map.end()
|
||||
}
|
||||
Self::Log(text) => {
|
||||
|
|
@ -232,8 +235,11 @@ impl<'de> Deserialize<'de> for ConversationEntry {
|
|||
}
|
||||
if let Some(key) = json.as_object_mut().and_then(|o| o.remove("memory_key")) {
|
||||
let key = key.as_str().unwrap_or("").to_string();
|
||||
let score = json.as_object_mut()
|
||||
.and_then(|o| o.remove("memory_score"))
|
||||
.and_then(|v| v.as_f64());
|
||||
let message: Message = serde_json::from_value(json).map_err(serde::de::Error::custom)?;
|
||||
Ok(Self::Memory { key, message })
|
||||
Ok(Self::Memory { key, message, score })
|
||||
} else {
|
||||
let message: Message = serde_json::from_value(json).map_err(serde::de::Error::custom)?;
|
||||
Ok(Self::Message(message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue