feat(#782): sk learn --dedupe — pre-write FTS5 similarity check#788
Merged
Conversation
…ear-duplicates - _find_similar_entries(): BM25 query against knowledge_fts, threshold -3.0 - --dedupe warn (default): print warning, allow write - --dedupe block: prevent write if near-duplicate found - --dedupe off: skip check (for batch ingest) - --merge <id>: UPDATE existing entry instead of INSERT Closes #782 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The dedupe check opened a get_db() connection and explicitly closed it before _write_learn_entry. Tests patch get_db() to return a single shared connection, so closing it made the later json_mode db.execute() fail with 'Cannot operate on a closed database'. Use del to drop the local reference instead; in production CPython the connection is released immediately (refcount → 0), while in tests the shared connection stays alive because the test closure still holds it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tests that call learn.main() directly without patching get_db() would hit the real get_db() → sys.exit(1) when no knowledge.db exists in CI. Wrap the dedupe DB open in try/except SystemExit so missing DB causes skip (no similar entries) rather than aborting the write. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Implements #782. FTS5 BM25 similarity check before INSERT in learn.py. --dedupe warn/block/off. --merge . Closes #782