feat: add embedding-based dedup and 'lore data reindex' command#288
Merged
Conversation
Enhance deduplicate() to use vector cosine similarity (threshold 0.85) alongside title word-overlap. With Nomic v1.5, same-domain distinct entries score 0.46-0.70, making embedding-based dedup viable — entries with different titles but semantically identical content are now caught. Add 'lore data reindex' CLI command to trigger checkConfigChange() + backfillEmbeddings() + backfillDistillationEmbeddings() on demand, without requiring a gateway restart. The dedup command now auto-reindexes if the embedding config changed (e.g. after a model migration) or if entries are missing embeddings, ensuring vectors are fresh before running similarity comparisons.
- Restore corrupted .lore.md entry 019e20a4 (curator overwrote cache warming gotcha with Nomic migration text) - Scope embedding DB query to project entry IDs instead of global fetch - Add try/catch around fromBlob() for corrupted embedding BLOBs - Remove double checkConfigChange() calls (backfillEmbeddings handles it) - Dedup auto-reindex now also backfills distillation embeddings - Add error handling around backfill calls in both cmdReindex and cmdDedup - Rename OverlapHit → DedupHit with 'score' field (was 'coefficient')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deduplicate()to use embedding cosine similarity (≥0.85 threshold) alongside title word-overlap, catching semantically identical entries with different titleslore data reindexCLI command for on-demand re-embedding without gateway restartlore data dedupwhen stale/missing embeddings detectedMotivation
With the Nomic v1.5 migration (PR #287), same-domain distinct entries score 0.46–0.70 cosine similarity — making embedding-based dedup viable at threshold 0.85+. Previously, BGE Small produced 0.93–0.97 for all same-domain entries, so dedup was limited to title word-overlap only.
What changed
packages/core/src/ltm.tsdeduplicate()now builds neighbor maps using two signals: title word-overlap (existing, ≥0.7 Jaccard + ≥4 shared words) OR embedding cosine similarity (new, ≥0.85). Pairs matching either signal are clustered together.entryVec.length === otherVec.length) to skip stale vectors.packages/gateway/src/cli/data.tslore data reindexcommand: callscheckConfigChange()+backfillEmbeddings()+backfillDistillationEmbeddings()directly.lore data dedupnow auto-callscheckConfigChange()+backfillEmbeddings()before scanning, so stale embeddings from a model migration are refreshed automatically.Test results