Skip to content

fix(index): attach to existing index when overwrite is false#32

Open
guyroyse wants to merge 1 commit into
redis:mainfrom
guyroyse:fix/message-history-attach
Open

fix(index): attach to existing index when overwrite is false#32
guyroyse wants to merge 1 commit into
redis:mainfrom
guyroyse:fix/message-history-attach

Conversation

@guyroyse

@guyroyse guyroyse commented Jun 25, 2026

Copy link
Copy Markdown

Problem

SearchIndex.create(overwrite, drop) had no create-if-absent branch — with overwrite=false on an existing index it issued an unconditional FT.CREATE and threw SEARCH_INDEX_EXISTS. This made MessageHistory single-use per index (resume + second session both threw); SemanticMessageHistory was affected the same way through its default constructors.

Fix

When the index exists and overwrite is false, attach and return (mirrors Python's create(overwrite=False)). The change is in the shared SearchIndex.create, so both extensions are repaired at once. No public signature changes.

Tests

Added SearchIndexTest coverage 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 when overwrite is false: it logs and returns without calling FT.CREATE, instead of failing with an index-already-exists error. When overwrite is true, behavior is unchanged—drop (optionally with data) then recreate.

This aligns Java with Python’s create(overwrite=False) and fixes callers such as MessageHistory that call create(false) on every session so a second session can reuse the same index and data.

Javadoc for the overload is expanded. SearchIndexTest adds integration coverage for create(false) (data preserved) and create(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.

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>
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.

MessageHistory single-use per index: resume / second session throws SEARCH_INDEX_EXISTS

1 participant