Skip to content

Commit 9acd2a6

Browse files
phernandezclaude
andcommitted
fix: preserve search index across server restarts
Remove unconditional DROP TABLE from init_search_index() that was wiping the FTS5 search index on every MCP server startup. The bug was introduced in PR #439 (v0.16.3) when splitting SQLite and Postgres search implementations. The DROP TABLE was added with a comment about Base.metadata.create_all() potentially creating a regular table, but this caused all indexed data to be lost whenever Claude Desktop restarted the MCP server. Symptoms users experienced: - Notes searchable immediately after creation - Search returns empty results after ~30 minutes (server restart) - Files exist on disk but search index is empty - recent_activity() shows "No recent activity" The fix simply removes the DROP TABLE since CREATE_SEARCH_INDEX already uses "CREATE VIRTUAL TABLE IF NOT EXISTS" which safely handles both cases (table exists vs doesn't exist). Affected users should run `basic-memory reset` once after updating to rebuild their search index. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5947f04 commit 9acd2a6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/basic_memory/repository/sqlite_search_repository.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ class SQLiteSearchRepository(SearchRepositoryBase):
2727
"""
2828

2929
async def init_search_index(self):
30-
"""Create FTS5 virtual table for search.
30+
"""Create FTS5 virtual table for search if it doesn't exist.
3131
32-
Note: Drops any existing search_index table first to ensure FTS5 virtual table creation.
33-
This is necessary because Base.metadata.create_all() might create a regular table.
32+
Uses CREATE VIRTUAL TABLE IF NOT EXISTS to preserve existing indexed data
33+
across server restarts.
3434
"""
3535
logger.info("Initializing SQLite FTS5 search index")
3636
try:
3737
async with db.scoped_session(self.session_maker) as session:
38-
# Drop any existing regular or virtual table first
39-
await session.execute(text("DROP TABLE IF EXISTS search_index"))
40-
# Create FTS5 virtual table
38+
# Create FTS5 virtual table if it doesn't exist
4139
await session.execute(CREATE_SEARCH_INDEX)
4240
await session.commit()
4341
except Exception as e: # pragma: no cover

0 commit comments

Comments
 (0)