Formation resolve.ts: SIMILARITY_DUPLICATE=0.9 is compared against raw BM25 score, causing legitimate memories to be silently discarded
Summary
In src/memory/formation/resolve.ts, the threshold constants (SIMILARITY_HIGH=0.75, SIMILARITY_MEDIUM=0.50, SIMILARITY_DUPLICATE=0.90) are expressed as normalized similarity scores (0..1), but they are compared against SearchHit.score returned by searchMemories(...), which in practice is the raw BM25 / FTS score (typically in the tens to hundreds).
As a result, almost any new memory that shares a handful of common technical words with any existing observation triggers the "Near-duplicate / Duplicate" branch and gets silently DISCARDed, even when the contents are semantically unrelated.
Reproduction
Repo: AVIDS2/memorix v1.0.8. Steps:
-
Store an initial "noisy" memory containing a long log dump or trace (lots of generic technical tokens:
error,kilo,plugin,session,memorix,trace,file,config,store, ...). -
Store any other long technical memory afterwards, even one on a completely different topic (e.g. "home network topology decision" vs. "running heart-rate zones decision").
-
Inspect the reply from
memorix_store. You will see:[SKIP] Formation DISCARD: Duplicate of #<N> (score: 272.71) [FAST] Formation[active]: contextual (0.51) | discard | 26msThe score is 272.71 — clearly not in the [0..1] range.
Root cause
src/memory/formation/resolve.ts:
const SIMILARITY_DUPLICATE = 0.90;
// ...
if (best.hit.score >= SIMILARITY_DUPLICATE) {
// ... discard / evolve branch
}
best.hit.score comes directly from FTS / BM25, e.g. 30..400, so the predicate is effectively always true for any non-trivial overlap. The composite scoreCandidate(...) also propagates the unnormalized score:
const score = candidate.score * 0.6
+ (entityMatch ? 0.2 : 0)
+ contentOverlap * 0.2;
— mixing a value with a potential magnitude of 100+ with 0.2 bonuses is meaningless.
Real-world impact
In an active session that creates a few early "debug dump" observations, those observations turn into permanent content black holes that swallow all subsequent technical memories of any topic. The user gets the impression "session.idle auto-store works but nothing actually persists", because every legitimate new memory is silently DISCARDed.
Concrete trace from a real session (3 unrelated long memories on home network, running training, NAS RAID-Z2):
tryStore CALL[session_idle] memorix_store entity=kilo-conversation type=decision title="..." narrLen=1008 ...
tryStore STORED reply=[SKIP] Formation DISCARD: Duplicate of #29 (score: 396.00) ...
tryStore CALL[session_idle] memorix_store entity=kilo-conversation type=gotcha title="..." narrLen=1123 ...
tryStore STORED reply=[SKIP] Formation DISCARD: Duplicate of #17 (score: 272.71) ...
#17 and #29 are early debug log dumps and share nothing semantically with home network or NAS RAID-Z2.
Suggested fix
Either:
- Normalize
SearchHit.scoreto [0..1] before passing it torunResolve. For SQLite FTS BM25 you can apply1 / (1 + score)or a per-query softmax across the top-k hits, then keep the existing thresholds. - Express thresholds in raw BM25 units and document them as such. This is brittle because BM25 scale depends on corpus and query length.
Option 1 is much safer and matches the apparent intent of the code (SIMILARITY_* constants are clearly meant to be normalized similarities).
Environment
- Memorix
v1.0.8(latest release) - Used via MCP from a Kilo Code v7.3.1 plugin
- Project: 30 observations total, ~10 of them are early debug log dumps
Workaround
Manually memorix_resolve (archive) any large "log dump" observations to remove them from the dedup pool. New unrelated memories will then be accepted until the next noisy memory is created and starts swallowing things again.
Thanks for the detailed report. Your diagnosis is correct.
I confirmed locally that SearchHit.score is a backend ranking score from the Orama/compact search path, not a guaranteed normalized semantic similarity in [0, 1]. Comparing that raw score directly against SIMILARITY_DUPLICATE = 0.90 is wrong and can make noisy/high-token observations behave like duplicate black holes.
I have a local fix in progress now:
- add a regression test where an unrelated noisy hit has
score: 272.71 - ensure that case resolves as
new, notdiscard - separate backend ranking score from normalized semantic similarity inside
resolve.ts - keep existing normalized-score tests passing
Current local verification:
npx vitest run tests/memory/formation/resolve.test.ts tests/memory/formation/pipeline.test.tspasses: 27 testsnpm run lintpassesnpm run buildpasses
Workaround until the patch is released: archive/resolve large noisy log-dump observations from the active set, or temporarily run formation in shadow/fallback mode if you are seeing valid memories skipped. But the real fix is to stop treating raw ranking scores as duplicate similarity, which is what this patch addresses.
Fixed on main in commit 5a780b6 (fix(formation): ignore raw ranking scores for duplicates).
What changed:
resolve.tsnow treats backend search scores above1as raw ranking scores, not normalized semantic similarity.- Duplicate thresholds such as
SIMILARITY_DUPLICATE = 0.90are only applied to normalized0..1similarity values. - Added a regression test for the reported class of failure: an unrelated noisy log-dump hit with
score: 272.71now resolves asnew, notdiscard. - Added the fix to the 1.0.9 changelog.
Verification run locally:
npx vitest run tests/memory/formation/resolve.test.ts tests/memory/formation/pipeline.test.ts— 27 passednpm test— full suite passednpm run lint— passednpm run build— passed
Leaving the issue open until the release/tag is cut, but the code fix is committed.
GitHub release/tag is now available: https://github.com/AVIDS2/memorix/releases/tag/v1.0.9\n\nCI is green on main for c4184231c86a1a49b3686fb8cd302e44477fa251. npm publish is still pending npm registry authentication on the release machine; keeping this open until the npm package is published as well.
Fixed and released in [email protected] on npm.
The fix changes Formation duplicate detection so raw Orama/BM25 ranking scores are no longer compared directly against normalized similarity thresholds. Noisy log-dump memories with high backend ranking scores should no longer silently discard unrelated valid memories as duplicates.
Verification completed before release:
- Local:
npm run lint,npm run build, fullnpm test,npm pack --dry-run - CI: main push
ad0e584ba1c45caab0b417b1c064750cf89b597bpassed on Windows/Ubuntu Node 20/22 - npm:
npm view memorix versionnow returns1.0.9
@a1364702 抱歉让你被这件事卷进来。
这几天仓库遇到了一些新账号在多个 issue 下集中发布与技术问题无关的 Star 相关指控,其中部分评论带有明显的攻击性和刷屏性质。我刚才在手机上点了 GitHub 的“引用回复”,本意是回复后面那条无关评论,但因为 GitHub issue 不是楼中楼,引用内容里带到了你的用户名,容易让人误以为我是在针对你。
不是这样的。你之前提交的 formation duplicate bug report 是真实有效的问题,也已经帮助项目修复并发布到 1.0.9,我很感谢你的反馈。
为了避免误会,我已经删除了我之前那条情绪化且不合适的回复。后续我会把无关争论和正常技术反馈区分开处理。