feat(recall): temporal-precision

This commit is contained in:
2026-06-22 13:29:12 -05:00
2 changed files with 59 additions and 7 deletions
+5 -4
View File
@@ -46,6 +46,8 @@ fn engram_score_node(node_json: String) -> Int {
let salience_str: String = json_get(node_json, "salience")
let importance_str: String = json_get(node_json, "importance")
let created_str: String = json_get(node_json, "created_at")
let updated_str: String = json_get(node_json, "updated_at")
let tier_str: String = json_get(node_json, "tier")
// Q1 fix: validate before str_to_int. Non-numeric values fall back to safe defaults.
// Parse as floats via * 100 integer arithmetic (el has no float math).
@@ -58,7 +60,6 @@ fn engram_score_node(node_json: String) -> Int {
if v > 100 { 100 } else { if v < 0 { 0 } else { v } }
}
// Recency: decay from 100 (today) to 10 (30+ days). created_at is Unix seconds.
let now_ts: Int = time_now()
let recency_100: Int = if !engram_numeric_valid(created_str) { 50 } else {
let created_ts: Int = str_to_int(created_str)
@@ -69,7 +70,6 @@ fn engram_score_node(node_json: String) -> Int {
if decay < 10 { 10 } else { decay }
}
// Combined score 0-1000000 (no floats): salience * importance * recency / 10000
return salience_100 * importance_100 * recency_100 / 10000
}
@@ -393,7 +393,7 @@ fn engram_compile(intent: String) -> String {
let bell_nodes: String = engram_search_json("bell:soft bell:hard BellEvent", 3)
let bell_ok: Bool = !str_eq(bell_nodes, "") && !str_eq(bell_nodes, "[]")
let now_ts: Int = time_now()
let cutoff_ts: Int = now_ts - 259200
let cutoff_ts: Int = now_ts - 1209600
let recent_bell: String = if bell_ok {
let bn0: String = json_array_get(bell_nodes, 0)
let bn_content: String = json_get(bn0, "content")
@@ -1447,7 +1447,8 @@ fn handle_chat_agentic(body: String) -> String {
let discard_hist: Bool = if !str_eq(reply_text, "") {
let updated: String = hist_append(agentic_hist, "user", message)
let updated2: String = hist_append(updated, "assistant", reply_text)
let trimmed: String = if json_array_len(updated2) > 20 { hist_trim(updated2) } else { updated2 }
// Increased from 20 to 40 turns: consistent with handle_chat window expansion.
let trimmed: String = if json_array_len(updated2) > 40 { hist_trim(updated2) } else { updated2 }
state_set(hist_key, trimmed)
true
} else { false }