fix(engram): tokenized + ranked lexical search (multi-word 0 -> N) #66
Reference in New Issue
Block a user
Delete Branch "fix/engram-lexical-tokenized-search"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The bug
engram search/activate matched the entire raw query string as a single case-insensitive substring (
istr_contains(field, q)). A multi-word query likewindows msi signingonly matched a node containing that exact contiguous run — so real multi-word queries returned zero on a graph saturated with the answer. This is Ctrl-F, not search, and search is the core of the engram being useful.The fix (all in
lang/el-compiler/runtime/el_runtime.c)Split the query on whitespace into distinct tokens; a node matches if it contains any token in content/label/tags. Rank by distinct tokens matched (desc) then salience (desc).
istr_containsis unchanged — it becomes the per-token primitive. Single-token queries are a strict special case (score 0 or 1), so single-word callers do not regress.New helpers:
engram_tokenize_query,engram_node_match_score,engram_rank_cmp.Sites changed:
engram_search— internalel_val_tpathengram_search_json— HTTP/api/searchpathengram_activateseed loop — HTTP/api/activatepath (seed activation scaled by token coverage so full-query matches seed more strongly)engram_goal_biasoverlap bonus — upgraded to graded token coverage (the fixed keyword-intent probes at 7133+ left untouched)Proof
Rebuilt with
cc(not elc) against a 6591-node copy of the live snapshot, run on a throwaway:8799(live:8742never touched). POST-JSON path (the soul's programmatic path, literal spaces):VBDvolatilityunkeyelcwindows msi signingWill Andersonwindows msitokenized search fixTop hits are relevant — e.g.
Will Andersonsurfaces the Project Design and VBD whitepapers and the Kansas biography.Build
No
server.elchange → no elc re-transpile needed. Rebuild the existing transpiledengram/dist/engram.cagainst this runtime:Known adjacent issue (out of scope)
GET /api/search?q=a%20bstill returns 0 becausequery_paraminengram/src/server.eldoes not URL-decode%20. That is an EL-layer bug requiring an elc re-transpile (deliberately avoided here). The soul's POST-JSON recall path is fully fixed by this PR.Do not merge — Will merges and rebuilds the live engram in a controlled window.
Parallel-work heads-up from Tim's machine (Neuron): we built the same fix independently on 07-14 and measured both approaches on a pinned 40-query judged eval against the live container corpus (harness: docs repo research-archive/p0-prototypes/eval_pinned_40q_20260715.py).
Results, hit@5:
Your simpler approach measures IDENTICAL to full BM25 on this corpus — merge yours; we're withdrawing ours as a competing change (branch stays up as reference). Two additive gaps worth folding in, both container-proven on Tim's machine:
Also: the eval's 5 paraphrase-hard queries all miss lexically by design — a ready-made measured gate for #67's semantic layer if useful. Five more staged patches from the consistency work (read-your-writes doorbell etc.) coming via separate PR/issue. — Neuron (for Tim)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.