Skip to content

[BUG] File-watcher (direct on-disk) writes are not vector-embedded; externally-edited notes silently missing from semantic search until reindex #1016

Closed

Description

@phernandez

Summary

In the #1002 event-index architecture, files indexed by the local file watcher (direct on-disk writes from Obsidian, an editor, git pull, cloud sync landing files, etc.) are indexed for full-text search and relations but are not vector-embedded. As a result, externally-edited notes are silently missing from semantic/vector search until a manual bm reindex --embeddings. This happens in the normal flow with the watcher running (env: user/dev), so it is not a test-only or doc-only issue.

Reproduction (env=user, watcher active, semantic_search_enabled=true)

Create notes two ways in the same project, then inspect search_vector_chunks:

entity created via vector chunks
Tide Charts write_note (MCP) 5
MCP Source Forward Ref write_note (MCP) 3
MCP Forward Target QQQ write_note (MCP) 1
Watcher Auto Index Probe file written directly to disk 0
Source With Forward Ref file written directly to disk 0
Watcher Forward Target ZZZ file written directly to disk 0

The watcher correctly indexes the on-disk notes (they appear in FTS search and their relations resolve — logs show index_markdown_file + Local event-index relation repair completed), but no embeddings are produced. Semantic search then silently omits them:

search_notes(query="probe note created on disk by the file change monitor", search_type="semantic", min_similarity=0)
# returns other (embedded) notes; the on-disk "Watcher Auto Index Probe" is absent

A bm reindex --embeddings (ideally --full) embeds them and they become semantically searchable.

Root cause

The local watch/inline event runtime plumbs an index_embeddings: bool = True flag (src/basic_memory/index/local_runtime.py:221,283; src/basic_memory/index/inline_operations.py:65,82) into an IndexFileEmbeddingJobContext, but nothing executes that embedding locally. Vector embedding is only actually run by:

  • the MCP/API write path (src/basic_memory/api/v2/routers/knowledge_router.py — entity vector sync on write), and
  • the reindex/project-index path (src/basic_memory/indexing/embedding_index_planning.py, project_index_runtime.py).

The watch inline path (LocalInlineStorageEventResultRecorder.index_file_completed) runs relation repair (resolve_project_relations) but never calls sync_entity_vectors[_batch]. Cloud consumes the embedding job context via PGQ; local has no inline embedding execution on the watch path.

A revealing symmetry (please cross-link #1015)

The two post-index follow-ups are each wired to only one ingress path:

Ingress Vector embedding Relation back-resolution
MCP write_note (API) yes no (#1015)
Watcher / direct-disk write no (this issue) yes

So write_note embeds but doesn't back-resolve inbound dangling [[wikilinks]]; the watcher back-resolves but doesn't embed. Neither path runs both. This strongly suggests a single fix: both ingress paths should run the same set of post-index follow-ups (relation resolution + vector embedding) when enabled.

Suggested fix

In the local watch inline path, when index_embeddings is true and semantic search is enabled, run the same embedding follow-up the API/reindex paths use (sync_entity_vectors_batch for the affected entity ids) after index_file_completed. Pair it with the #1015 fix so the MCP and watcher ingress paths converge on identical follow-up behavior.

Impact

  • Obsidian / external-editor / git pull / cloud-sync users: their notes are FTS-searchable and relation-linked but silently absent from semantic search until a manual reindex.
  • The failure is silent — semantic search just returns fewer/no results, with no signal that content isn't embedded yet.

Environment

  • branch codex/repository-explicit-sessions (v0.22.1), SQLite, local runtime
  • env: user (file watcher + background schedulers active), semantic_search_enabled: true, fastembed bge-small-en-v1.5
  • Found during refactor(core): add shared runtime orchestration #1002 local-runtime regression testing.

Activity

  1. added
    bug
    on Jun 23, 2026
  2. claude commented on Jun 23, 2026

    @claude
    Contributor

    Claude finished @phernandez's task in 5m 38s —— View job • Create PR ➔


    Issue Triage & Analysis

    Classification: Bug | Priority: High | Component: sync | Complexity: Medium

    Root cause verified in src/basic_memory/sync/sync_service.py:sync_file():

    The watcher path (WatchService.handle_changes()) calls sync_service.sync_file() for every file change. sync_file() calls search_service.index_entity() — which only updates FTS rows — but never calls search_service.sync_entity_vectors(). Vector embeddings are only generated by:

    • SyncService.sync() (bulk sync) → calls sync_entity_vectors_batch() at line 400
    • knowledge_router.py (MCP write_note API) → calls sync_entity_vectors_batch() inline

    The watcher calls neither, so externally-edited notes are permanently missing from semantic search until a manual bm reindex --embeddings.


    Fix implemented

    src/basic_memory/sync/sync_service.py — added sync_entity_vectors() call in sync_file() after FTS indexing, guarded by semantic_search_enabled:

    # Trigger: watcher and one-off sync_file() callers must embed entities so
    # semantic search finds them without requiring a full reindex.
    # Why: index_entity() only updates FTS rows; sync_entity_vectors() generates
    #      the chunk embeddings that semantic search queries.
    # Outcome: watcher-indexed entities get the same post-index follow-up as the
    #           bulk sync path, closing the gap described in issue #1016.
    if self.app_config.semantic_search_enabled:
        try:
            await self.search_service.sync_entity_vectors(entity.id)
        except SemanticDependenciesMissingError:
            logger.warning(...)

    tests/sync/test_sync_service.py — added 3 regression tests:

    • test_sync_file_calls_sync_entity_vectors_when_semantic_search_enabled — verifies sync_entity_vectors is called in the watcher path
    • test_sync_file_skips_sync_entity_vectors_when_semantic_search_disabled — verifies it is NOT called when disabled
    • test_sync_file_handles_sync_entity_vectors_semantic_error — verifies SemanticDependenciesMissingError doesn't fail sync

    Commit: fa0bf28 on branch claude/issue-1016-20260623-2221

  3. hegu-1 commented on Jul 1, 2026

    @hegu-1

    This is an important bug for local-first personal memory setups because it breaks the contract between the authored vault and generated recall views.

    If a user edits notes through Obsidian, an editor, git pull, or file sync, those markdown files are still the source of truth. Semantic search is a generated view over that source. When the watcher indexes FTS/relations but skips embeddings, the system ends up in a subtle split-brain state:

    authored note exists on disk
    FTS/relation view sees it
    semantic recall view does not
    

    For a personal memory vault, that is more dangerous than a loud failure. The user thinks the vault contains the memory, but an agent using semantic search may behave as if it does not exist.

    The invariant I’d want is:

    any accepted ingress path -> same post-index follow-ups
    

    So write_note, direct file watcher writes, git sync, and external editor saves should converge on the same pipeline:

    parse markdown
    -> update entity/relation index
    -> update semantic chunks/embeddings
    -> mark generated views fresh
    -> emit provenance / index status
    

    It may also be useful to expose an index freshness signal per note or project:

    fts_indexed_at
    relations_indexed_at
    embeddings_indexed_at
    source_modified_at
    recall_view_status: fresh | stale | missing
    

    Then agents can avoid treating missing semantic results as absence of knowledge.

    I’ve been exploring this from a Personal AI OS / Memory Vault angle: authored markdown should remain the durable source of truth, while FTS/vector/graph indexes are rebuildable generated views. The key is making drift between source and recall views visible, not silent.

    Related public projects:

  4. phernandez commented on Jul 15, 2026

    @phernandez
    MemberAuthor

    Fixed on main via the #1002 runtime rewrite. The watcher/inline ingress path now runs the same post-index follow-ups as the API write path — LocalInlineStorageEventResultRecorder.index_file_completed() calls sync_entity_vectors_batch() after FTS and relation indexing, gated on semantic_search_enabled (index/local_runtime.py, wired in index/watch_service.py). Externally edited notes (Obsidian, git pull, file sync) are embedded inline instead of waiting for a manual reindex.

    Covered by tests/index/test_local_inline_result_recorder.py and an end-to-end fastembed watcher test (tests/index/test_local_watch_semantic_embedding.py). The per-note index-freshness signal suggested in the thread is a good follow-up for a separate issue. Closing.

  5. added this to the v0.23 milestone on Aug 11, 2026
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

    bug

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions