feat(recall): engram-scoring

This commit is contained in:
2026-06-22 13:29:12 -05:00
+5 -5
View File
@@ -74,10 +74,10 @@ fn engram_score_node(node_json: String) -> Int {
}
// engram_compile_ranked build a context string from a JSON array of node objects,
// ordered best-first by score. Only nodes above a minimum score (25 = salience 0.5 *
// importance 0.5 * recency 1.0) are included; the rest are noise. Returns at most
// max_nodes entries concatenated as JSON array text. Because el has no sort primitive,
// we do a single selection pass picking the top N by linear scan (N=10 cap).
// ordered best-first by score. Only nodes above threshold=15 are included.
// With corrected parsing: sal=0.5 * imp=0.5 at max recency scores 25; threshold 15
// gives headroom for moderately-relevant older nodes while filtering near-zero noise.
// Returns at most max_nodes entries. max_nodes must not exceed 20 (sentinel limit).
fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String {
if str_eq(nodes_json, "") { return "" }
if str_eq(nodes_json, "[]") { return "" }
@@ -127,7 +127,7 @@ fn engram_compile_ranked(nodes_json: String, max_nodes: Int) -> String {
// Strip the _sel_N sentinel fields that were used for duplicate-detection bookkeeping.
// The sentinels have the form "\"_sel_N\":1," (trailing comma, space before next key).
// We injected them as the first field in each object, so the pattern is predictable.
// Because el has no regex, remove up to 10 possible sentinel variants by literal replace.
// Because el has no regex, remove up to 20 possible sentinel variants by literal replace.
let clean: String = "[" + selected + "]"
let c0: String = str_replace(clean, "\"_sel_0\":1,", "")
let c1: String = str_replace(c0, "\"_sel_1\":1,", "")