You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] bm reindex --embeddings fails with UNIQUE constraint on duplicate search_index rows #654
bm reindex --embeddings fails with UNIQUE constraint failed on search_vector_embeddings primary key for a subset of entities. Each subsequent run fixes exactly one more entity
(61 errors → 60 → 59), but the issue never fully resolves.
Steps To Reproduce
Have an existing project with indexed entities
Run bm reindex --embeddings
Expected Behavior
All entities should be embedded without errors.
Actual Behavior
A batch of entities fails with:
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError)
UNIQUE constraint failed on search_vector_embeddings primary key
[SQL: INSERT INTO search_vector_embeddings (rowid, embedding) VALUES (?, ?)]
Running again: 270/60, then 271/59 — one fewer error per pass.
Environment
OS: Windows 11
Python: 3.13.9
Basic Memory: 0.19.1
Installation: uv tool
Additional Context
The error trace shows the same rowid (e.g., 1438) appearing twice in a single INSERT batch.
Looking at the code, the path seems to be:
_build_chunk_records in search_repository_base.py builds a list from search_index rows using chunk_key = f"{row.type}:{row.id}:{chunk_index}". Since search_index is an FTS5 virtual table, it doesn't enforce UNIQUE constraints on (entity_id, type, id), so duplicate rows can accumulate over time.
When duplicates exist, the same chunk_key appears multiple times in chunk_records. The upsert loop at line 918 resolves both to the same existing chunk via existing_by_key dict lookup, appending the same row_id to embedding_jobs twice.
_write_embeddings then tries to INSERT the same rowid twice in the same executemany call, hitting the UNIQUE constraint.
The "one fix per pass" behavior likely comes from batch boundaries shifting between runs — entities co-batched with the failing entity get a chance to land in a clean batch on the next run, while the entity with the duplicate search_index rows keeps failing.
Activity
Fix SQLite and Windows semantic regressions