Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/zeph-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {

#[test]
fn estimate_tokens_basic() {
assert_eq!(estimate_tokens("Hello world"), 2);
assert_eq!(estimate_tokens("Hello world"), 3);
assert_eq!(estimate_tokens(""), 0);
assert_eq!(estimate_tokens("test"), 1);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/zeph-memory/src/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ pub struct SessionSummaryResult {
pub conversation_id: ConversationId,
}

/// Estimate token count using chars/4 heuristic.
/// Estimate token count using bytes/3 heuristic.
#[must_use]
pub fn estimate_tokens(text: &str) -> usize {
text.chars().count() / 4
text.len() / 3
}

fn build_summarization_prompt(messages: &[(MessageId, String, String)]) -> String {
Expand Down Expand Up @@ -738,13 +738,13 @@ mod tests {
#[test]
fn estimate_tokens_ascii() {
let text = "Hello, world!";
assert_eq!(estimate_tokens(text), 3);
assert_eq!(estimate_tokens(text), 4);
}

#[test]
fn estimate_tokens_unicode() {
let text = "Привет мир";
assert_eq!(estimate_tokens(text), 2);
assert_eq!(estimate_tokens(text), 6);
}

#[test]
Expand Down Expand Up @@ -1023,7 +1023,7 @@ mod tests {
#[test]
fn estimate_tokens_longer_text() {
let text = "a".repeat(100);
assert_eq!(estimate_tokens(&text), 25);
assert_eq!(estimate_tokens(&text), 33);
}

#[tokio::test]
Expand Down
Loading