Fast startup: only retokenize tail of conversation log
restore_from_log reads the full log but walks backwards from the tail, retokenizing each node as it goes. Stops when conversation budget is full. Only the nodes that fit get pushed into context. Added AstNode::retokenize() — recomputes token_ids on all leaves after deserialization (serde skip means they're empty). Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
6ec0e1c766
commit
7da3efc5df
2 changed files with 40 additions and 5 deletions
|
|
@ -296,6 +296,23 @@ impl AstNode {
|
|||
|
||||
// -- Builder --------------------------------------------------------------
|
||||
|
||||
pub fn retokenize(self) -> Self {
|
||||
match self {
|
||||
Self::Leaf(leaf) => {
|
||||
let token_ids = if leaf.body.is_prompt_visible() {
|
||||
tokenizer::encode(&leaf.body.render())
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
Self::Leaf(NodeLeaf { token_ids, ..leaf })
|
||||
}
|
||||
Self::Branch { role, children } => Self::Branch {
|
||||
role,
|
||||
children: children.into_iter().map(|c| c.retokenize()).collect(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_timestamp(mut self, ts: DateTime<Utc>) -> Self {
|
||||
match &mut self {
|
||||
Self::Leaf(leaf) => leaf.timestamp = Some(ts),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue