Skip to content

Memory: use the stored embeddings for near-dup detection and contradiction ranking - #336

Merged
currentbits merged 11 commits into
mainfrom
coder/memory-use-the-existing-embeddings-for-d-d60c60
Aug 17, 2026
Merged

currentbits merged 11 commits into
mainfrom
coder/memory-use-the-existing-embeddings-for-d-d60c60

Conversation

@currentbits

@currentbits currentbits commented Aug 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #310.

Entries were already being embedded into entry_vectors (all-MiniLM-L6-v2), but nothing on the write path or in the janitor ever read those vectors: dedup on write was lexical Jaccard over the 500 newest entries, and the contradiction scan was shared-entity-count plus Jaccard. Both miss paraphrases — the same fact worded differently sails through as a fresh entry. This wires the existing vectors into both.

Write path (memory-server/src/memory.js)

New checkSemanticDup(id), chained off the fire-and-forget embed that store() already issues. It reads the new entry's vector, runs cosine against live vectors in the same scope (same project, or either side global), and a best match at or above SEMANTIC_DUP = 0.90 enqueues a near_dup review pair with a cosine= detail. Dim- and model-guarded, skips task entries to match the existing dedup skip, and fail-soft throughout.

store() stays synchronous and the hard block stays lexical, deliberately: the real MiniLM embedder is async and lazily loads its model, so blocking every write on an embed is not acceptable. Semantic hits enqueue a pair for review; they never refuse the write.

Janitor (memory-server/src/janitor.js)

scanContradictions gains cosine as a third signal — shared >= 1 && cosine >= CONTRA_SIM (0.75) — catching the paraphrased contradiction that Jaccard misses. Qualifying partners are ranked by cosine (unscored pairs sort last, preserving today's behaviour as the tail) and capped at CONTRA_TOP = 5 per candidate, so one hub entity can no longer flood the review queue; the truncation is logged rather than silent. An entry already scanned this pass is skipped as a partner, so the other side cannot re-add a pair the cap dropped.

The scan stays synchronous and needs no embedder — the vectors are already in the DB. Each vector decodes at most once per pass via a cache, and a missing entry_vectors table (old DBs mid-migration) degrades to "no score" instead of throwing. The existing best-effort contract is unchanged.

Notes

  • Behaviour change worth flagging: strong pairs (shared >= 2) were previously all enqueued and now cap at 5 per candidate.
  • sqlite-vec was deliberately not added. Brute-force cosine with a per-row BLOB decode is fine at ~10^3 entries; a ponytail: comment on vectorSearch names the ceiling and the upgrade path for when the store outgrows it. No new dependencies.

Testing

cd memory-server && npm test — 151 pass, 0 fail. New coverage: paraphrase pairs that fall below the Jaccard warn threshold but are near-identical in vector space, dissimilar pairs producing nothing, task entries skipped, the CONTRA_TOP cap enqueueing highest-cosine first, and vectorless entries behaving exactly as before.

  • PR created by the Claude Code agent

Willem added 11 commits August 17, 2026 18:27
… Memory graph is dead in production: edges table has no write
… Orchestrator worker threads are never deleted, only archived
… Verification loop: agents must prove their work before a thr
… No preload/renderer protocol version check (spec-promised)
… Observability: OTel spans from the orchestrator + failure-mo
… Auto-dispatch threads from Planboard state (issue enters pla
Lexical Jaccard still hard-blocks store(). After embed, checkSemanticDup
enqueues a near_dup review when cosine >= 0.90 so paraphrases Jaccard
misses still get flagged. store() stays sync; semantic hits never refuse
the write.
Use entry_vectors cosine as an extra contradiction signal (paraphrases
Jaccard misses), rank partners by similarity, and cap at CONTRA_TOP so
a hub entity cannot flood the review queue.
…into coder/memory-use-the-existing-embeddings-for-d-d60c60
@currentbits
currentbits merged commit 4ceb007 into main Aug 17, 2026
1 check failed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits deleted the coder/memory-use-the-existing-embeddings-for-d-d60c60 branch October 3, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory: use the existing embeddings for dedup and contradiction detection

1 participant