Repository navigation
fix: keep SQLite fuzzy-term index memory in sync with the database - #355
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Kevin Turcios (KRRT7) wants to merge 1 commit into
Conversation
SqliteRelatedTermsFuzzy keeps a VectorBase, a term list, and an added-terms set in memory alongside the RelatedTermsFuzzy table, but three paths let them drift: - clear() only deleted the rows, so lookups still returned cleared terms and re-adding them was skipped, leaving the table empty. - deserialize() of empty data returned before clearing the VectorBase, so later terms were mapped to the wrong embeddings. - Loading an existing database did not populate the added-terms set, so re-adding a stored term duplicated it in lookups and serialize(). Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
Bernhard Merkle (bmerkle)
approved these changes
Oct 18, 2026
Bernhard Merkle (bmerkle)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — verified locally.
- All three drift paths reproduce: each new test fails against
main'srelated_terms_index.pyand passes with the fix. Fullmakeis green (814 passed). - Checked the rest of the class for the same class of bug:
remove_termraisesNotImplementedError, and theadd_terms_with_embeddingsand non-emptydeserializepaths already keep_vector_base/_terms_list/_added_termsin step with the table.
Non-blocking follow-up, same family: duplicates within one batch aren't filtered. add_terms(["fig", "fig", "date"]) writes 2 rows (thanks to INSERT OR REPLACE), but _terms_list/VectorBase get 3 entries, so serialize() returns ['fig', 'fig', 'date'] and lookup_term("fig") returns fig twice. Production callers pass unique terms today, so it's latent; de-duplicating new_terms in add_terms_with_embeddings (e.g. via dict.fromkeys) would close it.
This branch has not been deployed
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
SqliteRelatedTermsFuzzykeeps aVectorBase, a term list (vector position → term), and an added-terms set in memory alongside theRelatedTermsFuzzytable. Three paths let the in-memory state drift from the table:clear()only deleted the rows. Lookups still returned cleared terms, and re-adding a cleared term was skipped as "already added", so the table stayed empty (size 0,get_terms() == []).deserialize()of empty data returned before clearing theVectorBase. Terms added afterwards were appended after the stale vectors, so their positions no longer matched the term list and lookups could not find them.lookup_term("plum")returnedplumtwice andserialize()listed it twice.The fix resets all three in-memory structures in
clear()anddeserialize(), and populates the added-terms set when loading.Validation