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
fix(docs): namespace doc chunk ids by source file (#16)
Indexing a second markdown file silently destroyed chunks from the first.
parse_markdown reset its counter per call, so every document minted
doc-0001, doc-0002, ... while that id is simultaneously the RocksDB key
(doc:{id} and docvec:{id}), the chunk_cache key and the HNSW point id -
a single global namespace. The second file wrote straight over the first,
which then vanished from codegraph_list_doc_sources and
codegraph_search_docs while indexing still reported status: success.
The loss was partial and size-dependent, which is why it read as
intermittent: a 3-chunk file took only the first 3 chunks of a 10-chunk
file, and the 7 survivors made the next remove_source look like it had
done its job. Re-indexing the larger file afterwards then wiped the
smaller one entirely.
Ids are now doc-{fnv1a(source_file):016x}-{counter:04}. FNV-1a rather
than DefaultHasher because the value is baked into a persisted key, and
DefaultHasher's output is explicitly not guaranteed stable across Rust
releases - a toolchain upgrade would silently orphan every chunk already
on disk. The reference vectors are pinned by a test for the same reason.
Old and new ids have different shapes, so they coexist safely and no
migration is needed. An index written before this change keeps whatever
survived until its sources are re-indexed.
Reproduced and verified end to end with the reporter's exact steps
against a real engine: before, indexing two files left list_doc_sources
reporting 1 source; after, it reports 2, re-indexing the first no longer
wipes the second, and both markers are findable via search_docs.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rVbt7rENTwXkdHt3Bpgb5
0 commit comments