fix(index): attach to existing index when overwrite is false#32
Open
guyroyse wants to merge 1 commit into
Open
fix(index): attach to existing index when overwrite is false#32guyroyse wants to merge 1 commit into
guyroyse wants to merge 1 commit into
Conversation
SearchIndex.create(overwrite, drop) only dropped-then-recreated when overwrite was true; otherwise it fell through to an unconditional FT.CREATE and threw SEARCH_INDEX_EXISTS on an existing index. There was no "create-if-absent / attach" branch. This made MessageHistory single-use per index: its constructor calls create(false), so resuming a conversation or opening a second session in the same index threw mid-construction. SemanticMessageHistory was affected the same way through its default overwrite=false constructors. Match Python's create(overwrite=False): when the index already exists and overwrite is false, attach to it and return instead of recreating. The fix lives in the shared SearchIndex.create, so MessageHistory and SemanticMessageHistory are both repaired at once. Add SearchIndexTest coverage for the attach (overwrite=false) and recreate (overwrite=true) paths, each asserting existing data is preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Problem
SearchIndex.create(overwrite, drop)had no create-if-absent branch — withoverwrite=falseon an existing index it issued an unconditionalFT.CREATEand threwSEARCH_INDEX_EXISTS. This madeMessageHistorysingle-use per index (resume + second session both threw);SemanticMessageHistorywas affected the same way through its default constructors.Fix
When the index exists and
overwriteis false, attach and return (mirrors Python'screate(overwrite=False)). The change is in the sharedSearchIndex.create, so both extensions are repaired at once. No public signature changes.Tests
Added
SearchIndexTestcoverage for the attach (overwrite=false) and recreate (overwrite=true) paths, each asserting existing data is preserved. Verified multi-session + resume end-to-end against live Redis.Closes #31
🤖 Generated with Claude Code
Note
Low Risk
Small behavioral fix in shared index lifecycle code with targeted tests; no API signature changes.
Overview
SearchIndex.create(overwrite, drop)now treats an existing index as attach-only whenoverwriteis false: it logs and returns without callingFT.CREATE, instead of failing with an index-already-exists error. Whenoverwriteis true, behavior is unchanged—drop (optionally with data) then recreate.This aligns Java with Python’s
create(overwrite=False)and fixes callers such asMessageHistorythat callcreate(false)on every session so a second session can reuse the same index and data.Javadoc for the overload is expanded.
SearchIndexTestadds integration coverage forcreate(false)(data preserved) andcreate(true)(index still exists with data).Reviewed by Cursor Bugbot for commit 8cd6727. Bugbot is set up for automated code reviews on this repo. Configure here.