You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory: use the existing embeddings for dedup and contradiction detection #310
Code audit finding: entries get embedded (all-MiniLM-L6-v2, entry_vectors table) but dedup on write is lexical Jaccard over the 500 newest entries (src/memory.js:315-331), and the janitor's contradiction scan is shared-entity-count + Jaccard (src/janitor.js:21-90). Neither uses the vectors that already exist.
Use cosine over entry_vectors for near-duplicate detection (catches paraphrases Jaccard misses) and to rank contradiction candidates before enqueueing review pairs. While there: the vector leg is brute-force cosine with BLOB decode per row on every query — fine at hundreds of entries, but if the store grows, add sqlite-vec for ANN rather than hand-rolling.
Approach settled after reading the flow. Shared contract landed first, two grok workers building on it in parallel:
Contract (done, 4289207) — semanticNeighbors(db, vec, opts) in memory-server/src/review.js, whose docstring already declared it "shared by store gate + janitor scan". Cosine over entry_vectors, same-project + live only, fail-soft. Plus SEMANTIC_DUP = 0.88 / SEMANTIC_RELATED = 0.6. Covered by test/semantic-neighbors.test.js.
Worker A — write path (memory.js): semantic near-dup check runs inside embedEntry, right after the vector is UPSERTed, and enqueues a near_dup pair at cosine >= 0.88.
Worker B — janitor (janitor.js): contradiction candidates ranked by cosine, capped at 3 pairs per entry, with a third gate (shared entity + cosine >= 0.6) catching the paraphrased contradictions Jaccard scores under 0.4. Falls back to today's exact behaviour when an entry has no vector.
Two deliberate non-goals:
store() stays synchronous, so the hard block gate stays lexical. Embedding is async; making the block gate semantic forces store() async and await onto ~50 test call sites and 2 callers. A paraphrase now gets stored and immediately queued for review rather than refused — the review queue is the designed mechanism for that, and memory_maintenance/memory_resolve already surface it.
No sqlite-vec. Brute-force cosine with a per-row BLOB decode is fine at this store size; the ceiling and the ANN upgrade path are noted in a ponytail: comment at the helper.
Correction to my previous comment: this issue was already implemented on main before I started.
My worktree was cut from 32917ec. Commit 7de6476 (merge of coder/memory-use-the-existing-embeddings-for-d-d60c60) landed on mainafter that, from a parallel thread on this same issue, and already ships both halves: checkSemanticDup() + SEMANTIC_DUP = 0.9 in memory.js, and CONTRA_SIM/CONTRA_TOP cosine ranking with a per-pass vector cache in janitor.js. That is the issue as filed; nothing further is needed for it.
What survives from my thread is a refactor, not a feature: main had two hand-rolled brute-force cosine scans (vectorSearch and checkSemanticDup). The shared semanticNeighbors() helper collapses the second into a 5-line call and deletes checkSemanticDup entirely: net -62 lines, suite green 157/157.
Two deltas, deliberately handled:
Threshold drifted 0.9 to 0.88 in the worker's commit. Restored to 0.9 so the rewire is behaviour-preserving.
Scope: checkSemanticDup used projectScopeSql, so a global entry compared against every project's entries while a project entry compared only within its own. The helper uses exact project IS ? both ways, matching the lexical gate findNearDup. Small but real behaviour change; worth a look rather than a rubber stamp.
I did not rebuild the janitor half. main's version caches decoded vectors across candidates within a pass; routing it through semanticNeighbors would re-decode per candidate, which is strictly worse.
Activity
currentbits commentedon Aug 17, 2026
Approach settled after reading the flow. Shared contract landed first, two grok workers building on it in parallel:
Contract (done,
4289207) —semanticNeighbors(db, vec, opts)inmemory-server/src/review.js, whose docstring already declared it "shared by store gate + janitor scan". Cosine overentry_vectors, same-project + live only, fail-soft. PlusSEMANTIC_DUP = 0.88/SEMANTIC_RELATED = 0.6. Covered bytest/semantic-neighbors.test.js.Worker A — write path (
memory.js): semantic near-dup check runs insideembedEntry, right after the vector is UPSERTed, and enqueues anear_duppair at cosine >= 0.88.Worker B — janitor (
janitor.js): contradiction candidates ranked by cosine, capped at 3 pairs per entry, with a third gate (shared entity + cosine >= 0.6) catching the paraphrased contradictions Jaccard scores under 0.4. Falls back to today's exact behaviour when an entry has no vector.Two deliberate non-goals:
store()stays synchronous, so the hard block gate stays lexical. Embedding is async; making the block gate semantic forcesstore()async andawaitonto ~50 test call sites and 2 callers. A paraphrase now gets stored and immediately queued for review rather than refused — the review queue is the designed mechanism for that, andmemory_maintenance/memory_resolvealready surface it.ponytail:comment at the helper.currentbits commentedon Aug 17, 2026
Correction to my previous comment: this issue was already implemented on
mainbefore I started.My worktree was cut from
32917ec. Commit7de6476(merge ofcoder/memory-use-the-existing-embeddings-for-d-d60c60) landed onmainafter that, from a parallel thread on this same issue, and already ships both halves:checkSemanticDup()+SEMANTIC_DUP = 0.9inmemory.js, andCONTRA_SIM/CONTRA_TOPcosine ranking with a per-pass vector cache injanitor.js. That is the issue as filed; nothing further is needed for it.What survives from my thread is a refactor, not a feature:
mainhad two hand-rolled brute-force cosine scans (vectorSearchandcheckSemanticDup). The sharedsemanticNeighbors()helper collapses the second into a 5-line call and deletescheckSemanticDupentirely: net -62 lines, suite green 157/157.Two deltas, deliberately handled:
checkSemanticDupusedprojectScopeSql, so a global entry compared against every project's entries while a project entry compared only within its own. The helper uses exactproject IS ?both ways, matching the lexical gatefindNearDup. Small but real behaviour change; worth a look rather than a rubber stamp.I did not rebuild the janitor half.
main's version caches decoded vectors across candidates within a pass; routing it throughsemanticNeighborswould re-decode per candidate, which is strictly worse.memory: cosine near-dup on write via semanticNeighbors (#310)
memory: keep semantic near-dup at 0.9, drop unused SEMANTIC_RELATED
memory: drop semantic-dedup.test.js as a duplicate of dedup.test.js
memory: rank janitor contradiction pairs via semanticNeighbors (#310)
fix(memory): restore SEMANTIC_RELATED, the janitor rewire (#310) is i…