Describe the bug
Searching memories with a multi-word query in memory_read returns nothing unless the exact phrase appears verbatim in the entry text, because the filter uses a naive substring match (text.includes(q)).
Example
Given an entry with the text:
"The user prefers to drink coffee in the morning."
Searching with query coffee morning returns no results (the entry actually says "coffee in the morning" — the words in between break the exact substring match). Searching coffee alone works.
Suggested fix
Split the query into terms and match when all meaningful terms are present (AND logic), with a fallback to substring matching when the query has no terms longer than 2 characters:
function readQuery(store, directory, opts = {}) {
const q = String(opts.query ?? "").trim().toLowerCase();
if (!q) return readableEntries(store, directory).filter((e) => !opts.category || e.category === opts.category).filter((e) => !opts.scope || e.scope === opts.scope).sort((a, b) => score(b) - score(a));
const terms = q.split(/\s+/).filter((w) => w.length > 2);
return readableEntries(store, directory).filter((e) => {
const hay = e.text.toLowerCase() + " " + e.category.toLowerCase();
if (terms.length > 0) return terms.every((w) => hay.includes(w));
return hay.includes(q);
}).filter((e) => !opts.category || e.category === opts.category).filter((e) => !opts.scope || e.scope === opts.scope).sort((a, b) => score(b) - score(a));
}
Expected behavior
Multi-word queries like coffee morning, sudo password or open source privacy should match the corresponding entries.
Note: this issue was vibecoded — written with the help of an AI assistant (opencode) during a live session. The suggested patch was tested against real data and works, but please review it before merging.
Describe the bug
Searching memories with a multi-word query in
memory_readreturns nothing unless the exact phrase appears verbatim in the entry text, because the filter uses a naive substring match (text.includes(q)).Example
Given an entry with the text:
Searching with query
coffee morningreturns no results (the entry actually says "coffee in the morning" — the words in between break the exact substring match). Searchingcoffeealone works.Suggested fix
Split the query into terms and match when all meaningful terms are present (AND logic), with a fallback to substring matching when the query has no terms longer than 2 characters:
Expected behavior
Multi-word queries like
coffee morning,sudo passwordoropen source privacyshould match the corresponding entries.Note: this issue was vibecoded — written with the help of an AI assistant (opencode) during a live session. The suggested patch was tested against real data and works, but please review it before merging.