Skip to content

[BUG] Entities without a search_index row are invisible to every embedding path and to project info #1826

Closed

Description

@SWSAmor

Summary

An entity that has no search_index (FTS) row can never get a vector, no reindex variant short of
an explicit search pass repairs it, nothing reports it, and the only migration that promises a
backfill does nothing. On a long-lived local install (SQLite, upgraded through the 2025 migrations)
this left ~2.5% of all entities (110 of 4 453, across more than a dozen projects) unsearchable in every mode,
while bm project info reported full coverage. Verified against v0.23.2 and re-checked in the
v0.24.1 source; line references below are v0.24.1.

The four parts

  1. bm reindex --full --embeddings runs no search pass. The flags default to both only when
    neither is given (cli/commands/db.py:291-294), and the docstring itself says
    --full --embeddings # Full re-embed only. Vectors are built from FTS rows
    (repository/semantic_vector_sync.py, fetch_prepare_window_source_rows reads
    FROM search_index), so an entity without one is skipped. The command still reports success
    (in one case "7 entities embedded, 0 errors" with 0 chunks written). A user reading "full"
    reasonably expects a rebuild that repairs this.
  2. The backfill migration is empty. i2c3d4e5f6g7_auto_backfill_semantic_embeddings says
    db.run_migrations() detects the revision transition and runs sync_entity_vectors(); there is
    no such hook in run_migrations (db.py:540). Installs that enabled semantic search before this
    revision keep their pre-existing notes unembedded until the files change.
  3. FTS rows dropped by a migration never come back. 5fe1ab1ccebe and cc7172b46608 drop and
    recreate search_index empty. The scan classifies files by checksum only
    (indexing/change_planning.py:126-138), so an unchanged file is never re-indexed and its FTS row
    (and therefore its vector) never returns. Symptom: entity.size IS NULL on those rows (the
    column arrived later and is only written on re-index).
  4. project info cannot see the gap. It counts indexed entities as
    COUNT(DISTINCT entity_id) FROM search_index (services/project_service.py:1321-1329) and
    reports missing embeddings as FTS minus vectors, so an entity with neither is not counted
    anywhere. Coverage should be measured against entity (and arguably the files on disk).

Reproduction (part 1 + 4)

-- after deleting one entity's FTS rows, or on an install that went through the migrations above
SELECT COUNT(*) FROM entity e
WHERE NOT EXISTS (SELECT 1 FROM search_index s WHERE s.entity_id = e.id);   -- > 0

bm reindex -p <project> --full --embeddings → exit 0, the count above is unchanged.
bm project info <project> → reports no missing embeddings for those entities.
bm reindex -p <project> --full --search followed by embedding → the count goes to 0.

Suggested fixes

  • --full (with or without --embeddings) should include the search pass, or the embedding phase
    should index entities that have no FTS row instead of skipping them silently.
  • Implement the promised backfill in run_migrations, or remove the claim from the migration.
  • After a migration that drops search_index, force a full search pass on next start (or treat
    "entity without FTS row" as modified in change planning).
  • Measure coverage in project info from entity.

Workaround we use

bm reindex -p <project> --full --search, then embed the affected entities through
SearchService.sync_entity_vectors_batch (the per-entity path note writes use). We avoid
bm reindex --embeddings on large projects because of the reconcile cost fixed in #1581.

Activity

  1. added this to the v1.0 milestone on Oct 29, 2026
  2. phernandez commented on Oct 29, 2026

    @phernandez
    Member

    Fixed in #1954: index passes rebuild search rows for entities that have none, bm reindex --embeddings restores them before embedding (and reports unreadable files as errors), and project info counts entities missing from the search index against the entity table. Thanks @SWSAmor for the detailed report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions